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

Move internal state dir to 'common' subdir in git path. (Fixes bug with multiple worktrees) #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

morganwahl
Copy link

@morganwahl morganwahl commented Jun 4, 2021

This allows unlocked repos to work correctly with multiple worktrees.

When doing git worktree add newtree2 in an "unlocked" repo, I get the following output and creating the new worktree fails.

Preparing worktree (new branch 'newtree2')
git-crypt: Error: Unable to open key file - have you unlocked/initialized this repository yet?
error: external filter '"/usr/bin/git-crypt" smudge' failed 1
error: external filter '"/usr/bin/git-crypt" smudge' failed
fatal: env/docker-all.secret-env: smudge filter git-crypt failed

By putting strace in front of the smudge command in .git/config, I see:

openat(AT_FDCWD, "/home/morgan/Development/dev1/.git/worktrees/newtree2/git-crypt/keys/default", O_RDONLY) = -1 ENOENT (No such file or directory)

Git is calling the smudge command when checking out the new working tree, which then fails to find the key file because git rev-parse uses a separate dir for each worktree. Hence the worktrees/newtree2 in the path. The command fails because there is no git-crypt dir in .git/worktrees/newtree2.

git rev-parse --git-path should be used instead of git rev-parse --git-dir, based on https://git-scm.com/docs/git-worktree#_details :

See gitrepository-layout[5] for more information. The rule of thumb is do not make any assumption about whether a path belongs to $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something inside $GIT_DIR. Use git rev-parse --git-path to get the final path.

More importantly, git-crypt should be using the common subdir of the git dir to store in-use keys, since those need to be shared across workdirs. https://git-scm.com/docs/gitrepository-layout#Documentation/gitrepository-layout.txt-common

@baguilarq
Copy link

Hope we have response from the maintainers

@alerque
Copy link
Contributor

alerque commented Jan 11, 2023

@AGWA Any chance this can get reviewed and included? I'm starting to use more worktree based things myself and this needs to be fixed.

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.

4 participants