From c169ea59049f861aaba429f48b828d0820b74d1d Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 15 Nov 2019 13:04:42 +0100 Subject: builtins.fetchGit: Fix build when fetching a git worktree Worktrees[1] are a feature of git which allow you to check out a ref in a different directory. While playing around with flakes I realized that git repositories in a worktree checkout break when trying to build a flake: ``` $ git worktree add ../nixpkgs-flakes nixpkgs-flakes $ cd ../nixpkgs-flakes $ nix build .#hello error: opening directory '/home/ma27/Projects/nixpkgs-flakes/.git/refs/heads': Not a directory ``` This issue has been fixed by determining with `git rev-parse --git-common-dir` where the actual `.git` directory is. Please note that this issue only exists on the `flakes` branch, fetching worktree checkouts with Nix master seems to work fine. [1] https://git-scm.com/docs/git-worktree --- src/libstore/fetchers/git.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libstore/fetchers/git.cc b/src/libstore/fetchers/git.cc index 134d44ecd..9276b0993 100644 --- a/src/libstore/fetchers/git.cc +++ b/src/libstore/fetchers/git.cc @@ -217,7 +217,16 @@ struct GitInput : Input /* Check whether this repo has any commits. There are probably better ways to do this. */ - bool haveCommits = !readDirectory(actualUrl + "/.git/refs/heads").empty(); + auto gitDir = actualUrl + "/.git"; + auto commonGitDir = chomp(runProgram( + "git", + true, + { "-C", actualUrl, "rev-parse", "--git-common-dir" } + )); + if (commonGitDir != ".git") + gitDir = commonGitDir; + + bool haveCommits = !readDirectory(gitDir + "/refs/heads").empty(); try { if (haveCommits) { -- cgit v1.2.3