2017-11-03 14:33:50 +02:00
|
|
|
source common.sh
|
|
|
|
|
2023-03-16 22:00:20 +02:00
|
|
|
requireGit
|
2017-11-03 14:33:50 +02:00
|
|
|
|
|
|
|
clearStore
|
|
|
|
|
2022-04-07 18:31:12 +03:00
|
|
|
# Intentionally not in a canonical form
|
|
|
|
# See https://github.com/NixOS/nix/issues/6195
|
|
|
|
repo=$TEST_ROOT/./git
|
2017-11-03 14:33:50 +02:00
|
|
|
|
2019-04-19 15:06:27 +03:00
|
|
|
export _NIX_FORCE_HTTP=1
|
|
|
|
|
2021-12-13 22:31:20 +02:00
|
|
|
rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix $TEST_ROOT/worktree $TEST_ROOT/shallow $TEST_ROOT/minimal
|
2017-11-03 14:33:50 +02:00
|
|
|
|
|
|
|
git init $repo
|
|
|
|
git -C $repo config user.email "foobar@example.com"
|
|
|
|
git -C $repo config user.name "Foobar"
|
|
|
|
|
|
|
|
echo utrecht > $repo/hello
|
2017-11-21 20:12:47 +02:00
|
|
|
touch $repo/.gitignore
|
|
|
|
git -C $repo add hello .gitignore
|
2017-11-03 14:33:50 +02:00
|
|
|
git -C $repo commit -m 'Bla1'
|
|
|
|
rev1=$(git -C $repo rev-parse HEAD)
|
2022-10-15 01:27:13 +03:00
|
|
|
git -C $repo tag -a tag1 -m tag1
|
2017-11-03 14:33:50 +02:00
|
|
|
|
|
|
|
echo world > $repo/hello
|
|
|
|
git -C $repo commit -m 'Bla2' -a
|
2019-11-15 14:04:42 +02:00
|
|
|
git -C $repo worktree add $TEST_ROOT/worktree
|
|
|
|
echo hello >> $TEST_ROOT/worktree/hello
|
2017-11-03 14:33:50 +02:00
|
|
|
rev2=$(git -C $repo rev-parse HEAD)
|
2022-10-15 01:27:13 +03:00
|
|
|
git -C $repo tag -a tag2 -m tag2
|
2017-11-03 14:33:50 +02:00
|
|
|
|
2024-02-20 11:36:36 +02:00
|
|
|
# Check whether fetching in read-only mode works.
|
|
|
|
nix-instantiate --eval -E "builtins.readFile ((builtins.fetchGit file://$TEST_ROOT/worktree) + \"/hello\") == \"utrecht\\n\""
|
|
|
|
|
|
|
|
# Fetch a worktree.
|
2019-11-15 14:04:42 +02:00
|
|
|
unset _NIX_FORCE_HTTP
|
|
|
|
path0=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$TEST_ROOT/worktree).outPath")
|
2020-04-29 23:39:58 +03:00
|
|
|
path0_=$(nix eval --impure --raw --expr "(builtins.fetchTree { type = \"git\"; url = file://$TEST_ROOT/worktree; }).outPath")
|
|
|
|
[[ $path0 = $path0_ ]]
|
2023-09-28 17:52:28 +03:00
|
|
|
path0_=$(nix eval --impure --raw --expr "(builtins.fetchTree git+file://$TEST_ROOT/worktree).outPath")
|
|
|
|
[[ $path0 = $path0_ ]]
|
2019-11-15 14:04:42 +02:00
|
|
|
export _NIX_FORCE_HTTP=1
|
|
|
|
[[ $(tail -n 1 $path0/hello) = "hello" ]]
|
|
|
|
|
2017-11-03 14:33:50 +02:00
|
|
|
# Fetch the default branch.
|
2019-11-27 01:05:30 +02:00
|
|
|
path=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $(cat $path/hello) = world ]]
|
|
|
|
|
2020-12-22 13:18:10 +02:00
|
|
|
# Fetch a rev from another branch
|
|
|
|
git -C $repo checkout -b devtest
|
|
|
|
echo "different file" >> $TEST_ROOT/git/differentbranch
|
|
|
|
git -C $repo add differentbranch
|
|
|
|
git -C $repo commit -m 'Test2'
|
|
|
|
git -C $repo checkout master
|
|
|
|
devrev=$(git -C $repo rev-parse devtest)
|
2023-11-15 17:15:47 +02:00
|
|
|
nix eval --impure --raw --expr "builtins.fetchGit { url = file://$repo; rev = \"$devrev\"; }"
|
2020-12-22 13:18:10 +02:00
|
|
|
|
|
|
|
[[ $(nix eval --raw --expr "builtins.readFile (builtins.fetchGit { url = file://$repo; rev = \"$devrev\"; allRefs = true; } + \"/differentbranch\")") = 'different file' ]]
|
|
|
|
|
2018-01-16 19:50:38 +02:00
|
|
|
# In pure eval mode, fetchGit without a revision should fail.
|
2019-11-27 01:05:30 +02:00
|
|
|
[[ $(nix eval --impure --raw --expr "builtins.readFile (fetchGit file://$repo + \"/hello\")") = world ]]
|
|
|
|
(! nix eval --raw --expr "builtins.readFile (fetchGit file://$repo + \"/hello\")")
|
2018-01-16 19:50:38 +02:00
|
|
|
|
2017-11-03 14:33:50 +02:00
|
|
|
# Fetch using an explicit revision hash.
|
2019-11-27 01:05:30 +02:00
|
|
|
path2=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$repo; rev = \"$rev2\"; }).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
2018-01-16 19:50:38 +02:00
|
|
|
# In pure eval mode, fetchGit with a revision should succeed.
|
2019-11-27 01:05:30 +02:00
|
|
|
[[ $(nix eval --raw --expr "builtins.readFile (fetchGit { url = file://$repo; rev = \"$rev2\"; } + \"/hello\")") = world ]]
|
2018-01-16 19:50:38 +02:00
|
|
|
|
2024-01-24 14:19:02 +02:00
|
|
|
# But without a hash, it fails
|
libexpr: Support structured error classes
While preparing PRs like #9753, I've had to change error messages in
dozens of code paths. It would be nice if instead of
EvalError("expected 'boolean' but found '%1%'", showType(v))
we could write
TypeError(v, "boolean")
or similar. Then, changing the error message could be a mechanical
refactor with the compiler pointing out places the constructor needs to
be changed, rather than the error-prone process of grepping through the
codebase. Structured errors would also help prevent the "same" error
from having multiple slightly different messages, and could be a first
step towards error codes / an error index.
This PR reworks the exception infrastructure in `libexpr` to
support exception types with different constructor signatures than
`BaseError`. Actually refactoring the exceptions to use structured data
will come in a future PR (this one is big enough already, as it has to
touch every exception in `libexpr`).
The core design is in `eval-error.hh`. Generally, errors like this:
state.error("'%s' is not a string", getAttrPathStr())
.debugThrow<TypeError>()
are transformed like this:
state.error<TypeError>("'%s' is not a string", getAttrPathStr())
.debugThrow()
The type annotation has moved from `ErrorBuilder::debugThrow` to
`EvalState::error`.
2024-01-23 03:08:29 +02:00
|
|
|
expectStderr 1 nix eval --expr 'builtins.fetchGit "file:///foo"' | grepQuiet "fetchGit requires a locked input"
|
2024-01-24 14:19:02 +02:00
|
|
|
|
2017-11-03 14:33:50 +02:00
|
|
|
# Fetch again. This should be cached.
|
|
|
|
mv $repo ${repo}-tmp
|
2019-11-27 01:05:30 +02:00
|
|
|
path2=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
2019-11-27 01:05:30 +02:00
|
|
|
[[ $(nix eval --impure --expr "(builtins.fetchGit file://$repo).revCount") = 2 ]]
|
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit file://$repo).rev") = $rev2 ]]
|
2020-11-26 22:45:28 +02:00
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit file://$repo).shortRev") = ${rev2:0:7} ]]
|
2017-11-03 14:33:50 +02:00
|
|
|
|
|
|
|
# Fetching with a explicit hash should succeed.
|
2020-03-17 23:32:26 +02:00
|
|
|
path2=$(nix eval --refresh --raw --expr "(builtins.fetchGit { url = file://$repo; rev = \"$rev2\"; }).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
2020-03-17 23:32:26 +02:00
|
|
|
path2=$(nix eval --refresh --raw --expr "(builtins.fetchGit { url = file://$repo; rev = \"$rev1\"; }).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $(cat $path2/hello) = utrecht ]]
|
|
|
|
|
|
|
|
mv ${repo}-tmp $repo
|
|
|
|
|
|
|
|
# Using a clean working tree should produce the same result.
|
2019-11-27 01:05:30 +02:00
|
|
|
path2=$(nix eval --impure --raw --expr "(builtins.fetchGit $repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path2 ]]
|
|
|
|
|
|
|
|
# Using an unclean tree should yield the tracked but uncommitted changes.
|
2017-11-03 14:48:02 +02:00
|
|
|
mkdir $repo/dir1 $repo/dir2
|
|
|
|
echo foo > $repo/dir1/foo
|
2017-11-03 14:33:50 +02:00
|
|
|
echo bar > $repo/bar
|
2017-11-03 14:48:02 +02:00
|
|
|
echo bar > $repo/dir2/bar
|
|
|
|
git -C $repo add dir1/foo
|
2017-11-03 14:33:50 +02:00
|
|
|
git -C $repo rm hello
|
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
unset _NIX_FORCE_HTTP
|
2019-11-27 01:05:30 +02:00
|
|
|
path2=$(nix eval --impure --raw --expr "(builtins.fetchGit $repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[ ! -e $path2/hello ]
|
|
|
|
[ ! -e $path2/bar ]
|
2017-11-03 14:48:02 +02:00
|
|
|
[ ! -e $path2/dir2/bar ]
|
2017-11-21 20:12:47 +02:00
|
|
|
[ ! -e $path2/.git ]
|
2017-11-03 14:48:02 +02:00
|
|
|
[[ $(cat $path2/dir1/foo) = foo ]]
|
2017-11-03 14:33:50 +02:00
|
|
|
|
2020-07-28 23:46:39 +03:00
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]]
|
2021-10-14 15:44:45 +03:00
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit $repo).dirtyRev") = "${rev2}-dirty" ]]
|
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit $repo).dirtyShortRev") = "${rev2:0:7}-dirty" ]]
|
2020-07-28 23:46:39 +03:00
|
|
|
|
2017-11-03 14:33:50 +02:00
|
|
|
# ... unless we're using an explicit ref or rev.
|
2019-11-27 01:05:30 +02:00
|
|
|
path3=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = $repo; ref = \"master\"; }).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path3 ]]
|
|
|
|
|
2019-11-27 01:05:30 +02:00
|
|
|
path3=$(nix eval --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; }).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path = $path3 ]]
|
|
|
|
|
|
|
|
# Committing should not affect the store path.
|
|
|
|
git -C $repo commit -m 'Bla3' -a
|
|
|
|
|
2020-03-17 23:32:26 +02:00
|
|
|
path4=$(nix eval --impure --refresh --raw --expr "(builtins.fetchGit file://$repo).outPath")
|
2017-11-03 14:33:50 +02:00
|
|
|
[[ $path2 = $path4 ]]
|
2017-11-24 04:50:01 +02:00
|
|
|
|
2021-10-14 15:44:45 +03:00
|
|
|
[[ $(nix eval --impure --expr "builtins.hasAttr \"rev\" (builtins.fetchGit $repo)") == "true" ]]
|
|
|
|
[[ $(nix eval --impure --expr "builtins.hasAttr \"dirtyRev\" (builtins.fetchGit $repo)") == "false" ]]
|
|
|
|
[[ $(nix eval --impure --expr "builtins.hasAttr \"dirtyShortRev\" (builtins.fetchGit $repo)") == "false" ]]
|
|
|
|
|
2022-12-07 13:58:58 +02:00
|
|
|
status=0
|
2020-04-29 23:39:58 +03:00
|
|
|
nix eval --impure --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; narHash = \"sha256-B5yIPHhEm0eysJKEsO7nqxprh9vcblFxpJG11gXJus1=\"; }).outPath" || status=$?
|
|
|
|
[[ "$status" = "102" ]]
|
|
|
|
|
|
|
|
path5=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; narHash = \"sha256-Hr8g6AqANb3xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\"; }).outPath")
|
|
|
|
[[ $path = $path5 ]]
|
|
|
|
|
2017-11-24 04:50:01 +02:00
|
|
|
# tarball-ttl should be ignored if we specify a rev
|
|
|
|
echo delft > $repo/hello
|
|
|
|
git -C $repo add hello
|
|
|
|
git -C $repo commit -m 'Bla4'
|
|
|
|
rev3=$(git -C $repo rev-parse HEAD)
|
2019-11-27 01:05:30 +02:00
|
|
|
nix eval --tarball-ttl 3600 --expr "builtins.fetchGit { url = $repo; rev = \"$rev3\"; }" >/dev/null
|
2017-12-22 22:18:29 +02:00
|
|
|
|
|
|
|
# Update 'path' to reflect latest master
|
2019-11-27 01:05:30 +02:00
|
|
|
path=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$repo).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
|
|
|
|
# Check behavior when non-master branch is used
|
|
|
|
git -C $repo checkout $rev2 -b dev
|
|
|
|
echo dev > $repo/hello
|
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
# File URI uses dirty tree unless specified otherwise
|
2019-11-27 01:05:30 +02:00
|
|
|
path2=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$repo).outPath")
|
2020-01-21 17:27:53 +02:00
|
|
|
[ $(cat $path2/hello) = dev ]
|
2017-12-22 22:18:29 +02:00
|
|
|
|
|
|
|
# Using local path with branch other than 'master' should work when clean or dirty
|
2019-11-27 01:05:30 +02:00
|
|
|
path3=$(nix eval --impure --raw --expr "(builtins.fetchGit $repo).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
# (check dirty-tree handling was used)
|
2020-07-28 23:46:39 +03:00
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]]
|
2020-11-26 22:45:28 +02:00
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit $repo).shortRev") = 0000000 ]]
|
2021-12-13 22:31:20 +02:00
|
|
|
# Making a dirty tree clean again and fetching it should
|
|
|
|
# record correct revision information. See: #4140
|
|
|
|
echo world > $repo/hello
|
|
|
|
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit $repo).rev") = $rev2 ]]
|
2017-12-22 22:18:29 +02:00
|
|
|
|
|
|
|
# Committing shouldn't change store path, or switch to using 'master'
|
2021-12-13 22:31:20 +02:00
|
|
|
echo dev > $repo/hello
|
2017-12-22 22:18:29 +02:00
|
|
|
git -C $repo commit -m 'Bla5' -a
|
2019-11-27 01:05:30 +02:00
|
|
|
path4=$(nix eval --impure --raw --expr "(builtins.fetchGit $repo).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
[[ $(cat $path4/hello) = dev ]]
|
|
|
|
[[ $path3 = $path4 ]]
|
|
|
|
|
2021-04-20 14:52:50 +03:00
|
|
|
# Using remote path with branch other than 'master' should fetch the HEAD revision.
|
|
|
|
# (--tarball-ttl 0 to prevent using the cached repo above)
|
|
|
|
export _NIX_FORCE_HTTP=1
|
|
|
|
path4=$(nix eval --tarball-ttl 0 --impure --raw --expr "(builtins.fetchGit $repo).outPath")
|
|
|
|
[[ $(cat $path4/hello) = dev ]]
|
|
|
|
[[ $path3 = $path4 ]]
|
|
|
|
unset _NIX_FORCE_HTTP
|
|
|
|
|
2017-12-22 22:18:29 +02:00
|
|
|
# Confirm same as 'dev' branch
|
2019-11-27 01:05:30 +02:00
|
|
|
path5=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = $repo; ref = \"dev\"; }).outPath")
|
2017-12-22 22:18:29 +02:00
|
|
|
[[ $path3 = $path5 ]]
|
2018-01-09 16:58:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Nuke the cache
|
2020-03-17 23:32:26 +02:00
|
|
|
rm -rf $TEST_HOME/.cache/nix
|
2018-01-09 16:58:19 +02:00
|
|
|
|
2023-10-25 19:55:08 +03:00
|
|
|
# Try again. This should work.
|
2019-11-27 01:05:30 +02:00
|
|
|
path5=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = $repo; ref = \"dev\"; }).outPath")
|
2018-01-09 16:58:19 +02:00
|
|
|
[[ $path3 = $path5 ]]
|
2020-03-16 14:20:32 +02:00
|
|
|
|
2021-12-13 22:31:15 +02:00
|
|
|
# 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
|
|
|
|
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 ]]
|
|
|
|
|
2020-03-17 22:34:38 +02:00
|
|
|
# Fetching a shallow repo shouldn't work by default, because we can't
|
|
|
|
# return a revCount.
|
2020-03-16 14:20:32 +02:00
|
|
|
git clone --depth 1 file://$repo $TEST_ROOT/shallow
|
2020-03-17 22:34:38 +02:00
|
|
|
(! nix eval --impure --raw --expr "(builtins.fetchGit { url = $TEST_ROOT/shallow; ref = \"dev\"; }).outPath")
|
|
|
|
|
|
|
|
# But you can request a shallow clone, which won't return a revCount.
|
|
|
|
path6=$(nix eval --impure --raw --expr "(builtins.fetchTree { type = \"git\"; url = \"file://$TEST_ROOT/shallow\"; ref = \"dev\"; shallow = true; }).outPath")
|
2020-03-16 14:20:32 +02:00
|
|
|
[[ $path3 = $path6 ]]
|
2020-03-17 22:34:38 +02:00
|
|
|
[[ $(nix eval --impure --expr "(builtins.fetchTree { type = \"git\"; url = \"file://$TEST_ROOT/shallow\"; ref = \"dev\"; shallow = true; }).revCount or 123") == 123 ]]
|
2021-03-30 12:39:37 +03:00
|
|
|
|
libexpr: Support structured error classes
While preparing PRs like #9753, I've had to change error messages in
dozens of code paths. It would be nice if instead of
EvalError("expected 'boolean' but found '%1%'", showType(v))
we could write
TypeError(v, "boolean")
or similar. Then, changing the error message could be a mechanical
refactor with the compiler pointing out places the constructor needs to
be changed, rather than the error-prone process of grepping through the
codebase. Structured errors would also help prevent the "same" error
from having multiple slightly different messages, and could be a first
step towards error codes / an error index.
This PR reworks the exception infrastructure in `libexpr` to
support exception types with different constructor signatures than
`BaseError`. Actually refactoring the exceptions to use structured data
will come in a future PR (this one is big enough already, as it has to
touch every exception in `libexpr`).
The core design is in `eval-error.hh`. Generally, errors like this:
state.error("'%s' is not a string", getAttrPathStr())
.debugThrow<TypeError>()
are transformed like this:
state.error<TypeError>("'%s' is not a string", getAttrPathStr())
.debugThrow()
The type annotation has moved from `ErrorBuilder::debugThrow` to
`EvalState::error`.
2024-01-23 03:08:29 +02:00
|
|
|
expectStderr 1 nix eval --expr 'builtins.fetchTree { type = "git"; url = "file:///foo"; }' | grepQuiet "fetchTree requires a locked input"
|
2024-01-24 14:19:02 +02:00
|
|
|
|
2021-03-30 12:39:37 +03:00
|
|
|
# Explicit ref = "HEAD" should work, and produce the same outPath as without ref
|
|
|
|
path7=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; }).outPath")
|
|
|
|
path8=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; }).outPath")
|
|
|
|
[[ $path7 = $path8 ]]
|
|
|
|
|
|
|
|
# ref = "HEAD" should fetch the HEAD revision
|
|
|
|
rev4=$(git -C $repo rev-parse HEAD)
|
|
|
|
rev4_nix=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; }).rev")
|
|
|
|
[[ $rev4 = $rev4_nix ]]
|
2021-07-05 14:09:46 +03:00
|
|
|
|
|
|
|
# The name argument should be handled
|
|
|
|
path9=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; name = \"foo\"; }).outPath")
|
|
|
|
[[ $path9 =~ -foo$ ]]
|
2022-01-01 22:26:41 +02:00
|
|
|
|
2022-10-15 01:27:13 +03:00
|
|
|
# Specifying a ref without a rev shouldn't pick a cached rev for a different ref
|
|
|
|
export _NIX_FORCE_HTTP=1
|
|
|
|
rev_tag1_nix=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"refs/tags/tag1\"; }).rev")
|
|
|
|
rev_tag1=$(git -C $repo rev-parse refs/tags/tag1)
|
|
|
|
[[ $rev_tag1_nix = $rev_tag1 ]]
|
|
|
|
rev_tag2_nix=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"refs/tags/tag2\"; }).rev")
|
|
|
|
rev_tag2=$(git -C $repo rev-parse refs/tags/tag2)
|
|
|
|
[[ $rev_tag2_nix = $rev_tag2 ]]
|
|
|
|
unset _NIX_FORCE_HTTP
|
|
|
|
|
2023-11-19 15:37:42 +02:00
|
|
|
# Ensure .gitattributes is respected
|
|
|
|
touch $repo/not-exported-file
|
2023-11-27 23:34:41 +02:00
|
|
|
touch $repo/exported-wonky
|
2023-11-19 15:37:42 +02:00
|
|
|
echo "/not-exported-file export-ignore" >> $repo/.gitattributes
|
2023-11-27 23:34:41 +02:00
|
|
|
echo "/exported-wonky export-ignore=wonk" >> $repo/.gitattributes
|
|
|
|
git -C $repo add not-exported-file exported-wonky .gitattributes
|
2023-11-19 15:37:42 +02:00
|
|
|
git -C $repo commit -m 'Bla6'
|
|
|
|
rev5=$(git -C $repo rev-parse HEAD)
|
|
|
|
path12=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = file://$repo; rev = \"$rev5\"; }).outPath")
|
|
|
|
[[ ! -e $path12/not-exported-file ]]
|
2023-11-27 23:34:41 +02:00
|
|
|
[[ -e $path12/exported-wonky ]]
|
2023-11-19 15:37:42 +02:00
|
|
|
|
2022-01-01 22:26:41 +02:00
|
|
|
# should fail if there is no repo
|
|
|
|
rm -rf $repo/.git
|
|
|
|
(! nix eval --impure --raw --expr "(builtins.fetchGit \"file://$repo\").outPath")
|
|
|
|
|
|
|
|
# should succeed for a repo without commits
|
|
|
|
git init $repo
|
2023-10-25 19:55:08 +03:00
|
|
|
git -C $repo add hello # need to add at least one file to cause the root of the repo to be visible
|
2022-01-01 22:26:41 +02:00
|
|
|
path10=$(nix eval --impure --raw --expr "(builtins.fetchGit \"file://$repo\").outPath")
|
2023-02-27 16:33:54 +02:00
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
|
|
|
echo utrecht > "$repo/hello"
|
|
|
|
touch "$repo/.gitignore"
|
|
|
|
git -C "$repo" add hello .gitignore
|
|
|
|
git -C "$repo" commit -m 'Bla1'
|
|
|
|
cd "$repo"
|
|
|
|
path11=$(nix eval --impure --raw --expr "(builtins.fetchGit ./.).outPath")
|
2024-02-20 12:40:02 +02:00
|
|
|
|
|
|
|
# Test a workdir with no commits.
|
|
|
|
empty="$TEST_ROOT/empty"
|
|
|
|
git init "$empty"
|
|
|
|
|
|
|
|
emptyAttrs='{ lastModified = 0; lastModifiedDate = "19700101000000"; narHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; rev = "0000000000000000000000000000000000000000"; revCount = 0; shortRev = "0000000"; submodules = false; }'
|
|
|
|
|
|
|
|
[[ $(nix eval --impure --expr "builtins.removeAttrs (builtins.fetchGit $empty) [\"outPath\"]") = $emptyAttrs ]]
|
|
|
|
|
|
|
|
echo foo > "$empty/x"
|
|
|
|
|
|
|
|
[[ $(nix eval --impure --expr "builtins.removeAttrs (builtins.fetchGit $empty) [\"outPath\"]") = $emptyAttrs ]]
|
|
|
|
|
|
|
|
git -C "$empty" add x
|
|
|
|
|
|
|
|
[[ $(nix eval --impure --expr "builtins.removeAttrs (builtins.fetchGit $empty) [\"outPath\"]") = '{ lastModified = 0; lastModifiedDate = "19700101000000"; narHash = "sha256-wzlAGjxKxpaWdqVhlq55q5Gxo4Bf860+kLeEa/v02As="; rev = "0000000000000000000000000000000000000000"; revCount = 0; shortRev = "0000000"; submodules = false; }' ]]
|
|
|
|
|
|
|
|
# Test a repo with an empty commit.
|
|
|
|
git -C "$empty" rm -f x
|
|
|
|
|
|
|
|
git -C "$empty" config user.email "foobar@example.com"
|
|
|
|
git -C "$empty" config user.name "Foobar"
|
|
|
|
git -C "$empty" commit --allow-empty --allow-empty-message --message ""
|
|
|
|
|
|
|
|
nix eval --impure --expr "let attrs = builtins.fetchGit $empty; in assert attrs.lastModified != 0; assert attrs.rev != \"0000000000000000000000000000000000000000\"; assert attrs.revCount == 1; true"
|