Defect #1319

git's "get_rev" API should use repo's current branch instead of hardwiring "master"

Added by Brian Ericson over 9 years ago. Updated over 9 years ago.

Status:ClosedStart date:2008-05-28
Priority:HighDue date:
Assignee:-% Done:

0%

Category:SCM
Target version:0.7.2
Resolution:Fixed Affected version:

Description

lib/redmine/scm/adapters/git_adapter.rb gets the revision (git_rev -- line 31 in particular (lines 30-32 shown) using the following cmd:

          cmd="git --git-dir #{target('')} show #{shell_quote rev} -- #{shell_quote path}" if rev!='latest' and (! rev.nil?)
          cmd="git --git-dir #{target('')} log -1 master -- #{shell_quote path}" if
            rev=='latest' or rev.nil?

If the repo does not use master, this won't work properly -- the "Browse" table will be stuck at "master" (assuming the branch exists) but the "Latest Revisions" table will show commits to the current branch. In effect, you will not be able to browse the tree to see the files changed in the commits you can see.
I propose the following instead:
          if rev!='latest' and (! rev.nil?)
            cmd="git --git-dir #{target('')} show #{shell_quote rev} -- #{shell_quote path}" 
          else
            branch = shellout("git --git-dir #{target('')} branch") { |io| io.grep(/\*/)[0].strip.match(/\* (.*)/)[1] }
            cmd="git --git-dir #{target('')} log -1 #{branch} -- #{shell_quote path}" 
          end

This adds an additional shellout to get the current branch of the current repository and passes that to the cmd string (replacing the hard-wired "master").

Associated revisions

Revision 1475
Added by Jean-Philippe Lang over 9 years ago

Fixed: GitAdapter#get_rev should use current branch instead of hardwiring master (#1319).

History

#1 Updated by Jean-Philippe Lang over 9 years ago

  • Category set to SCM
  • Status changed from New to Closed
  • Target version set to 0.7.2
  • Resolution set to Fixed

Patch applied in r1475. Thanks.

Also available in: Atom PDF