jenkinsci / jenkinsci/git-plugin

[JENKINS-59736] No new commits used if LocalBranch checked in same workspace

Open
#3,483 0 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

Reproduce steps:



  • Create branch

  • Execute pipeline with LocalBranch

  • Add commits to branch

  • Repeat pipeline in same workspace - no new commits will be used from original

Criteria to reproduce:



  • Usage of LocalBranch extension

  • Usage of original branch name containig '/' symbol

Problem in class:

hudson.plugins.git.util.DefaultBuildChooser#getCandidateRevisions


Example Pipeline:

node('master') {

stage('Checkout'){
script {
String url = 'https://example.com/repository.git'
//: Branch name containing `/` symbol
String branch = 'feature/branch'
String credentialsId = 'secret-credentials'

//: Checkout original
checkout scm: [
$class: 'GitSCM',
userRemoteConfigs: [
[
url: url,
credentialsId: credentialsId
]
],
extensions: [[$class: 'LocalBranch']],
branches: [
[name: branch]
]
]

//: Change local history
sh('git reset --hard HEAD^')

//: Checkout one more time - local history will be used
checkout scm: [
$class: 'GitSCM',
userRemoteConfigs: [
[
url: url,
credentialsId: credentialsId
]
],
extensions: [[$class: 'LocalBranch']],
branches: [
[name: branch]
]
]

}
}
}


Workaround:

Execute before checkout

sh('rm -rf .git/refs/heads/*')


To remove local branches refs

---
Originally reported by xxxbobrxxx, imported from: No new commits used if LocalBranch checked in same workspace


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

Raw content of original issue

Reproduce steps:



  • Create branch

  • Execute pipeline with LocalBranch

  • Add commits to branch

  • Repeat pipeline in same workspace - no new commits will be used from original

Criteria to reproduce:



  • Usage of LocalBranch extension

  • Usage of original branch name containig '/' symbol

Problem in class:



hudson.plugins.git.util.DefaultBuildChooser#getCandidateRevisions



Example Pipeline:



node('master') {

stage('Checkout'){
script {
String url = 'https://example.com/repository.git'
//: Branch name containing `/` symbol
String branch = 'feature/branch'
String credentialsId = 'secret-credentials'

//: Checkout original
checkout scm: [
$class: 'GitSCM',
userRemoteConfigs: [
[
url: url,
credentialsId: credentialsId
]
],
extensions: [[$class: 'LocalBranch']],
branches: [
[name: branch]
]
]

//: Change local history
sh('git reset --hard HEAD^')

//: Checkout one more time - local history will be used
checkout scm: [
$class: 'GitSCM',
userRemoteConfigs: [
[
url: url,
credentialsId: credentialsId
]
],
extensions: [[$class: 'LocalBranch']],
branches: [
[name: branch]
]
]

}
}
}



Workaround:

Execute before checkout



sh('rm -rf .git/refs/heads/*')



To remove local branches refs

  • environment: Any version from

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.