about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-12-12 01:19:00 +0100
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-12-19 01:46:15 +0100
commit74f2e495436983b9b3d8c9a94a638bb411cfb245 (patch)
tree04a62a57ab232213cbbaf28a288f80fb21be03f8 /lib
parent2f3e65ad7bf63d3c07f95ddcf41d3ea7473d3abd (diff)
downloadnixlib-74f2e495436983b9b3d8c9a94a638bb411cfb245.tar
nixlib-74f2e495436983b9b3d8c9a94a638bb411cfb245.tar.gz
nixlib-74f2e495436983b9b3d8c9a94a638bb411cfb245.tar.bz2
nixlib-74f2e495436983b9b3d8c9a94a638bb411cfb245.tar.lz
nixlib-74f2e495436983b9b3d8c9a94a638bb411cfb245.tar.xz
nixlib-74f2e495436983b9b3d8c9a94a638bb411cfb245.tar.zst
nixlib-74f2e495436983b9b3d8c9a94a638bb411cfb245.zip
lib.fileset.fetchGit: Refactoring
Diffstat (limited to 'lib')
-rw-r--r--lib/fileset/internal.nix42
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/fileset/internal.nix b/lib/fileset/internal.nix
index 9de5590d3eff..c8a659cd09fd 100644
--- a/lib/fileset/internal.nix
+++ b/lib/fileset/internal.nix
@@ -861,28 +861,34 @@ rec {
   # Type: String -> String -> Path -> Attrs -> FileSet
   _fromFetchGit = function: argument: path: extraFetchGitAttrs:
     let
-      # This imports the files unnecessarily, which currently can't be avoided
-      # because `builtins.fetchGit` is the only function exposing which files are tracked by Git.
-      # With the [lazy trees PR](https://github.com/NixOS/nix/pull/6530),
-      # the unnecessarily import could be avoided.
-      # However a simpler alternative still would be [a builtins.gitLsFiles](https://github.com/NixOS/nix/issues/2944).
-      fetchResult = fetchGit ({
-        url = path;
-      } // extraFetchGitAttrs);
+      tryFetchGit =
+        let
+          # This imports the files unnecessarily, which currently can't be avoided
+          # because `builtins.fetchGit` is the only function exposing which files are tracked by Git.
+          # With the [lazy trees PR](https://github.com/NixOS/nix/pull/6530),
+          # the unnecessarily import could be avoided.
+          # However a simpler alternative still would be [a builtins.gitLsFiles](https://github.com/NixOS/nix/issues/2944).
+          fetchResult = fetchGit ({
+            url = path;
+          } // extraFetchGitAttrs);
+        in
+        if inPureEvalMode then
+          throw "lib.fileset.${function}: This function is currently not supported in pure evaluation mode, since it currently relies on `builtins.fetchGit`. See https://github.com/NixOS/nix/issues/9292."
+        # We can identify local working directories by checking for .git,
+        # see https://git-scm.com/docs/gitrepository-layout#_description.
+        # Note that `builtins.fetchGit` _does_ work for bare repositories (where there's no `.git`),
+        # even though `git ls-files` wouldn't return any files in that case.
+        else if ! pathExists (path + "/.git") then
+          throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to point to a local working tree of a Git repository, but it's not."
+        else
+          _mirrorStorePath path fetchResult.outPath;
+
     in
-    if inPureEvalMode then
-      throw "lib.fileset.${function}: This function is currently not supported in pure evaluation mode, since it currently relies on `builtins.fetchGit`. See https://github.com/NixOS/nix/issues/9292."
-    else if ! isPath path then
+    if ! isPath path then
       throw "lib.fileset.${function}: Expected the ${argument} to be a path, but it's a ${typeOf path} instead."
     else if pathType path != "directory" then
       throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to be a directory, but it's a file instead."
-    # We can identify local working directories by checking for .git,
-    # see https://git-scm.com/docs/gitrepository-layout#_description.
-    # Note that `builtins.fetchGit` _does_ work for bare repositories (where there's no `.git`),
-    # even though `git ls-files` wouldn't return any files in that case.
-    else if ! pathExists (path + "/.git") then
-      throw "lib.fileset.${function}: Expected the ${argument} (${toString path}) to point to a local working tree of a Git repository, but it's not."
     else
-      _mirrorStorePath path fetchResult.outPath;
+      tryFetchGit;
 
 }