Mic92 / nixpkgs-review

Review pull-requests on https://github.com/NixOS/nixpkgs
MIT License
409 stars 66 forks source link

Can't find the git repo when using `git worktree` #411

Closed MattSturgeon closed 3 months ago

MattSturgeon commented 3 months ago

I generally prefer to checkout several worktrees on repos where I'm likely to have more than one branch worked on simultaniously, so I'll typically clone a --bare repo, then git worktree add various directories within it.

nixpkgs-review doesn't seem to support this, failing to find the git repo:

# ~/nixpkgs is a bare repo
# ~/nixpkgs/master is a worktree with the `master` branch checked out
$ cd ~/nixpkgs/master

$ nix run 'nixpkgs#nixpkgs-review' -- pr 329264
$ git -c fetch.prune=false fetch --no-tags --force https://github.com/NixOS/nixpkgs master:refs/nixpkgs-review/0 pull/329264/head:refs/nixpkgs-review/1
fatal: not a git repository: /home/matt/nixpkgs.git/worktrees/master
https://github.com/NixOS/nixpkgs/pull/329264 failed to build: Failed to fetch ('master', 'pull/329264/head') from https://github.com/NixOS/nixpkgs. git fetch failed with exit code 128
$ git worktree remove -f /home/matt/.cache/nixpkgs-review/pr-329264/nixpkgs
fatal: not a git repository: /home/matt/nixpkgs.git/worktrees/master
Failed to remove worktree at /home/matt/.cache/nixpkgs-review/pr-329264/nixpkgs. Please remove it manually. Git failed with: 128

# I also attempted to run from the bare repo itself:
$ cd ..

$ nix run 'nixpkgs#nixpkgs-review' -- pr 329264
Has to be executed from nixpkgs repository
MattSturgeon commented 3 months ago

Nevermind, I should have read the error more closely!

fatal: not a git repository: /home/matt/nixpkgs.git/worktrees/master

The issue is that I'd renamed the repo from nixpkgs.git -> nixpkgs at some point after creating the master worktree. After pruning the worktree and re-adding it everything works correctly.