Project

General

Profile

Actions

Defect #1319

closed

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

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

Status:
Closed
Priority:
High
Assignee:
-
Category:
SCM
Target version:
Start date:
2008-05-28
Due date:
% Done:

0%

Estimated time:
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").

Actions

Also available in: Atom PDF