Defect #1319

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

Added by Brian Ericson 102 days ago. Updated 100 days ago.

Status:Closed Start:2008-05-28
Priority:High Due date:
Assigned to:- % Done:

0%

Category:SCM
Target version:0.7.2
Affected version:

Resolution:

Fixed


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:
1           cmd="git --git-dir #{target('')} show #{shell_quote rev} -- #{shell_quote path}" if rev!='latest' and (! rev.nil?)
2           cmd="git --git-dir #{target('')} log -1 master -- #{shell_quote path}" if
3             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:
1           if rev!='latest' and (! rev.nil?)
2             cmd="git --git-dir #{target('')} show #{shell_quote rev} -- #{shell_quote path}" 
3           else
4             branch = shellout("git --git-dir #{target('')} branch") { |io| io.grep(/\*/)[0].strip.match(/\* (.*)/)[1] }
5             cmd="git --git-dir #{target('')} log -1 #{branch} -- #{shell_quote path}" 
6           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 jplang 100 days ago

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

History

2008-05-29 20:45 - Jean-Philippe Lang

  • 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