Project

General

Profile

Actions

Defect #44476

open

Fails to fetch revisions if a Git branch name contains a 40-character hexadecimal string

Added by Vitaly vit9696 about 18 hours ago. Updated about 1 hour ago.

Status:
Confirmed
Priority:
Normal
Assignee:
-
Category:
SCM
Resolution:
Affected version:

Description

If there is a Git-repository with branch name like this dependabot/github_actions/dtolnay/rust-toolchain-0b1efabc08b657293548b77fb76cc02d26091c7e, running rails runner "Repository.fetch_changesets" -e production command will fail with the following error:

git log error: git exited with non-zero status: 128

The issue is with the regular expression in lib/redmine/scm/adapters/git_adapter.rb, namely '\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$'. Due to incorrect space handling it mistakes branch name with a revision name. For example, this input is handled correctly:

dependabot/github_actions/coverallsapp/github-action-2.3.3                                2beebd80d386a98d0b31e9ce8fccf4c409c87c56 Dependabot update

But if branch name contains a hash-like value it will mistreat hash-like value with a revision id.

The correct way is to require spacing between branch name and revision name:

Index: lib/redmine/scm/adapters/git_adapter.rb
===================================================================
--- lib/redmine/scm/adapters/git_adapter.rb (revision 23546)
+++ lib/redmine/scm/adapters/git_adapter.rb (working copy)
@@ -84,7 +84,7 @@
           cmd_args = %w|branch --no-color --verbose --no-abbrev|
           git_cmd(cmd_args) do |io|
             io.each_line do |line|
-              branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
+              branch_rev = line.match('\s*(\*?)\s*(.*?)\s+([0-9a-f]{40}).*$')
               next unless branch_rev

               bran = GitBranch.new(scm_iconv('UTF-8', @path_encoding, branch_rev[2]))
@@ -337,7 +337,7 @@
           end
           revs
         rescue ScmCommandAborted => e
-          err_msg = "git log error: #{e.message}" 
+          err_msg = "git log error: #{@url} #{e.message}}" 
           logger.error(err_msg)
           if block_given?
             raise CommandFailed, err_msg

Adding url helps to identify the problematic repo, so I would also merge this.


Files

Actions

Also available in: Atom PDF