Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/functional/common/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,25 @@ execUnshare () {
exec unshare --mount --map-root-user "$SHELL" "$@"
}

initGitRepo() {
local repo="$1"
local extraArgs="${2-}"

# shellcheck disable=SC2086 # word splitting of extraArgs is intended
git -C "$repo" init $extraArgs
git -C "$repo" config user.email "foobar@example.com"
git -C "$repo" config user.name "Foobar"
}

createGitRepo() {
local repo="$1"
local extraArgs="${2-}"

rm -rf "$repo" "$repo".tmp
mkdir -p "$repo"

# shellcheck disable=SC2086 # word splitting of extraArgs is intended
initGitRepo "$repo" $extraArgs
}

fi # COMMON_FUNCTIONS_SH_SOURCED
17 changes: 6 additions & 11 deletions tests/functional/fetchGit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ repo=$TEST_ROOT/./git

export _NIX_FORCE_HTTP=1

rm -rf "$repo" "${repo}"-tmp "$TEST_HOME"/.cache/nix "$TEST_ROOT"/worktree "$TEST_ROOT"/minimal
rm -rf "${repo}"-tmp "$TEST_HOME"/.cache/nix "$TEST_ROOT"/worktree "$TEST_ROOT"/minimal

git init "$repo"
git -C "$repo" config user.email "foobar@example.com"
git -C "$repo" config user.name "Foobar"
createGitRepo "$repo"

echo utrecht > "$repo"/hello
touch "$repo"/.gitignore
Expand Down Expand Up @@ -213,8 +211,7 @@ path5=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = $repo; ref =

# Fetching from a repo with only a specific revision and no branches should
# not fall back to copying files and record correct revision information. See: #5302
mkdir "$TEST_ROOT"/minimal
git -C "$TEST_ROOT"/minimal init
createGitRepo "$TEST_ROOT"/minimal
git -C "$TEST_ROOT"/minimal fetch "$repo" "$rev2"
git -C "$TEST_ROOT"/minimal checkout "$rev2"
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit { url = $TEST_ROOT/minimal; }).rev") = "$rev2" ]]
Expand Down Expand Up @@ -267,17 +264,15 @@ rm -rf "$TEST_HOME"/.cache/nix
(! nix eval --impure --raw --expr "(builtins.fetchGit \"file://$repo\").outPath")

# should succeed for a repo without commits
git init "$repo"
initGitRepo "$repo"
git -C "$repo" add hello # need to add at least one file to cause the root of the repo to be visible
# shellcheck disable=SC2034
path10=$(nix eval --impure --raw --expr "(builtins.fetchGit \"file://$repo\").outPath")

# should succeed for a path with a space
# regression test for #7707
repo="$TEST_ROOT/a b"
git init "$repo"
git -C "$repo" config user.email "foobar@example.com"
git -C "$repo" config user.name "Foobar"
createGitRepo "$repo"

echo utrecht > "$repo/hello"
touch "$repo/.gitignore"
Expand All @@ -289,7 +284,7 @@ path11=$(nix eval --impure --raw --expr "(builtins.fetchGit ./.).outPath")

# Test a workdir with no commits.
empty="$TEST_ROOT/empty"
git init "$empty"
createGitRepo "$empty"

emptyAttrs="{ lastModified = 0; lastModifiedDate = \"19700101000000\"; narHash = \"sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=\"; rev = \"0000000000000000000000000000000000000000\"; revCount = 0; shortRev = \"0000000\"; submodules = false; }"
result=$(nix eval --impure --expr "builtins.removeAttrs (builtins.fetchGit $empty) [\"outPath\"]")
Expand Down
6 changes: 2 additions & 4 deletions tests/functional/fetchGitRefs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ clearStoreIfPossible

repo="$TEST_ROOT/git"

rm -rf "$repo" "${repo}-tmp" "$TEST_HOME/.cache/nix"
rm -rf "${repo}-tmp" "$TEST_HOME/.cache/nix"

git init "$repo"
git -C "$repo" config user.email "foobar@example.com"
git -C "$repo" config user.name "Foobar"
createGitRepo "$repo"

echo utrecht > "$repo/hello"
git -C "$repo" add hello
Expand Down
4 changes: 1 addition & 3 deletions tests/functional/fetchGitShallow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ source common.sh
requireGit

