diff options
author | Léo Gaspard <leo@gaspard.io> | 2021-03-27 21:16:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-27 21:16:31 +0100 |
commit | 144a997c8e58c996330c1bf4cb78430f3e18a498 (patch) | |
tree | 0b56e627b1341dfe7656d223652abc8c46d00072 /lib/sources.nix | |
parent | cb231de72bae23b42cba47ac4540eafb801b0a60 (diff) | |
download | nixpkgs-144a997c8e58c996330c1bf4cb78430f3e18a498.tar nixpkgs-144a997c8e58c996330c1bf4cb78430f3e18a498.tar.gz nixpkgs-144a997c8e58c996330c1bf4cb78430f3e18a498.tar.bz2 nixpkgs-144a997c8e58c996330c1bf4cb78430f3e18a498.tar.lz nixpkgs-144a997c8e58c996330c1bf4cb78430f3e18a498.tar.xz nixpkgs-144a997c8e58c996330c1bf4cb78430f3e18a498.tar.zst nixpkgs-144a997c8e58c996330c1bf4cb78430f3e18a498.zip |
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.)
Diffstat (limited to 'lib/sources.nix')
-rw-r--r-- | lib/sources.nix | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/sources.nix b/lib/sources.nix index 1a3afcae67d..1a821f55056 100644 --- a/lib/sources.nix +++ b/lib/sources.nix @@ -138,12 +138,13 @@ rec { in if m == null then throw ("File contains no gitdir reference: " + path) else - let gitDir = absolutePath (dirOf path) (lib.head m); - commonDir' = if pathIsRegularFile "${gitDir}/commondir" - then lib.fileContents "${gitDir}/commondir" - else gitDir; - commonDir = absolutePath gitDir commonDir'; - refFile = lib.removePrefix "${commonDir}/" "${gitDir}/${file}"; + let gitDir = absolutePath (dirOf path) (lib.head m); + commonDir'' = if pathIsRegularFile "${gitDir}/commondir" + then lib.fileContents "${gitDir}/commondir" + else gitDir; + commonDir' = lib.removeSuffix "/" commonDir''; + commonDir = absolutePath gitDir commonDir'; + refFile = lib.removePrefix "${commonDir}/" "${gitDir}/${file}"; in readCommitFromFile refFile commonDir else if pathIsRegularFile fileName |