summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorelseym <elseym@me.com>2020-01-14 21:08:38 +0100
committerelseym <elseym@me.com>2020-01-14 21:08:38 +0100
commit9d396d2e426b9a765de0b8999aa214f1259633e6 (patch)
tree7cdce5dfcba76380b03f5a990f0c2a403f19da2a /lib
parent10b1ba0c936843c1e9b13d32a08ff8b51aeb7b24 (diff)
downloadnixpkgs-9d396d2e426b9a765de0b8999aa214f1259633e6.tar
nixpkgs-9d396d2e426b9a765de0b8999aa214f1259633e6.tar.gz
nixpkgs-9d396d2e426b9a765de0b8999aa214f1259633e6.tar.bz2
nixpkgs-9d396d2e426b9a765de0b8999aa214f1259633e6.tar.lz
nixpkgs-9d396d2e426b9a765de0b8999aa214f1259633e6.tar.xz
nixpkgs-9d396d2e426b9a765de0b8999aa214f1259633e6.tar.zst
nixpkgs-9d396d2e426b9a765de0b8999aa214f1259633e6.zip
lib.commitIdFromGitRepo: fix support for git-submodule
Adds handling for relative references from .git-files, fixing a bug introduced by c9214c394b248e1f26e45dbe1be2bd82363af3a6.
Diffstat (limited to 'lib')
-rw-r--r--lib/sources.nix10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/sources.nix b/lib/sources.nix
index 0fd172c42b7..a5765c0fda5 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -113,6 +113,10 @@ rec {
       with builtins;
         let fileName       = toString path + "/" + file;
             packedRefsName = toString path + "/packed-refs";
+            absolutePath   = base: path:
+              if lib.hasPrefix "/" path
+              then path
+              else toString (/. + "${base}/${path}");
         in if pathIsRegularFile path
            # Resolve git worktrees. See gitrepository-layout(5)
            then
@@ -120,13 +124,11 @@ rec {
              in if m == null
                 then throw ("File contains no gitdir reference: " + path)
                 else
-                  let gitDir     = lib.head m;
+                  let gitDir     = absolutePath (dirOf path) (lib.head m);
                       commonDir' = if pathIsRegularFile "${gitDir}/commondir"
                                    then lib.fileContents "${gitDir}/commondir"
                                    else gitDir;
-                      commonDir  = if lib.hasPrefix "/" commonDir'
-                                   then commonDir'
-                                   else toString (/. + "${gitDir}/${commonDir'}");
+                      commonDir  = absolutePath gitDir commonDir';
                       refFile    = lib.removePrefix "${commonDir}/" "${gitDir}/${file}";
                   in readCommitFromFile refFile commonDir