2019-10-26 09:09:50 +00:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
|
|
|
if [[ -z $(type -p git) ]]; then
|
|
|
|
echo "Git not installed; skipping Git submodule tests"
|
|
|
|
exit 99
|
|
|
|
fi
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
|
|
|
|
rootRepo=$TEST_ROOT/gitSubmodulesRoot
|
|
|
|
subRepo=$TEST_ROOT/gitSubmodulesSub
|
|
|
|
|
2020-04-07 11:45:17 +00:00
|
|
|
rm -rf ${rootRepo} ${subRepo} $TEST_HOME/.cache/nix
|
2019-10-26 09:09:50 +00:00
|
|
|
|
|
|
|
initGitRepo() {
|
|
|
|
git init $1
|
|
|
|
git -C $1 config user.email "foobar@example.com"
|
|
|
|
git -C $1 config user.name "Foobar"
|
|
|
|
}
|
|
|
|
|
|
|
|
addGitContent() {
|
|
|
|
echo "lorem ipsum" > $1/content
|
|
|
|
git -C $1 add content
|
|
|
|
git -C $1 commit -m "Initial commit"
|
|
|
|
}
|
|
|
|
|
|
|
|
initGitRepo $subRepo
|
|
|
|
addGitContent $subRepo
|
|
|
|
|
|
|
|
initGitRepo $rootRepo
|
|
|
|
|
|
|
|
git -C $rootRepo submodule init
|
|
|
|
git -C $rootRepo submodule add $subRepo sub
|
|
|
|
git -C $rootRepo add sub
|
|
|
|
git -C $rootRepo commit -m "Add submodule"
|
|
|
|
|
|
|
|
rev=$(git -C $rootRepo rev-parse HEAD)
|
|
|
|
|
2020-04-07 12:29:45 +00:00
|
|
|
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")
|
|
|
|
r3=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath")
|
2020-03-16 13:47:55 +00:00
|
|
|
|
2021-09-22 15:25:25 +00:00
|
|
|
[[ $r1 == $r2 ]]
|
|
|
|
[[ $r2 != $r3 ]]
|
2020-03-16 13:47:55 +00:00
|
|
|
|
2020-04-07 12:29:45 +00:00
|
|
|
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")
|
|
|
|
r6=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$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")
|
2020-03-16 13:47:55 +00:00
|
|
|
|
|
|
|
[[ $r1 == $r4 ]]
|
2021-09-22 15:25:25 +00:00
|
|
|
[[ $r4 == $r5 ]]
|
2020-03-16 13:47:55 +00:00
|
|
|
[[ $r3 == $r6 ]]
|
|
|
|
[[ $r6 == $r7 ]]
|
|
|
|
[[ $r7 == $r8 ]]
|
|
|
|
|
2020-04-07 12:29:45 +00:00
|
|
|
have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; }).submodules")
|
2021-09-22 15:25:25 +00:00
|
|
|
[[ $have_submodules == false ]]
|
2020-03-17 13:27:14 +00:00
|
|
|
|
2020-04-07 12:29:45 +00:00
|
|
|
have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = false; }).submodules")
|
2020-03-17 13:27:14 +00:00
|
|
|
[[ $have_submodules == false ]]
|
|
|
|
|
2020-04-07 12:29:45 +00:00
|
|
|
have_submodules=$(nix eval --expr "(builtins.fetchGit { url = $rootRepo; rev = \"$rev\"; submodules = true; }).submodules")
|
2020-03-17 13:27:14 +00:00
|
|
|
[[ $have_submodules == true ]]
|
|
|
|
|
2021-09-22 15:25:25 +00:00
|
|
|
pathWithoutSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; }).outPath")
|
|
|
|
pathWithSubmodules=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath")
|
2020-04-07 12:29:45 +00:00
|
|
|
pathWithSubmodulesAgain=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath")
|
|
|
|
pathWithSubmodulesAgainWithRef=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; ref = \"master\"; rev = \"$rev\"; submodules = true; }).outPath")
|
2020-03-17 19:14:19 +00:00
|
|
|
|
2019-10-26 09:09:50 +00:00
|
|
|
# The resulting store path cannot be the same.
|
|
|
|
[[ $pathWithoutSubmodules != $pathWithSubmodules ]]
|
|
|
|
|
2020-03-02 13:46:19 +00:00
|
|
|
# Checking out the same repo with submodules returns in the same store path.
|
|
|
|
[[ $pathWithSubmodules == $pathWithSubmodulesAgain ]]
|
|
|
|
|
2020-03-17 19:14:19 +00:00
|
|
|
# Checking out the same repo with submodules returns in the same store path.
|
|
|
|
[[ $pathWithSubmodulesAgain == $pathWithSubmodulesAgainWithRef ]]
|
|
|
|
|
2020-03-02 13:46:19 +00:00
|
|
|
# The submodules flag is actually honored.
|
2019-10-26 09:09:50 +00:00
|
|
|
[[ ! -e $pathWithoutSubmodules/sub/content ]]
|
|
|
|
[[ -e $pathWithSubmodules/sub/content ]]
|
|
|
|
|
2020-03-17 19:14:19 +00:00
|
|
|
[[ -e $pathWithSubmodulesAgainWithRef/sub/content ]]
|
|
|
|
|
2020-03-02 13:42:19 +00:00
|
|
|
# No .git directory or submodule reference files must be left
|
|
|
|
test "$(find "$pathWithSubmodules" -name .git)" = ""
|
2020-03-02 13:46:19 +00:00
|
|
|
|
|
|
|
# Git repos without submodules can be fetched with submodules = true.
|
2020-03-02 14:50:39 +00:00
|
|
|
subRev=$(git -C $subRepo rev-parse HEAD)
|
2020-04-07 12:29:45 +00:00
|
|
|
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")
|
2020-03-02 13:46:19 +00:00
|
|
|
|
|
|
|
[[ $noSubmoduleRepoBaseline == $noSubmoduleRepo ]]
|