Skip to content

Commit d8d6d90

Browse files
committed
Parse non-sha1 refs in pin-depends
Fixes #12
1 parent c9176ab commit d8d6d90

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/opam.nix

+11-6
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,22 @@ in rec {
386386
baseUrl = last (splitString "+" fullUrl); # Get rid of "git+"
387387
urlParts = splitString "#" baseUrl;
388388
url = head urlParts;
389-
rev = last urlParts;
390-
hasRev = length urlParts > 1;
391-
optionalRev = optionalAttrs hasRev { inherit rev; };
392-
allRefsOrWarn = if lib.versionAtLeast __nixVersion "2.4" then {
389+
ref = last urlParts;
390+
hasRef = length urlParts > 1;
391+
isRev = s: !isNull (builtins.match "[0-9a-f]{40}" s);
392+
hasRev = hasRef && isRev ref;
393+
optionalRev = optionalAttrs hasRev { rev = ref; };
394+
refsOrWarn = if hasRef && !isRev ref then {
395+
inherit ref;
396+
} else if lib.versionAtLeast __nixVersion "2.4" then {
393397
allRefs = true;
394398
} else
395399
lib.warn
396400
"Nix version is too old for allRefs = true; fetching a repository may fail if the commit is on a non-master branch"
397401
{ };
398-
path = (builtins.fetchGit
399-
({ inherit url; } // allRefsOrWarn // optionalRev)) // {
402+
path =
403+
(builtins.fetchGit ({ inherit url; } // refsOrWarn // optionalRev))
404+
// {
400405
inherit url;
401406
};
402407
repo = filterOpamRepo { ${name} = null; } (makeOpamRepo path);

0 commit comments

Comments
 (0)