Skip to content

Commit c1ab3bb

Browse files
committed
Handle the change in export-ignore default behaviour as well
1 parent 04b1b1e commit c1ab3bb

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/libfetchers/git.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -790,27 +790,27 @@ struct GitInputScheme : InputScheme
790790
bool smudgeLfs = getLfsAttr(input);
791791
auto accessor = repo->getAccessor(rev, exportIgnore, "«" + input.to_string(true) + "»", smudgeLfs);
792792

793-
/* Backward compatibility hack for locks produced by Nix < 2.20 that depend on Git filters. Nix >= 2.20 doesn't
794-
* apply Git filters, so we may get a NAR hash mismatch. If that happens, try again with filters enabled. */
793+
/* Backward compatibility hack for locks produced by Nix < 2.20 that depend on Nix applying Git filters or
794+
* `export-ignore`. Nix >= 2.20 doesn't do those, so we may get a NAR hash mismatch. If that happens, try again
795+
* with filters and export-ignore enabled. */
795796
if (auto expectedNarHash = input.getNarHash()) {
796797
if (accessor->pathExists(CanonPath(".gitattributes"))) {
797798
accessor->fingerprint = makeFingerprint(input, rev);
798-
auto narHashNoFilters =
799+
auto narHashNew =
799800
fetchToStore2(settings, *store, {accessor}, FetchMode::DryRun, input.getName()).second;
800-
if (expectedNarHash != narHashNoFilters) {
801-
auto accessor2 =
802-
repo->getAccessor(rev, exportIgnore, "«" + input.to_string(true) + "»", smudgeLfs, true);
803-
accessor2->fingerprint = makeFingerprint(input, rev) + ";f";
804-
auto narHashFilters =
801+
if (expectedNarHash != narHashNew) {
802+
auto accessor2 = repo->getAccessor(rev, true, "«" + input.to_string(true) + "»", smudgeLfs, true);
803+
accessor2->fingerprint = makeFingerprint(input, rev) + ";e;f";
804+
auto narHashOld =
805805
fetchToStore2(settings, *store, {accessor2}, FetchMode::DryRun, input.getName()).second;
806-
if (expectedNarHash == narHashFilters) {
806+
if (expectedNarHash == narHashOld) {
807807
warn(
808-
"Git input '%s' specifies a NAR hash '%s' that is only correct if Git filters are applied.\n"
809-
"This is pre-Nix 2.20 behavior; in Nix 2.20 and later, Git filters are not applied.\n"
808+
"Git input '%s' specifies a NAR hash '%s' that was created by Nix < 2.20.\n"
809+
"Nix >= 2.20 does not apply Git filters and `export-ignore` by default, which changes the NAR hash.\n"
810810
"Please update the NAR hash to '%s'.",
811811
input.to_string(),
812812
expectedNarHash->to_string(HashFormat::SRI, true),
813-
narHashNoFilters.to_string(HashFormat::SRI, true));
813+
narHashNew.to_string(HashFormat::SRI, true));
814814
accessor = accessor2;
815815
}
816816
}

tests/functional/fetchGit.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,23 +318,27 @@ git init "$eol"
318318
git -C "$eol" config user.email "foobar@example.com"
319319
git -C "$eol" config user.name "Foobar"
320320
printf "Hello\nWorld\n" > "$eol/crlf"
321-
git -C "$eol" add crlf
321+
printf "ignore me" > "$eol/ignored"
322+
git -C "$eol" add crlf ignored
322323
git -C "$eol" commit -a -m Initial
323-
printf "crlf text eol=crlf\n" > "$eol/.gitattributes"
324+
printf "crlf text eol=crlf\nignored export-ignore\n" > "$eol/.gitattributes"
324325
git -C "$eol" add .gitattributes
325326
git -C "$eol" commit -a -m 'Apply gitattributes'
326327

327328
rev="$(git -C "$eol" rev-parse HEAD)"
328329

329330
export _NIX_TEST_BARF_ON_UNCACHEABLE=1
330331

332+
oldHash="sha256-OizkFa+lIZbi+DCfbH8AYzsJ+BRmW0u/a7KKuzXADEU="
333+
newHash="sha256-hKHmbBsoVwqPNkL0MXL0RAtbOCqK6tP4xpX2tKR6GPI="
334+
331335
expectStderr 0 nix eval --expr \
332-
"assert builtins.readFile \"\${builtins.fetchTree { type = \"git\"; url = \"file://$eol\"; rev = \"$rev\"; narHash = \"sha256-kxXTCbD8wCYT9qNDKzl9bNKO8++pKY2QwAhqSqENP5k=\"; }}/crlf\" == \"Hello\r\nWorld\r\n\"; true" \
333-
| grepQuiet "Please update the NAR hash to 'sha256-LDLvcwdcwCxnuPTxSQ6gLAyopB20lD0bOQoQB3i2hsA='"
336+
"let tree = builtins.fetchTree { type = \"git\"; url = \"file://$eol\"; rev = \"$rev\"; narHash = \"$oldHash\"; }; in assert builtins.readFile \"\${tree}/crlf\" == \"Hello\r\nWorld\r\n\"; assert !builtins.pathExists \"\${tree}/ignored\"; true" \
337+
| grepQuiet "Please update the NAR hash to '$newHash'"
334338

335339
nix eval --expr \
336-
"assert builtins.readFile \"\${builtins.fetchTree { type = \"git\"; url = \"file://$eol\"; rev = \"$rev\"; narHash = \"sha256-LDLvcwdcwCxnuPTxSQ6gLAyopB20lD0bOQoQB3i2hsA=\"; }}/crlf\" == \"Hello\nWorld\n\"; true"
340+
"let tree = builtins.fetchTree { type = \"git\"; url = \"file://$eol\"; rev = \"$rev\"; narHash = \"$newHash\"; }; in assert builtins.readFile \"\${tree}/crlf\" == \"Hello\nWorld\n\"; assert builtins.pathExists \"\${tree}/ignored\"; true"
337341

338342
expectStderr 102 nix eval --expr \
339-
"assert builtins.readFile \"\${builtins.fetchTree { type = \"git\"; url = \"file://$eol\"; rev = \"$rev\"; narHash = \"sha256-DLDvcwdcwCxnuPTxSQ6gLAyopB20lD0bOQoQB3i2hsA=\"; }}/crlf\" == \"Hello\nWorld\n\"; true" \
343+
"builtins.fetchTree { type = \"git\"; url = \"file://$eol\"; rev = \"$rev\"; narHash = \"sha256-DLDvcwdcwCxnuPTxSQ6gLAyopB20lD0bOQoQB3i2hsA=\"; }" \
340344
| grepQuiet "NAR hash mismatch"

0 commit comments

Comments
 (0)