From a649a536792eade93238e3e273f53604d65c3db9 Mon Sep 17 00:00:00 2001 From: Josh Spence Date: Wed, 9 Jul 2025 10:56:22 +1000 Subject: [PATCH] Add test cases --- tests/functional/fetchGit.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/functional/fetchGit.sh b/tests/functional/fetchGit.sh index a41aa35c0..7ebab2ab7 100755 --- a/tests/functional/fetchGit.sh +++ b/tests/functional/fetchGit.sh @@ -303,3 +303,26 @@ 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" + +# Test a repo with `eol=crlf`. +repo="$TEST_ROOT/crlf" +git init "$repo" +git -C $repo config user.email "foobar@example.com" +git -C $repo config user.name "Foobar" + +echo -n -e 'foo\nbar\nbaz' > "$repo/newlines.txt" +echo -n -e 'foo\nbar\nbaz' > "$repo/test.txt" +git -C "$repo" add newlines.txt test.txt +git -C "$repo" commit -m 'Add files containing LF line endings' +echo 'test.txt eol=crlf' > "$repo/.gitattributes" +git -C "$repo" add .gitattributes +git -C "$repo" commit -m 'Add eol=crlf to gitattributes' +narhash=$(nix eval --raw --impure --expr "(builtins.fetchGit { url = \"$repo\"; ref = \"master\"; }).narHash") +[[ "$narhash" = "sha256-k7u7RAaF+OvrbtT3KCCDQA8e9uOdflUo5zSgsosoLzA=" ]] + +# Ensure that NAR hash doesn't depend on user configuration. +rm -rf $TEST_HOME/.cache/nix +export GIT_CONFIG_GLOBAL="$TEST_ROOT/gitconfig" +git config --global core.autocrlf true +new_narhash=$(nix eval --raw --impure --expr "(builtins.fetchGit { url = \"$repo\"; ref = \"master\"; }).narHash") +[[ "$new_narhash" = "$narhash" ]]