git.iko.soy/typeable/nixpkgs
on master help sign in
lib: fix commitIdFromGitRepo (#117752)

When in the presence of worktrees, it happens that /commondir has a trailing slash. In these circumstances, it can lead to `lib.pathType` being passed paths like `/foo/bar/.git/`, which in turn lead to `error: attribute '.git' missing`. With this change, we now make sure send properly-formatted paths to all other functions. This, in particular, fixes running NixOS tests on worktrees created by libgit2 on my machine. (Worktrees created by git itself appear to not hit the issue.)

commit144a997c8e58c996330c1bf4cb78430f3e18a498 authorLéo Gaspard <leo@gaspard.io> dateSat 27 Mar 2021, 21:16 (6 years ago) parentcb231de
1 file changed+7−6
lib/sources.nix+7−6
lib/sources.nix+7−6
@@ -138,12 +138,13 @@ rec {
138138 in if m == null
139139 then throw ("File contains no gitdir reference: " + path)
140140 else
141− let gitDir = absolutePath (dirOf path) (lib.head m);
142− commonDir' = if pathIsRegularFile "${gitDir}/commondir"
143− then lib.fileContents "${gitDir}/commondir"
144− else gitDir;
145− commonDir = absolutePath gitDir commonDir';
146− refFile = lib.removePrefix "${commonDir}/" "${gitDir}/${file}";
141+ let gitDir = absolutePath (dirOf path) (lib.head m);
142+ commonDir'' = if pathIsRegularFile "${gitDir}/commondir"
143+ then lib.fileContents "${gitDir}/commondir"
144+ else gitDir;
145+ commonDir' = lib.removeSuffix "/" commonDir'';
146+ commonDir = absolutePath gitDir commonDir';
147+ refFile = lib.removePrefix "${commonDir}/" "${gitDir}/${file}";
147148 in readCommitFromFile refFile commonDir
148149
149150 else if pathIsRegularFile fileName