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.
This commit is contained in:
Eelco Dolstra 2022-08-31 16:09:27 +02:00
parent 89f10212f6
commit 120bec5595

View file

@ -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};