Project

General

Profile

Actions

Defect #31120

closed

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

Added by Chad Petersen almost 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
SCM
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
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


Files

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

Updated by Chad Petersen almost 5 years ago

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

Actions #2

Updated by Go MAEDA almost 5 years ago

  • Description updated (diff)
Actions #3

Updated by Go MAEDA almost 5 years ago

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

Actions #4

Updated by Go MAEDA almost 5 years 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?

Actions #5

Updated by Chad Petersen almost 5 years 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.

Actions #6

Updated by Go MAEDA almost 5 years 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]
Actions #7

Updated by Go MAEDA almost 5 years 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
Actions #8

Updated by Go MAEDA almost 5 years 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.

Actions #9

Updated by Go MAEDA almost 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF