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

Applying patch: git apply, worktrees and invalid gitdir #69

Closed
e1senh0rn opened this issue Mar 4, 2016 · 2 comments
Closed

Applying patch: git apply, worktrees and invalid gitdir #69

e1senh0rn opened this issue Mar 4, 2016 · 2 comments

Comments

@e1senh0rn
Copy link

I'm using recently released worktrees git feature, and having issues with applying patches.
Also I use Vagrant, and it renders gitdir path within worktree invalid.

Here is an example.

mkdir /tmp/git_apply_issue
cd /tmp/git_apply_issue
# Simulate worktree with invalid path
echo 'gitdir: /nonexistent' > .git
echo "source 'https://rubygems.org'\n\ngem 'nokogiri'" > Gemfile
bundle install --path ./.bundle

# Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-apple-darwin15.2.0/ports/libxml2/2.9.2... OK
# Running git apply with /tmp/git_apply_issue/.bundle/ruby/2.3.0/gems/nokogiri-1.6.7.2/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch... ERROR, review '/tmp/git_apply_issue/.bundle/ruby/2.3.0/gems/nokogiri-1.6.7.2/ext/nokogiri/tmp/x86_64-apple-darwin15.2.0/ports/libxml2/2.9.2/patch.log' to see what happened. Last lines are:
# ========================================================================
# fatal: Not a git repository: /nonexistent
# ========================================================================
...

I believe it is caused by behavior of git apply itself. Apparently --work-tree=. does not prevent git from traversing up and looking for git repo files.

git apply command is being executed within /tmp/git_apply_issue/.bundle/ruby/2.3.0/gems/nokogiri-1.6.7.2/ext/nokogiri.

Is there a way to avoid this error?

@flavorjones
Copy link
Owner

@e1senh0rn Thanks for asking this question.

I don't totally understand what you're demonstrating above ... that git apply blows up if you have gitdir set to a nonexistent directory? This seems a little contrived. Can you help me understand a real use case?

@e1senh0rn
Copy link
Author

You are correct, git apply just blows up. Actually, patch works just fine.

Here is what I'm doing.
I have rails project (cloned from git repo) in /Users/eisenhorn/work/project.
I create another branch to play with vagrant. Switching branches during daily work leads me to bunch of issues like removed .vagrant folder, overwritten project configs, etc.
To avoid it I create worktree with vagrant branch in /Users/eisenhorn/work/project-vagrant (via git worktree add ../project-vagrant vagrant).
Everything looks very smooth, I just change dir and keep working (start vm, provision, run app, etc).

In Vagrantfile I'm mapping /Users/eisenhorn/work/project-vagrant into VM as /home/vagrant/app. That is why .git file has completely broken gitdir specification within VM.

Finally, in VM I execute bundle install --path /home/vagrant/app/.bundle, and nokogiri installation fails because of bundled libxml/libxslt and mini_portile applying patches via git apply. Git traverses up, encounters invalid gitdir, and fails.

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

No branches or pull requests

2 participants