Allow use on repos without commits #14

Closed
jtojnar wants to merge 1 commit from jtojnar/fresh-repos into master

View file

@ -77,12 +77,14 @@ let
# Try to clean the source tree by using fetchGit, if this source
# tree is a valid git repository.
tryFetchGit = src:
if isGit && !isShallow
if isGit && !isShallow && hasBranch
then builtins.fetchGit src
else { outPath = src; };
# NB git worktrees have a file for .git, so we don't check the type of .git
isGit = builtins.pathExists (src + "/.git");
isShallow = builtins.pathExists (src + "/.git/shallow");
# Repos without commits do not have any heads.
hasBranch = builtins.pathExists (src + "/.git/refs/heads") && builtins.readDir (src + "/.git/refs/heads") != { };
in
(if src ? outPath then src else tryFetchGit src)