Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f3505a789914
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1d99c4ab25cf
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Feb 19, 2020

  1. 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
    Ma27 committed Feb 19, 2020
    Copy the full SHA
    c169ea5 View commit details
  2. Merge pull request #3229 from Ma27/flakes-fetchgit-worktree-support

    builtins.fetchGit: Fix build when fetching a git worktree
    edolstra authored Feb 19, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1d99c4a View commit details
Showing with 18 additions and 1 deletion.
  1. +10 −1 src/libstore/fetchers/git.cc
  2. +8 −0 tests/fetchGit.sh
11 changes: 10 additions & 1 deletion src/libstore/fetchers/git.cc
Original file line number Diff line number Diff line change
@@ -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) {
8 changes: 8 additions & 0 deletions tests/fetchGit.sh
Original file line number Diff line number Diff line change
@@ -25,8 +25,16 @@ rev1=$(git -C $repo rev-parse HEAD)

echo world > $repo/hello
git -C $repo commit -m 'Bla2' -a
git -C $repo worktree add $TEST_ROOT/worktree
echo hello >> $TEST_ROOT/worktree/hello
rev2=$(git -C $repo rev-parse HEAD)

# Fetch a worktree
unset _NIX_FORCE_HTTP
path0=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$TEST_ROOT/worktree).outPath")
export _NIX_FORCE_HTTP=1
[[ $(tail -n 1 $path0/hello) = "hello" ]]

# Fetch the default branch.
path=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$repo).outPath")
[[ $(cat $path/hello) = world ]]