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

Better handling of Mercurial branches

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: mercurial-plugin
    • Labels:
      None
    • Environment:
      Platform: All, OS: All
    • Similar Issues:

      Description

      I have some suggestions to improve the current sequence of hg commands issued by
      the Mercurial plugin.

      Currently we have:

      hg incoming --quiet --bundle hg.bundle --template [blah...] -r $branch
      hg pull -u hg.bundle ## ( this command doesn't specify which branch the working
      copy should be brought to )

      I think this would be better:

      hg incoming --quiet --bundle hg.bundle --template [blah...] -r $branch
      hg pull hg.bundle ## ( instead of 'hg pull -u hg.bundle' )
      hg update -C -r $revision ### ( this command should bring the working copy to
      the tip of the specified branch )

      On the Java side, instead of

      if (branch!=null) args.add("-r",branch);
      else args.add("-r", "default");

      I suggest this:

      if (null == branch || branch.trim().length() == 0)

      { // Excplicitly select the default branch branch = "default"; }

      // It's safer to ALWAYS specify which branch to use
      args.add("-r", branch);

        Attachments

          Issue Links

            Activity

            elifarley Elifarley created issue -
            Hide
            elifarley Elifarley added a comment -

            Oops... Instead of

            hg update -C -r $revision ### ( this command should bring the working copy to
            the tip of the specified branch )

            I meant this:

            hg update -C -r $branch ### ( this command should bring the working copy to
            the tip of the specified branch )

            Show
            elifarley Elifarley added a comment - Oops... Instead of hg update -C -r $revision ### ( this command should bring the working copy to the tip of the specified branch ) I meant this: hg update -C -r $branch ### ( this command should bring the working copy to the tip of the specified branch )
            Hide
            elifarley Elifarley added a comment -

            Assigned to 'jglick'.

            Show
            elifarley Elifarley added a comment - Assigned to 'jglick'.
            Hide
            jglick Jesse Glick added a comment -

            .

            Show
            jglick Jesse Glick added a comment - .
            Hide
            elifarley Elifarley added a comment -

            Below is a patch that should solve the problem:

            Index: src/main/java/hudson/plugins/mercurial/MercurialSCM.java
            ===================================================================
            — src/main/java/hudson/plugins/mercurial/MercurialSCM.java (revision 21107)
            +++ src/main/java/hudson/plugins/mercurial/MercurialSCM.java (working copy)
            @@ -326,11 +326,21 @@
            // in 0.9.4 apparently it returns 0.
            try {
            if(launcher.launch()

            • .cmds(findHgExe(listener),"pull","-u","hg.bundle")
              + .cmds(findHgExe(listener),"pull", "hg.bundle")

            .envs(build.getEnvironment(listener)).stdout(listener).pwd(workspace).join()!=0)

            { listener.error("Failed to pull"); return false; }

            +
            + r = launcher.launch()
            + .cmds(findHgExe(listener),"update", "-C", "-r", branch == null
            ? "default" : branch)
            +
            .envs(build.getEnvironment(listener)).stdout(listener).pwd(workspace).join();
            +
            + if ( r != 0 )

            { + listener.error("Failed to update. Exit value: " + r); + return false; + }

            +
            } catch (IOException e) {
            listener.error("Failed to pull");
            return false;

            Show
            elifarley Elifarley added a comment - Below is a patch that should solve the problem: Index: src/main/java/hudson/plugins/mercurial/MercurialSCM.java =================================================================== — src/main/java/hudson/plugins/mercurial/MercurialSCM.java (revision 21107) +++ src/main/java/hudson/plugins/mercurial/MercurialSCM.java (working copy) @@ -326,11 +326,21 @@ // in 0.9.4 apparently it returns 0. try { if(launcher.launch() .cmds(findHgExe(listener),"pull","-u","hg.bundle") + .cmds(findHgExe(listener),"pull", "hg.bundle") .envs(build.getEnvironment(listener)).stdout(listener).pwd(workspace).join()!=0) { listener.error("Failed to pull"); return false; } + + r = launcher.launch() + .cmds(findHgExe(listener),"update", "-C", "-r", branch == null ? "default" : branch) + .envs(build.getEnvironment(listener)).stdout(listener).pwd(workspace).join(); + + if ( r != 0 ) { + listener.error("Failed to update. Exit value: " + r); + return false; + } + } catch (IOException e) { listener.error("Failed to pull"); return false;
            Hide
            elifarley Elifarley added a comment -

            Here's a slightly modified patch, against v. 1.16:

            Index: src/main/java/hudson/plugins/mercurial/MercurialSCM.java
            ===================================================================
            — src/main/java/hudson/plugins/mercurial/MercurialSCM.java (revision 18537)
            +++ src/main/java/hudson/plugins/mercurial/MercurialSCM.java (working copy)
            @@ -305,12 +305,25 @@
            // if incoming didn't fetch anything, it will return 1. That was
            for 0.9.3.
            // in 0.9.4 apparently it returns 0.
            try {
            +
            + final String branchToPull = branch == null ? "default" : branch;
            +
            if(launcher.launch(

            • new
              String[] {getDescriptor().getHgExe(),"pull","-u","hg.bundle"}

              ,
              + new String[]

              {getDescriptor().getHgExe(),"pull", "-r", branchToPull, "hg.bundle"}

              ,
              build.getEnvVars(),listener.getLogger(),workspace).join()!=0)

              { listener.error("Failed to pull"); return false; }

              +
              + r = launcher.launch( new String[]

              { + getDescriptor().getHgExe(), "update", "-C", "-r", branchToPull + }

              , build.getEnvVars(), listener.getLogger(), workspace ).join();
              +
              + if ( r != 0 )

              { + listener.error( "Failed to update. Exit value: " + r ); + return false; + }

              +
              } catch (IOException e) {
              listener.error("Failed to pull");
              return false;

            Show
            elifarley Elifarley added a comment - Here's a slightly modified patch, against v. 1.16: Index: src/main/java/hudson/plugins/mercurial/MercurialSCM.java =================================================================== — src/main/java/hudson/plugins/mercurial/MercurialSCM.java (revision 18537) +++ src/main/java/hudson/plugins/mercurial/MercurialSCM.java (working copy) @@ -305,12 +305,25 @@ // if incoming didn't fetch anything, it will return 1. That was for 0.9.3. // in 0.9.4 apparently it returns 0. try { + + final String branchToPull = branch == null ? "default" : branch; + if(launcher.launch( new String[] {getDescriptor().getHgExe(),"pull","-u","hg.bundle"} , + new String[] {getDescriptor().getHgExe(),"pull", "-r", branchToPull, "hg.bundle"} , build.getEnvVars(),listener.getLogger(),workspace).join()!=0) { listener.error("Failed to pull"); return false; } + + r = launcher.launch( new String[] { + getDescriptor().getHgExe(), "update", "-C", "-r", branchToPull + } , build.getEnvVars(), listener.getLogger(), workspace ).join(); + + if ( r != 0 ) { + listener.error( "Failed to update. Exit value: " + r ); + return false; + } + } catch (IOException e) { listener.error("Failed to pull"); return false;
            Hide
            jglick Jesse Glick added a comment -
                • Issue 2057 has been marked as a duplicate of this issue. ***
            Show
            jglick Jesse Glick added a comment - Issue 2057 has been marked as a duplicate of this issue. ***
            jglick Jesse Glick made changes -
            Field Original Value New Value
            Link This issue is duplicated by JENKINS-2057 [ JENKINS-2057 ]
            Hide
            jglick Jesse Glick added a comment -
                • Issue 2502 has been marked as a duplicate of this issue. ***
            Show
            jglick Jesse Glick added a comment - Issue 2502 has been marked as a duplicate of this issue. ***
            jglick Jesse Glick made changes -
            Link This issue is duplicated by JENKINS-2502 [ JENKINS-2502 ]
            Hide
            jglick Jesse Glick added a comment -
                • Issue 3879 has been marked as a duplicate of this issue. ***
            Show
            jglick Jesse Glick added a comment - Issue 3879 has been marked as a duplicate of this issue. ***
            jglick Jesse Glick made changes -
            Link This issue is duplicated by JENKINS-3879 [ JENKINS-3879 ]
            Hide
            jglick Jesse Glick added a comment -

            Basic issue.

            Show
            jglick Jesse Glick added a comment - Basic issue.
            Hide
            jglick Jesse Glick added a comment -

            I will do it a little differently than the suggested patches, but same idea.

            Show
            jglick Jesse Glick added a comment - I will do it a little differently than the suggested patches, but same idea.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in hudson
            User: : jglick
            Path:
            trunk/hudson/plugins/mercurial/src/main/java/hudson/plugins/mercurial/MercurialSCM.java
            trunk/hudson/plugins/mercurial/src/test/java/hudson/plugins/mercurial/MercurialSCMTest.java
            http://fisheye4.cenqua.com/changelog/hudson/?cs=21790
            Log:
            [FIXED JENKINS-4281] Some problems with named branches.
            Sometimes pulled or polled changesets from branches irrelevant to the job.
            More seriously, was impossible to switch branches without deleting workspace.
            Now always passing -r, using 'default' or the specified branch name, and updating -C.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in hudson User: : jglick Path: trunk/hudson/plugins/mercurial/src/main/java/hudson/plugins/mercurial/MercurialSCM.java trunk/hudson/plugins/mercurial/src/test/java/hudson/plugins/mercurial/MercurialSCMTest.java http://fisheye4.cenqua.com/changelog/hudson/?cs=21790 Log: [FIXED JENKINS-4281] Some problems with named branches. Sometimes pulled or polled changesets from branches irrelevant to the job. More seriously, was impossible to switch branches without deleting workspace. Now always passing -r, using 'default' or the specified branch name, and updating -C.
            scm_issue_link SCM/JIRA link daemon made changes -
            Status Open [ 1 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            abayer Andrew Bayer made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 134354 ] JNJira + In-Review [ 202785 ]

              People

              • Assignee:
                jglick Jesse Glick
                Reporter:
                elifarley Elifarley
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: