divergence
divergence copied to clipboard
git_manager.rb:64: warning: conflicting chdir during another chdir block
I was getting many of those chdir warnings. To stop them, I removed the surrounding Dir.chdir @git_path do
so this:
Dir.chdir @git_path do
# This is fast, but only works on locally checked out branches
`git show-ref --verify --quiet 'refs/heads/#{branch}'`
return true if $?.exitstatus == 0
# This is slow and will only get called for remote branches.
result = `git ls-remote --heads origin 'refs/heads/#{branch}'`
return result.strip.length != 0
end
becomes this:
# This is fast, but only works on locally checked out branches
`git --git-dir #{@git_path}/.git show-ref --verify --quiet 'refs/heads/#{branch}'`
return true if $?.exitstatus == 0
# This is slow and will only get called for remote branches.
result = `git --git-dir #{@git_path}/.git ls-remote --heads origin 'refs/heads/#{branch}'`
return result.strip.length != 0
I just noticed that the git() function also wraps the git calls in Dir.chdir and should also be changed.
Whoops. Evidently, the git calls will also need --work-tree
, e.g.:
git --work-tree #{@git_path} --git-dir #{@git_path}/.git #{cmd.to_s} 2>&1
Would love to see this in a pull request :smile: