lib.commitIdFromGitRepo: fix support for git-submodule
Adds handling for relative references from .git-files, fixing a bug introduced by c9214c394b
.
This commit is contained in:
parent
10b1ba0c93
commit
9d396d2e42
@ -113,6 +113,10 @@ rec {
|
|||||||
with builtins;
|
with builtins;
|
||||||
let fileName = toString path + "/" + file;
|
let fileName = toString path + "/" + file;
|
||||||
packedRefsName = toString path + "/packed-refs";
|
packedRefsName = toString path + "/packed-refs";
|
||||||
|
absolutePath = base: path:
|
||||||
|
if lib.hasPrefix "/" path
|
||||||
|
then path
|
||||||
|
else toString (/. + "${base}/${path}");
|
||||||
in if pathIsRegularFile path
|
in if pathIsRegularFile path
|
||||||
# Resolve git worktrees. See gitrepository-layout(5)
|
# Resolve git worktrees. See gitrepository-layout(5)
|
||||||
then
|
then
|
||||||
@ -120,13 +124,11 @@ rec {
|
|||||||
in if m == null
|
in if m == null
|
||||||
then throw ("File contains no gitdir reference: " + path)
|
then throw ("File contains no gitdir reference: " + path)
|
||||||
else
|
else
|
||||||
let gitDir = lib.head m;
|
let gitDir = absolutePath (dirOf path) (lib.head m);
|
||||||
commonDir' = if pathIsRegularFile "${gitDir}/commondir"
|
commonDir' = if pathIsRegularFile "${gitDir}/commondir"
|
||||||
then lib.fileContents "${gitDir}/commondir"
|
then lib.fileContents "${gitDir}/commondir"
|
||||||
else gitDir;
|
else gitDir;
|
||||||
commonDir = if lib.hasPrefix "/" commonDir'
|
commonDir = absolutePath gitDir commonDir';
|
||||||
then commonDir'
|
|
||||||
else toString (/. + "${gitDir}/${commonDir'}");
|
|
||||||
refFile = lib.removePrefix "${commonDir}/" "${gitDir}/${file}";
|
refFile = lib.removePrefix "${commonDir}/" "${gitDir}/${file}";
|
||||||
in readCommitFromFile refFile commonDir
|
in readCommitFromFile refFile commonDir
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user