divergence icon indicating copy to clipboard operation
divergence copied to clipboard

git_manager.rb:64: warning: conflicting chdir during another chdir block

Open paulie4 opened this issue 12 years ago • 3 comments

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

paulie4 avatar Nov 02 '12 23:11 paulie4

I just noticed that the git() function also wraps the git calls in Dir.chdir and should also be changed.

paulie4 avatar Nov 03 '12 00:11 paulie4

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

paulie4 avatar Nov 03 '12 03:11 paulie4

Would love to see this in a pull request :smile:

meltingice avatar Nov 03 '12 16:11 meltingice