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 17 hours ago. Updated 32 minutes 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 #1

Updated by Go MAEDA about 3 hours ago

  • Tracker changed from Patch to Defect
  • Status changed from New to Confirmed
Actions #2

Updated by Go MAEDA about 3 hours ago

Thank you for reporting this issue and providing the patch. I was able to reproduce the problem.

I have attached two patches.

The first patch contains your fix to the regular expression, together with a test that fails without the fix and passes with it. I did not include the change that adds @url to the error message in GitAdapter#revisions. The other SCM adapters do not include the repository URL in their error messages, and the message can also be displayed in the web interface through CommandFailed. I think such a change would be better discussed separately, for all adapters at once.

The second patch improves the readability of GitAdapter#branches without changing its behavior. It is independent of the first patch, so the first patch can be committed and backported without it.

Actions #3

Updated by Vitaly vit9696 about 2 hours ago

Thank you for providing proper patches. Looks good to me. Any chance this lands into 7.0.2?

Actions #4

Updated by Go MAEDA 32 minutes ago

Vitaly vit9696 wrote in #note-3:

Any chance this lands into 7.0.2?

In my opinion, this fix should be backported to Redmine 7.0.2 and 6.1.5.

Actions

Also available in: Atom PDF