jenkinsci / jenkinsci/git-plugin
[JENKINS-59736] No new commits used if LocalBranch checked in same workspace
- 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
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
Assessment
This issue has not been assessed yet.