Defect #31120

Garbage lines in the output of 'git branch' break git adapter

Added by Chad Petersen about 1 month ago. Updated about 1 month ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

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

Description

I found that adding an if condition around line 84-89 solves the issue.

change:

branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
bran = GitBranch.new(branch_rev[2])
bran.revision =  branch_rev[3]
bran.scmid    =  branch_rev[3]
bran.is_default = ( branch_rev[1] == '*' )
@branches << bran

To:

if branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
  bran = GitBranch.new(branch_rev[2])
  bran.revision =  branch_rev[3]
  bran.scmid    =  branch_rev[3]
  bran.is_default = ( branch_rev[1] == '*' )
  @branches << bran
end

31120.patch Magnifier - Fix by Chad Petersen (1.09 KB) Go MAEDA, 2019-03-31 06:39

Associated revisions

Revision 18046
Added by Go MAEDA about 1 month ago

Garbage lines in the output of 'git branch' break git adapter (#31120).

Contributed by Chad Petersen.

Revision 18047
Added by Go MAEDA about 1 month ago

Merged r18046 from trunk to 4.0-stable (#31120).

Revision 18048
Added by Go MAEDA about 1 month ago

Merged r18046 from trunk to 3.4-stable (#31120).

History

#1 Updated by Chad Petersen about 1 month ago

The file is {redmineroot}\lib\redmine\scm\adapters\git_adapter.rb

#2 Updated by Go MAEDA about 1 month ago

  • Description updated (diff)

#3 Updated by Go MAEDA about 1 month ago

I have generated a patch file from Chad Petersen's post.

#4 Updated by Go MAEDA about 1 month ago

  • Status changed from New to Needs feedback

The fixed code looks correct but I was not able to reproduce the situation that 'git branch --no-color --verbose --no-abbrev' outputs a single branch using two or more lines even if the commit log consists of multiple lines.

Could you tell me the operations to make a repository that causes the problem?

#5 Updated by Chad Petersen about 1 month ago

It's a bit of an odd setup. This particular team is using TFS as its source control. So in order to pull it across to git, I'm using the git-TFS integration found here: https://github.com/git-tfs/git-tfs. This appends git commit messages with a new line including the TFS commit so you can trace them back.

#6 Updated by Go MAEDA about 1 month ago

  • Tracker changed from Patch to Defect
  • Subject changed from Git commit with multi-line comment on a project with more than one branch breaking parser. to Git commit with multi-line comment on a project with more than one branch breaking parser
  • Status changed from Needs feedback to New
  • Target version set to 3.4.11

Chad Petersen wrote:

It's a bit of an odd setup. This particular team is using TFS as its source control. So in order to pull it across to git, I'm using the git-TFS integration found here: https://github.com/git-tfs/git-tfs. This appends git commit messages with a new line including the TFS commit so you can trace them back.

I understand. Thank you for clarifying.
I cannot reproduce the problem because I don't use TFS, but the code after line 86 ('bran = GitBranch...') must not be executed if branch_rev is nil. I am setting the target version to 3.4.11.

diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb
index e0c5d4763..0733cbc40 100644
--- a/lib/redmine/scm/adapters/git_adapter.rb
+++ b/lib/redmine/scm/adapters/git_adapter.rb
@@ -84,6 +84,7 @@ module Redmine
           git_cmd(cmd_args) do |io|
             io.each_line do |line|
               branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
+              next unless branch_rev
               bran = GitBranch.new(branch_rev[2])
               bran.revision =  branch_rev[3]
               bran.scmid    =  branch_rev[3]

#7 Updated by Go MAEDA about 1 month ago

  • Subject changed from Git commit with multi-line comment on a project with more than one branch breaking parser to Multi-line commit message breaks git adapter when parsing branches

#8 Updated by Go MAEDA about 1 month ago

  • Subject changed from Multi-line commit message breaks git adapter when parsing branches to Garbage lines in the output of 'git branch' break git adapter
  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Fixed in r18046. Thank you for your contribution.

#9 Updated by Go MAEDA about 1 month ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF