···
in type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts;
in cleanSourceWith { inherit filter src; };
169
-
pathIsGitRepo = path: (tryEval (commitIdFromGitRepo path)).success;
169
+
pathIsGitRepo = path: (commitIdFromGitRepoOrError path)?value;
172
+
Get the commit id of a git repo.
174
+
Example: commitIdFromGitRepo <nixpkgs/.git>
176
+
commitIdFromGitRepo = path:
177
+
let commitIdOrError = commitIdFromGitRepoOrError path;
178
+
in commitIdOrError.value or (throw commitIdOrError.error);
Get the commit id of a git repo.
183
+
Returns `{ value = commitHash }` or `{ error = "... message ..." }`.
Example: commitIdFromGitRepo <nixpkgs/.git>
176
-
commitIdFromGitRepo =
187
+
commitIdFromGitRepoOrError =
let readCommitFromFile = file: path:
178
-
let fileName = toString path + "/" + file;
179
-
packedRefsName = toString path + "/packed-refs";
189
+
let fileName = path + "/${file}";
190
+
packedRefsName = path + "/packed-refs";
absolutePath = base: path:
if lib.hasPrefix "/" path
···
let m = match "^gitdir: (.*)$" (lib.fileContents path);
189
-
then throw ("File contains no gitdir reference: " + path)
200
+
then { error = "File contains no gitdir reference: " + path; }
let gitDir = absolutePath (dirOf path) (lib.head m);
commonDir'' = if pathIsRegularFile "${gitDir}/commondir"
···
let fileContent = lib.fileContents fileName;
matchRef = match "^ref: (.*)$" fileContent;
218
+
then { value = fileContent; }
else readCommitFromFile (lib.head matchRef) path
else if pathIsRegularFile packedRefsName
···
# https://github.com/NixOS/nix/issues/2147#issuecomment-659868795
refs = filter isRef (split "\n" fileContent);
221
-
then throw ("Could not find " + file + " in " + packedRefsName)
222
-
else lib.head (matchRef (lib.head refs))
232
+
then { error = "Could not find " + file + " in " + packedRefsName; }
233
+
else { value = lib.head (matchRef (lib.head refs)); }
224
-
else throw ("Not a .git directory: " + path);
235
+
else { error = "Not a .git directory: " + toString path; };
in readCommitFromFile "HEAD";
pathHasContext = builtins.hasContext or (lib.hasPrefix storeDir);