jenkinsci / jenkinsci/git-plugin

[JENKINS-46219] Should fetch origin/refs even if repository exists in work tree

Open
#3,177 4 comments 0 reactions 0 assignees View on GitHub
component:git-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
694
Forks
1.1k
Avg merge
1h 29m
Merged PRs (30d)
3

Description

Use case: Using git-plugin to run jobs on incoming pull requests, when the git repo exists in working tree, git-plugin fails to merge the branches because of a missing reference to the base branch.

Behavior: git-plugin throws GitException

Expected behavior: merge successfully the pr branch and the base branch

Suggested solution: fetch origin references and not only the tags

Stack trace:

> git rev-parse --is-inside-work-tree # timeout=10

Fetching changes from the remote Git repository

> git config remote.origin.url https://github.com/ros/bond_core.git # timeout=10

Fetching upstream changes from https://github.com/ros/bond_core.git

> git --version # timeout=10

> git fetch --tags --progress https://github.com/ros/bond_core.git +refs/pull/:refs/remotes/origin/pr/

> git rev-parse refs/remotes/origin/pr/31/merge^


{commit} # timeout=10

> git rev-parse refs/remotes/origin/origin/pr/31/merge^{commit}

# timeout=10

Merging Revision b0644a4eb62fde36776aae1a6ecd63a5a077838f (refs/remotes/origin/pr/31/merge) to origin/groovy-devel, UserMergeOptions


{mergeRemote='origin', mergeTarget='groovy-devel', mergeStrategy='default', fastForwardMode='--ff'}

> git rev-parse origin/groovy-devel^


{commit} # timeout=10

FATAL: Command "git rev-parse origin/groovy-devel^{commit}

" returned status code 128:

stdout: origin/groovy-devel^


{commit}

Workaround: wipe the workspace of the job

Link to failing Jenkins job:

http://build.ros.org/job/Ipr__bond_core__ubuntu_trusty_amd64/25/console

This is my first issue on Jenkins please let me know if there is any missing information or if this is not the right way to describe an issue.

Thanks!

Edit: markewaite Sorry for the delay. For various reasons our buildfarm has an "old" version of Jenkins and some plugins. We're spinning up a new farm with the latest version of Jenkins and all plugins, I'll use that config to test and provide a reproducible example

---
Originally reported by mikaelarguedas, imported from: Should fetch origin/refs even if repository exists in work tree


  • status: Open
  • priority: Minor
  • component(s): git-plugin
  • resolution: Unresolved
  • votes: 2
  • watchers: 4
  • imported: 2025-12-02

Raw content of original issue

Use case: Using git-plugin to run jobs on incoming pull requests, when the git repo exists in working tree, git-plugin fails to merge the branches because of a missing reference to the base branch.

Behavior: git-plugin throws GitException
Expected behavior: merge successfully the pr branch and the base branch

Suggested solution: fetch origin references and not only the tags

Stack trace:
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/ros/bond_core.git # timeout=10
Fetching upstream changes from https://github.com/ros/bond_core.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/ros/bond_core.git +refs/pull/:refs/remotes/origin/pr/
> git rev-parse refs/remotes/origin/pr/31/merge^


{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/pr/31/merge^{commit}

# timeout=10
Merging Revision b0644a4eb62fde36776aae1a6ecd63a5a077838f (refs/remotes/origin/pr/31/merge) to origin/groovy-devel, UserMergeOptions


{mergeRemote='origin', mergeTarget='groovy-devel', mergeStrategy='default', fastForwardMode='--ff'}

> git rev-parse origin/groovy-devel^


{commit} # timeout=10
FATAL: Command "git rev-parse origin/groovy-devel^{commit}

" returned status code 128:
stdout: origin/groovy-devel^


{commit}

Workaround: wipe the workspace of the job

Link to failing Jenkins job:
http://build.ros.org/job/Ipr__bond_core__ubuntu_trusty_amd64/25/console

This is my first issue on Jenkins please let me know if there is any missing information or if this is not the right way to describe an issue.
Thanks!

Edit: markewaite Sorry for the delay. For various reasons our buildfarm has an "old" version of Jenkins and some plugins. We're spinning up a new farm with the latest version of Jenkins and all plugins, I'll use that config to test and provide a reproducible example

3 attachments

- [comparison_of_success_and_failure.png](https://issues.jenkins.io/secure/attachment/41995/comparison_of_success_and_failure.png)
> ![comparison_of_success_and_failure.png](https://issues.jenkins.io/secure/attachment/41995/comparison_of_success_and_failure.png)
- [fails_when_git_folder_exists.txt](https://issues.jenkins.io/secure/attachment/41993/fails_when_git_folder_exists.txt)
- [success_when_no_git_folder_exists.txt](https://issues.jenkins.io/secure/attachment/41994/success_when_no_git_folder_exists.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.