Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-50401

Checkout resolution misbehaves with local branch and forward slashes

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • git-plugin
    • None
    • Jenkins 2.107.1, git-plugin 2.7.1

      If the git plugin uses a local branch which is named the same as the remote and contains a forward slash, it will cause the checkout command to not update to the latest commit. Since using branches with / is common and local branch might be necessary, this should be fixed or at least produce a warning.

      To test: Create the following pipeline:

      node {
        stage ('hello') {
          dir ('foo') {
            checkout([$class: 'GitSCM', branches: [[name: "foo/bar"]], extensions: [[$class: 'LocalBranch', localBranch: 'foo/bar']], userRemoteConfigs: [[credentialsId: '...', url: "..."]]])
          }
        }
      }

      And follow these steps:

      1. Push branch foo/bar
      2. Run pipeline
      3. Push branch foo/bar with new versions
      4. Re-run pipeline in same folder

      The output should have the following contents:

       > git.exe fetch --tags --progress ssh://xxxx +refs/heads/*:refs/remotes/origin/*
       > git.exe rev-parse "foo/bar^{commit}" # timeout=10
       > git.exe rev-parse "refs/remotes/origin/foo/bar^{commit}" # timeout=10
      Multiple candidate revisions
      Checking out Revision 7bbd0143e31f1280e032cf350cf9f466642d1d65 (foo/bar)
      

      The 7bbd014 is the older commit however, since the local branch takes precedence over the remote one.

      Workarounds:

      • Name the local branch differently from the remote branch
      • Specify the fully quialified branch name (remotes/origin/${branch}) in the checkout command

          [JENKINS-50401] Checkout resolution misbehaves with local branch and forward slashes

          James Housley added a comment -

          I was having this issue when using "origin" as the "Name" of my git repository in the job's settings, and then using e.g. "abc/def" as my branch specifier. Removing the Name and instead using "origin/abc/def" as my branch specifier fixed the issue.

          James Housley added a comment - I was having this issue when using "origin" as the "Name" of my git repository in the job's settings, and then using e.g. "abc/def" as my branch specifier. Removing the Name and instead using "origin/abc/def" as my branch specifier fixed the issue.

          Ramon Leon added a comment -

          markwaite I'm a bit confused about this. Is it fixed actually? Which version? I saw this PR but it was closed without merging https://github.com/jenkinsci/branch-api-plugin/pull/47

          Thank you.

          Ramon Leon added a comment - markwaite I'm a bit confused about this. Is it fixed actually? Which version? I saw this PR but it was closed without merging  https://github.com/jenkinsci/branch-api-plugin/pull/47 Thank you.

          Mark Waite added a comment - - edited

          mramonleon I don't remember why I marked this as fixed but not released without linking a pull request or providing some other comment to justify that change.  Neither this bug nor either of the linked bugs are mentioned in the git plugin 4.0.0 changelog or in the git client plugin 3.0.0 changelog.  I've corrected my mistake and placed it back into 'OPEN' state.

          Mark Waite added a comment - - edited mramonleon I don't remember why I marked this as fixed but not released without linking a pull request or providing some other comment to justify that change.  Neither this bug nor either of the linked bugs are mentioned in the git plugin 4.0.0 changelog or in the git client plugin 3.0.0 changelog .  I've corrected my mistake and placed it back into 'OPEN' state.

            Unassigned Unassigned
            shauser Stephan Hauser
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: