Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for git worktree creation from a thunk using local git repo #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dfordivam
Copy link

@dfordivam dfordivam commented May 17, 2023

I use git worktrees a lot and have always wanted the nix-thunk to support it.
So last few days I spent some time and implemented it.

The following are some notes for the worktree support.

Usage

nix-thunk worktree [-b|--branch BRANCH] [-d|--detach] THUNKDIR GITDIR

Like this

nix-thunk worktree .obelisk/impl ~/repos/obelisk -b somebranch

Benefits of using worktree; as opposed to doing unpack and create a new git repo.

  • For big repos, like nixpkgs, worktree is far better than doing a new git checkout.
  • worktree creation happens almost instantaneously, even for small sized repos.
  • It can work offline
  • The stashes and temporary branches can be kept locally and shared among different worktrees.
  • Unless you are doing some small fix, the thunk might remain unpacked for a while.
    and having the unpacked thunk(s) linked to the main git repository (as a worktree) has many advantages
    • It helps keep track of the work that was being done for a particular repo.
    • And by keeping the worktree in the thunk's original directory, as opposed to some other directory.
      It helps avoids the situation where you could forget, after a few months, where a worktree was being used from.
  • worktree(s) use less disk-space.

Problems with using worktree

  • Repos containing sub-modules don't work properly with git worktree.

  • If the local repo already contains a branch of the same name as the thunk, then the new worktree cannot be created with that branch name.

  • The local branch may be pointing to a different revision, and I think it's better to not modify the existing branches in the git repo.
    In this situation, user has two options.

    • The first is to specify a new branch name in the "nix-thunk worktree" command line itself.
    • The other one is to create the worktree with detached head.

(Fixing the branch naming before pushing to remote, or updating the existing branch to track the remote will have to be done manually by the user.)

Packing worktrees

When doing packing of worktree thunks there are fewer number of concerns than the usual. Namely these two

  • That there are no untracked files or uncommitted changes in the worktree
  • That the branch has been pushed remote, so that the thunk is valid

Performance

Here are the unpack vs worktree creation time I noted on my machine

repo unpack worktree
nixpkgs 477.73 s 5.27 s
obelisk 3.13 s 721.56 ms
alamgu 932.34 ms 558.87 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants