1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +01:00

shellcheck fix: tests/functional/fetchGitSubmodules.sh

This commit is contained in:
Farid Zakaria 2025-09-25 13:09:36 -07:00
parent ea035ae165
commit 53ad2433b4
2 changed files with 77 additions and 77 deletions

View file

@ -106,7 +106,6 @@
enable = true; enable = true;
excludes = [ excludes = [
# We haven't linted these files yet # We haven't linted these files yet
''^tests/functional/fetchGitSubmodules\.sh$''
''^tests/functional/fetchGitVerification\.sh$'' ''^tests/functional/fetchGitVerification\.sh$''
''^tests/functional/fetchMercurial\.sh$'' ''^tests/functional/fetchMercurial\.sh$''
''^tests/functional/fixed\.builder1\.sh$'' ''^tests/functional/fixed\.builder1\.sh$''

View file

@ -11,7 +11,7 @@ clearStoreIfPossible
rootRepo=$TEST_ROOT/gitSubmodulesRoot rootRepo=$TEST_ROOT/gitSubmodulesRoot
subRepo=$TEST_ROOT/gitSubmodulesSub subRepo=$TEST_ROOT/gitSubmodulesSub
rm -rf ${rootRepo} ${subRepo} $TEST_HOME/.cache/nix rm -rf "${rootRepo}" "${subRepo}" "$TEST_HOME"/.cache/nix
# Submodules can't be fetched locally by default, which can cause # Submodules can't be fetched locally by default, which can cause
# information leakage vulnerabilities, but for these tests our # information leakage vulnerabilities, but for these tests our
@ -23,35 +23,35 @@ export XDG_CONFIG_HOME=$TEST_HOME/.config
git config --global protocol.file.allow always git config --global protocol.file.allow always
initGitRepo() { initGitRepo() {
git init $1 git init "$1"
git -C $1 config user.email "foobar@example.com" git -C "$1" config user.email "foobar@example.com"
git -C $1 config user.name "Foobar" git -C "$1" config user.name "Foobar"
} }
addGitContent() { addGitContent() {
echo "lorem ipsum" > $1/content echo "lorem ipsum" > "$1"/content
git -C $1 add content git -C "$1" add content
git -C $1 commit -m "Initial commit" git -C "$1" commit -m "Initial commit"
} }
initGitRepo $subRepo initGitRepo "$subRepo"
addGitContent $subRepo addGitContent "$subRepo"
initGitRepo $rootRepo initGitRepo "$rootRepo"
git -C $rootRepo submodule init git -C "$rootRepo" submodule init
git -C $rootRepo submodule add $subRepo sub git -C "$rootRepo" submodule add "$subRepo" sub
git -C $rootRepo add sub git -C "$rootRepo" add sub
git -C $rootRepo commit -m "Add submodule" git -C "$rootRepo" commit -m "Add submodule"
rev=$(git -C $rootRepo rev-parse HEAD) rev=$(git -C "$rootRepo" rev-parse HEAD)
r1=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; }).outPath") r1=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; }).outPath")
r2=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = false; }).outPath") r2=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = false; }).outPath")
r3=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath") r3=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath")
[[ $r1 == $r2 ]] [[ $r1 == "$r2" ]]
[[ $r2 != $r3 ]] [[ $r2 != "$r3" ]]
r4=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; }).outPath") r4=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; }).outPath")
r5=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = false; }).outPath") r5=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = false; }).outPath")
@ -59,11 +59,11 @@ r6=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \
r7=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath") r7=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath")
r8=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = true; }).outPath") r8=$(nix eval --raw --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = true; }).outPath")
[[ $r1 == $r4 ]] [[ $r1 == "$r4" ]]
[[ $r4 == $r5 ]] [[ $r4 == "$r5" ]]
[[ $r3 == $r6 ]] [[ $r3 == "$r6" ]]
[[ $r6 == $r7 ]] [[ $r6 == "$r7" ]]
[[ $r7 == $r8 ]] [[ $r7 == "$r8" ]]
have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; }).submodules") have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; }).submodules")
[[ $have_submodules == false ]] [[ $have_submodules == false ]]
@ -80,13 +80,13 @@ pathWithSubmodulesAgain=$(nix eval --raw --expr "(builtins.fetchGit { url = file
pathWithSubmodulesAgainWithRef=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath") pathWithSubmodulesAgainWithRef=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath")
# The resulting store path cannot be the same. # The resulting store path cannot be the same.
[[ $pathWithoutSubmodules != $pathWithSubmodules ]] [[ $pathWithoutSubmodules != "$pathWithSubmodules" ]]
# Checking out the same repo with submodules returns in the same store path. # Checking out the same repo with submodules returns in the same store path.
[[ $pathWithSubmodules == $pathWithSubmodulesAgain ]] [[ $pathWithSubmodules == "$pathWithSubmodulesAgain" ]]
# Checking out the same repo with submodules returns in the same store path. # Checking out the same repo with submodules returns in the same store path.
[[ $pathWithSubmodulesAgain == $pathWithSubmodulesAgainWithRef ]] [[ $pathWithSubmodulesAgain == "$pathWithSubmodulesAgainWithRef" ]]
# The submodules flag is actually honored. # The submodules flag is actually honored.
[[ ! -e $pathWithoutSubmodules/sub/content ]] [[ ! -e $pathWithoutSubmodules/sub/content ]]
@ -98,14 +98,14 @@ pathWithSubmodulesAgainWithRef=$(nix eval --raw --expr "(builtins.fetchGit { url
test "$(find "$pathWithSubmodules" -name .git)" = "" test "$(find "$pathWithSubmodules" -name .git)" = ""
# Git repos without submodules can be fetched with submodules = true. # Git repos without submodules can be fetched with submodules = true.
subRev=$(git -C $subRepo rev-parse HEAD) subRev=$(git -C "$subRepo" rev-parse HEAD)
noSubmoduleRepoBaseline=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$subRepo; rev = \"$subRev\"; }).outPath") noSubmoduleRepoBaseline=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$subRepo; rev = \"$subRev\"; }).outPath")
noSubmoduleRepo=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$subRepo; rev = \"$subRev\"; submodules = true; }).outPath") noSubmoduleRepo=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$subRepo; rev = \"$subRev\"; submodules = true; }).outPath")
[[ $noSubmoduleRepoBaseline == $noSubmoduleRepo ]] [[ $noSubmoduleRepoBaseline == "$noSubmoduleRepo" ]]
# Test .gitmodules with entries that refer to non-existent objects or objects that are not submodules. # Test .gitmodules with entries that refer to non-existent objects or objects that are not submodules.
cat >> $rootRepo/.gitmodules <<EOF cat >> "$rootRepo"/.gitmodules <<EOF
[submodule "missing"] [submodule "missing"]
path = missing path = missing
url = https://example.org/missing.git url = https://example.org/missing.git
@ -114,11 +114,11 @@ cat >> $rootRepo/.gitmodules <<EOF
path = file path = file
url = https://example.org/file.git url = https://example.org/file.git
EOF EOF
echo foo > $rootRepo/file echo foo > "$rootRepo"/file
git -C $rootRepo add file git -C "$rootRepo" add file
git -C $rootRepo commit -a -m "Add bad submodules" git -C "$rootRepo" commit -a -m "Add bad submodules"
rev=$(git -C $rootRepo rev-parse HEAD) rev=$(git -C "$rootRepo" rev-parse HEAD)
r=$(nix eval --raw --expr "builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }") r=$(nix eval --raw --expr "builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }")
@ -126,44 +126,44 @@ r=$(nix eval --raw --expr "builtins.fetchGit { url = file://$rootRepo; rev = \"$
[[ ! -e $r/missing ]] [[ ! -e $r/missing ]]
# Test relative submodule URLs. # Test relative submodule URLs.
rm $TEST_HOME/.cache/nix/fetcher-cache* rm "$TEST_HOME"/.cache/nix/fetcher-cache*
rm -rf $rootRepo/.git $rootRepo/.gitmodules $rootRepo/sub rm -rf "$rootRepo"/.git "$rootRepo"/.gitmodules "$rootRepo"/sub
initGitRepo $rootRepo initGitRepo "$rootRepo"
git -C $rootRepo submodule add ../gitSubmodulesSub sub git -C "$rootRepo" submodule add ../gitSubmodulesSub sub
git -C $rootRepo commit -m "Add submodule" git -C "$rootRepo" commit -m "Add submodule"
rev2=$(git -C $rootRepo rev-parse HEAD) rev2=$(git -C "$rootRepo" rev-parse HEAD)
pathWithRelative=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev2\"; submodules = true; }).outPath") pathWithRelative=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev2\"; submodules = true; }).outPath")
diff -r -x .gitmodules $pathWithSubmodules $pathWithRelative diff -r -x .gitmodules "$pathWithSubmodules" "$pathWithRelative"
# Test clones that have an upstream with relative submodule URLs. # Test clones that have an upstream with relative submodule URLs.
rm $TEST_HOME/.cache/nix/fetcher-cache* rm "$TEST_HOME"/.cache/nix/fetcher-cache*
cloneRepo=$TEST_ROOT/a/b/gitSubmodulesClone # NB /a/b to make the relative path not work relative to $cloneRepo cloneRepo=$TEST_ROOT/a/b/gitSubmodulesClone # NB /a/b to make the relative path not work relative to $cloneRepo
git clone $rootRepo $cloneRepo git clone "$rootRepo" "$cloneRepo"
pathIndirect=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$cloneRepo; rev = \"$rev2\"; submodules = true; }).outPath") pathIndirect=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$cloneRepo; rev = \"$rev2\"; submodules = true; }).outPath")
[[ $pathIndirect = $pathWithRelative ]] [[ $pathIndirect = "$pathWithRelative" ]]
# Test submodule export-ignore interaction # Test submodule export-ignore interaction
git -C $rootRepo/sub config user.email "foobar@example.com" git -C "$rootRepo"/sub config user.email "foobar@example.com"
git -C $rootRepo/sub config user.name "Foobar" git -C "$rootRepo"/sub config user.name "Foobar"
echo "/exclude-from-root export-ignore" >> $rootRepo/.gitattributes echo "/exclude-from-root export-ignore" >> "$rootRepo"/.gitattributes
# TBD possible semantics for submodules + exportIgnore # TBD possible semantics for submodules + exportIgnore
# echo "/sub/exclude-deep export-ignore" >> $rootRepo/.gitattributes # echo "/sub/exclude-deep export-ignore" >> $rootRepo/.gitattributes
echo nope > $rootRepo/exclude-from-root echo nope > "$rootRepo"/exclude-from-root
git -C $rootRepo add .gitattributes exclude-from-root git -C "$rootRepo" add .gitattributes exclude-from-root
git -C $rootRepo commit -m "Add export-ignore" git -C "$rootRepo" commit -m "Add export-ignore"
echo "/exclude-from-sub export-ignore" >> $rootRepo/sub/.gitattributes echo "/exclude-from-sub export-ignore" >> "$rootRepo"/sub/.gitattributes
echo nope > $rootRepo/sub/exclude-from-sub echo nope > "$rootRepo"/sub/exclude-from-sub
# TBD possible semantics for submodules + exportIgnore # TBD possible semantics for submodules + exportIgnore
# echo aye > $rootRepo/sub/exclude-from-root # echo aye > $rootRepo/sub/exclude-from-root
git -C $rootRepo/sub add .gitattributes exclude-from-sub git -C "$rootRepo"/sub add .gitattributes exclude-from-sub
git -C $rootRepo/sub commit -m "Add export-ignore (sub)" git -C "$rootRepo"/sub commit -m "Add export-ignore (sub)"
git -C $rootRepo add sub git -C "$rootRepo" add sub
git -C $rootRepo commit -m "Update submodule" git -C "$rootRepo" commit -m "Update submodule"
git -C $rootRepo status git -C "$rootRepo" status
# # TBD: not supported yet, because semantics are undecided and current implementation leaks rules from the root to submodules # # TBD: not supported yet, because semantics are undecided and current implementation leaks rules from the root to submodules
# # exportIgnore can be used with submodules # # exportIgnore can be used with submodules
@ -199,39 +199,40 @@ test_submodule_nested() {
local repoB=$TEST_ROOT/submodule_nested/b local repoB=$TEST_ROOT/submodule_nested/b
local repoC=$TEST_ROOT/submodule_nested/c local repoC=$TEST_ROOT/submodule_nested/c
rm -rf $repoA $repoB $repoC $TEST_HOME/.cache/nix rm -rf "$repoA" "$repoB" "$repoC" "$TEST_HOME"/.cache/nix
initGitRepo $repoC initGitRepo "$repoC"
touch $repoC/inside-c touch "$repoC"/inside-c
git -C $repoC add inside-c git -C "$repoC" add inside-c
addGitContent $repoC addGitContent "$repoC"
initGitRepo $repoB initGitRepo "$repoB"
git -C $repoB submodule add $repoC c git -C "$repoB" submodule add "$repoC" c
git -C $repoB add c git -C "$repoB" add c
addGitContent $repoB addGitContent "$repoB"
initGitRepo $repoA initGitRepo "$repoA"
git -C $repoA submodule add $repoB b git -C "$repoA" submodule add "$repoB" b
git -C $repoA add b git -C "$repoA" add b
addGitContent $repoA addGitContent "$repoA"
# Check non-worktree fetch # Check non-worktree fetch
local rev=$(git -C $repoA rev-parse HEAD) local rev
rev=$(git -C "$repoA" rev-parse HEAD)
out=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repoA\"; rev = \"$rev\"; submodules = true; }).outPath") out=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repoA\"; rev = \"$rev\"; submodules = true; }).outPath")
test -e $out/b/c/inside-c test -e "$out"/b/c/inside-c
test -e $out/content test -e "$out"/content
test -e $out/b/content test -e "$out"/b/content
test -e $out/b/c/content test -e "$out"/b/c/content
local nonWorktree=$out local nonWorktree=$out
# Check worktree based fetch # Check worktree based fetch
# TODO: make it work without git submodule update # TODO: make it work without git submodule update
git -C $repoA submodule update --init --recursive git -C "$repoA" submodule update --init --recursive
out=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repoA\"; submodules = true; }).outPath") out=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repoA\"; submodules = true; }).outPath")
find $out find "$out"
[[ $out == $nonWorktree ]] || { find $out; false; } [[ $out == "$nonWorktree" ]] || { find "$out"; false; }
} }
test_submodule_nested test_submodule_nested