diff --git a/lib/sources.nix b/lib/sources.nix index 8e58e4b6a9dd..535b04523b57 100644 --- a/lib/sources.nix +++ b/lib/sources.nix @@ -55,10 +55,11 @@ rec { # packed-refs file, so we have to grep through it: else if lib.pathExists packedRefsName then - let packedRefs = lib.splitString "\n" (readFile packedRefsName); - matchRule = match ("^(.*) " + file + "$"); - matchedRefs = lib.flatten (lib.filter (m: ! (isNull m)) (map matchRule packedRefs)); - in lib.head matchedRefs + let fileContent = readFile packedRefsName; + matchRef = match ".*\n([^\n ]*) " + file + "\n.*" fileContent; + in if isNull matchRef + then throw ("Could not find " + file + " in " + packedRefsName) + else lib.head matchRef else throw ("Not a .git directory: " + path); in lib.flip readCommitFromFile "HEAD"; }