on iko/ghcjs-patch-master help sign in
Improve cleanGit error handling (#408)
commit50180fb684d683fa51498687e0d32e083de3218e authorJonas Carpay <jonascarpay@gmail.com> dateTue 21 Jan 2020, 18:07 (7 years ago) parent6aca3f2
1 file changed+17−14
lib/clean-git.nix+17−14
lib/clean-git.nix+17−14
@@ -54,7 +54,8 @@ in
5454if builtins.pathExists (toString src + "/.git")
5555then
5656 let
57− isWorktree = !builtins.pathExists (toString src + "/.git/index");
57+ hasIndex = builtins.pathExists (toString src + "/.git/index");
58+ isWorktree = (builtins.readDir (toString src)).".git" == "regular";
5859
5960 # Identify the .git directory and filter just the files that we need.
6061 gitDir = cleanSourceWith ({
@@ -66,20 +67,22 @@ then
6667 lib.any (i: (lib.hasSuffix i path)) [
6768 "/config" "/index" "/HEAD" "/objects" "/refs" ]);
6869 } // (
69− if !isWorktree
70+ if hasIndex
7071 then { inherit src; subDir = ".git"; }
71− else {
72− # likely a git worktree, so follow the indirection
73− src =
74− let
75− git_content = lines (readFile (toString src + "/.git"));
76− first_line = head git_content;
77− prefix = "gitdir: ";
78− ok = length git_content == 1 && has_prefix prefix first_line;
79− in
80− if ok
81− then /. + remove_prefix prefix first_line
82− else abort "gitSource.nix: Cannot parse ${toString src + "/.git"}";
72+ else if !isWorktree
73+ then abort "cleanGit: ${toString src + "/.git"} has no index file"
74+ else {
75+ # likely a git worktree, so follow the indirection
76+ src =
77+ let
78+ git_content = lines (readFile (toString src + "/.git"));
79+ first_line = head git_content;
80+ prefix = "gitdir: ";
81+ ok = length git_content == 1 && has_prefix prefix first_line;
82+ in
83+ if ok
84+ then /. + remove_prefix prefix first_line
85+ else abort "gitSource.nix: Cannot parse ${toString src + "/.git"}";
8386 }));
8487
8588 # Worktrees have a commondir pointing to the common `.git` dir. We need the