From 120bec5595ba3fa3041bac8453980b59db1e4415 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 31 Aug 2022 16:09:27 +0200 Subject: [PATCH] GitInputScheme: Do not record 'ref' for dirty trees The URLs 'git+file:///foo' and 'git+file:///foo?rev=bla' are not exactly the same. The former can use the dirty tree at /foo, while the latter won't (it will use the latest committed revision of branch 'bla'). So since we use the latter in the in-memory lock file, the subsequent call to fetchTree won't be able to see any dirty changes to /foo, which isn't what we want. --- src/libfetchers/git.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index faede2eed..0270ed502 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -281,7 +281,7 @@ struct GitInputScheme : InputScheme /* URL of the repo, or its path if isLocal. */ std::string url; - void checkDirty() const + void warnDirty() const { if (isDirty) { if (!fetchSettings.allowDirty) @@ -753,12 +753,10 @@ struct GitInputScheme : InputScheme return {accessor, input}; } - repoInfo.checkDirty(); - - auto ref = getDefaultRef(repoInfo); - input.attrs.insert_or_assign("ref", ref); - if (!repoInfo.isDirty) { + auto ref = getDefaultRef(repoInfo); + input.attrs.insert_or_assign("ref", ref); + auto rev = updateRev(input, repoInfo, ref); input.attrs.insert_or_assign( @@ -769,11 +767,13 @@ struct GitInputScheme : InputScheme "lastModified", getLastModified(repoInfo, repoInfo.url, rev)); } else { + repoInfo.warnDirty(); + // FIXME: maybe we should use the timestamp of the last // modified dirty file? input.attrs.insert_or_assign( "lastModified", - getLastModified(repoInfo, repoInfo.url, ref)); + getLastModified(repoInfo, repoInfo.url, "HEAD")); } return {makeFSInputAccessor(CanonPath(repoInfo.url), listFiles(repoInfo), std::move(makeNotAllowedError)), input};