# Create a test repo with multiple commits for all our tests
git init "$TEST_ROOT/shallow-parent"
git -C "$TEST_ROOT/shallow-parent" config user.email "foobar@example.com"
git -C "$TEST_ROOT/shallow-parent" config user.name "Foobar"
createGitRepo "$TEST_ROOT/shallow-parent"

# Add several commits to have history
echo "{ outputs = _: {}; }" > "$TEST_ROOT/shallow-parent/flake.nix"
Expand Down
18 changes: 6 additions & 12 deletions tests/functional/fetchGitSubmodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@ rm -rf "${rootRepo}" "${subRepo}" "$TEST_HOME"/.cache/nix
export XDG_CONFIG_HOME=$TEST_HOME/.config
git config --global protocol.file.allow always

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"
createGitRepo "$subRepo"
addGitContent "$subRepo"

initGitRepo "$rootRepo"
createGitRepo "$rootRepo"

git -C "$rootRepo" submodule init
git -C "$rootRepo" submodule add "$subRepo" sub
Expand Down Expand Up @@ -199,19 +193,19 @@ test_submodule_nested() {
local repoB=$TEST_ROOT/submodule_nested/b
local repoC=$TEST_ROOT/submodule_nested/c

rm -rf "$repoA" "$repoB" "$repoC" "$TEST_HOME"/.cache/nix
rm -rf "$TEST_HOME"/.cache/nix

initGitRepo "$repoC"
createGitRepo "$repoC"
touch "$repoC"/inside-c
git -C "$repoC" add inside-c
addGitContent "$repoC"

initGitRepo "$repoB"
createGitRepo "$repoB"
git -C "$repoB" submodule add "$repoC" c
git -C "$repoB" add c
addGitContent "$repoB"

initGitRepo "$repoA"
createGitRepo "$repoA"
git -C "$repoA" submodule add "$repoB" b
git -C "$repoA" add b
addGitContent "$repoA"
Expand Down
4 changes: 1 addition & 3 deletions tests/functional/fetchGitVerification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ ssh-keygen -f "$keysDir/testkey2" -t rsa -P "" -C "test key 2"
key2File="$keysDir/testkey2.pub"
publicKey2=$(awk '{print $2}' "$key2File")

git init "$repo"
git -C "$repo" config user.email "foobar@example.com"
git -C "$repo" config user.name "Foobar"
createGitRepo "$repo"
git -C "$repo" config gpg.format ssh

echo 'hello' > "$repo"/text
Expand Down
21 changes: 0 additions & 21 deletions tests/functional/flakes/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,3 @@ writeTrivialFlake() {
}
EOF
}

initGitRepo() {
local repo="$1"
local extraArgs="${2-}"

# shellcheck disable=SC2086 # word splitting of extraArgs is intended
git -C "$repo" init $extraArgs
git -C "$repo" config user.email "foobar@example.com"
git -C "$repo" config user.name "Foobar"
}

createGitRepo() {
local repo="$1"
local extraArgs="${2-}"

rm -rf "$repo" "$repo".tmp
mkdir -p "$repo"

# shellcheck disable=SC2086 # word splitting of extraArgs is intended
initGitRepo "$repo" $extraArgs
}
4 changes: 1 addition & 3 deletions tests/functional/flakes/relative-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ EOF
# https://github.com/NixOS/nix/issues/13164
mkdir -p "$TEST_ROOT/issue-13164/nested-flake1/nested-flake2"
(
initGitRepo "$TEST_ROOT/issue-13164"
cd "$TEST_ROOT/issue-13164"
git init
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
cat >flake.nix <<EOF
{
inputs.nestedFlake1.url = "path:./nested-flake1";
Expand Down
7 changes: 0 additions & 7 deletions tests/functional/git-hashing/simple-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ source common.sh

repo="$TEST_ROOT/scratch"

initRepo () {
git init "$repo" --object-format="$hashAlgo"

git -C "$repo" config user.email "you@example.com"
git -C "$repo" config user.name "Your Name"
}

# Compare Nix's and git's implementation of git hashing
try () {
local expected="$1"
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/git-hashing/simple-sha1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ hashAlgo=sha1

source simple-common.sh

initRepo
createGitRepo "$repo" "--object-format=$hashAlgo"

# blob
test0
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/git-hashing/simple-sha256.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source simple-common.sh

requireDaemonNewerThan 2.31pre20250724

initRepo
createGitRepo "$repo" "--object-format=$hashAlgo"

# blob
test0
Expand Down
Loading