Maven SCM
  1. Maven SCM
  2. SCM-584

Checkout branch with Git uses unfamiliar command sequence which leads to errors during checkout

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 1.7
    • Component/s: maven-scm-provider-git
    • Labels:
      None
    • Complexity:
      Intermediate
    • Number of attachments :
      2

      Description

      I want to checkout a specific branch from my git repo using the maven-scm-plugin. The plugin first clones the repo and gets the default branch as selected in gitorious. After that the plugin executes git pull ... mybranch which works fine as long as there are no merge conflicts between current branch and branch to checkout. In the case of any conflict an error occurs.

      The git checkout -b command should be used instead.

      [INFO] Working directory: <a_dir>
      [INFO] Executing: /bin/sh -c cd /home/maven-proj/target/deploy-workspace && git fetch git://gitorious/<...>/my-proj.git
      [INFO] Working directory: <a_dir>
      [INFO] Executing: /bin/sh -c cd  /home/maven-proj/target/deploy-workspace && git checkout HEAD
      [INFO] Working directory: <a_dir>
      [INFO] Executing: /bin/sh -c cd /home/maven-proj/target/deploy-workspace && git ls-files
      [INFO] Working directory: <a_dir>
      [INFO] 
      [INFO] --- maven-scm-plugin:1.4:update (switch-branch) 
      [INFO] Executing: /bin/sh -c cd /home/maven-proj/target/deploy-workspace && git pull git://gitorious/<..>/deploy.git mysql55
      
      [WARNING] failed to update git, return code 1
      [ERROR] Provider message:
      [ERROR] The git-pull origin master command failed.
      [ERROR] Command output:
      [ERROR] From git://gitorious/<...>/deploy
       * branch            mysql55    -> FETCH_HEAD
      
      
      
      1. SCM-584.patch
        3 kB
        Sebastian Annies

        Activity

        Hide
        Daniel Strassenburg added a comment -

        Before the git fetch listed above a git clone is performed:

        Executing: /bin/sh -c cd <a_dir> && git clone git://gitorious/<...>/deploy.git/home/maven-proj/target/deploy-workspace
        
        Show
        Daniel Strassenburg added a comment - Before the git fetch listed above a git clone is performed: Executing: /bin/sh -c cd <a_dir> && git clone git://gitorious/<...>/deploy.git/home/maven-proj/target/deploy-workspace
        Hide
        Sebastian Annies added a comment -

        A little project showing the error. I would have written a regular test but I didn't understand the test framework. To see the error unzip and execute

        mvn install
        
        Show
        Sebastian Annies added a comment - A little project showing the error. I would have written a regular test but I didn't understand the test framework. To see the error unzip and execute mvn install
        Sebastian Annies made changes -
        Field Original Value New Value
        Attachment SCM-584-test-prj.zip [ 52461 ]
        Hide
        Sebastian Annies added a comment -

        Patches the problem by appending the --branch parameter to the git command in case the version is a branch. This makes sure that a subsequent pull does what intended!

        Show
        Sebastian Annies added a comment - Patches the problem by appending the --branch parameter to the git command in case the version is a branch. This makes sure that a subsequent pull does what intended!
        Sebastian Annies made changes -
        Attachment SCM-584.patch [ 52462 ]
        Hide
        Mark Struberg added a comment -

        patch looks good, thanks Sebastian!

        Show
        Mark Struberg added a comment - patch looks good, thanks Sebastian!
        Hide
        Ancoron Luciferis added a comment -

        Patch availability for about 1,5 years and still not integrated... wow!

        But furthermore it is really strange why this issue appeared in the first place. The initial developer(s) of the git provider must have been blind. How else can you explain that someone wanted to do a 'git pull' for switching to a branch?! As every documentation says 'git pull' is just a shortcut for 'git fetch' + 'git merge'.

        From the man page:

        [...] git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. [...]


        Even if it worked for the developer in the first place then only by luck.

        Show
        Ancoron Luciferis added a comment - Patch availability for about 1,5 years and still not integrated... wow! But furthermore it is really strange why this issue appeared in the first place. The initial developer(s) of the git provider must have been blind. How else can you explain that someone wanted to do a 'git pull' for switching to a branch?! As every documentation says 'git pull' is just a shortcut for 'git fetch' + 'git merge'. From the man page: [...] git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. [...] Even if it worked for the developer in the first place then only by luck.
        Hide
        Ancoron Luciferis added a comment -

        OK, I can confirm that the patch indeed fixes this problem but then the command sequence still is awful:

        [INFO] [scm:checkout {execution: export-inplace}]
        [INFO] Removing /srv/dev/test/target/upstream-sources
        [INFO] Executing: /bin/sh -c cd /srv/dev/test/target && git clone --branch develop http://git.myserver.localdomain/other.git /srv/dev/test/target/upstream-sources
        [INFO] Working directory: /srv/dev/test/target
        [INFO] Executing: /bin/sh -c cd /tmp && git ls-remote http://git.myserver.localdomain/other.git
        [INFO] Working directory: /tmp
        [INFO] Executing: /bin/sh -c cd /srv/dev/test/target/upstream-sources && git pull http://git.myserver.localdomain/other.git develop:develop
        [INFO] Working directory: /srv/dev/test/target/upstream-sources
        [INFO] Executing: /bin/sh -c cd /srv/dev/test/target/upstream-sources && git checkout develop
        [INFO] Working directory: /srv/dev/test/target/upstream-sources
        [INFO] Executing: /bin/sh -c cd /srv/dev/test/target/upstream-sources && git ls-files
        [INFO] Working directory: /srv/dev/test/target/upstream-sources
        


        What I would expect is this:

        [INFO] [scm:checkout {execution: export-inplace}]
        [INFO] Removing /srv/dev/test/target/upstream-sources
        [INFO] Executing: /bin/sh -c cd /srv/dev/test/target && git clone --branch develop http://git.myserver.localdomain/other.git /srv/dev/test/target/upstream-sources
        [INFO] Working directory: /srv/dev/test/target
        [INFO] Executing: /bin/sh -c cd /tmp && git ls-remote http://git.myserver.localdomain/other.git
        [INFO] Working directory: /tmp
        [INFO] Executing: /bin/sh -c cd /srv/dev/test/target/upstream-sources && git ls-files
        [INFO] Working directory: /srv/dev/test/target/upstream-sources
        


        ...so drop the additional pull and checkout - doesn't make any sense in git, really.

        Show
        Ancoron Luciferis added a comment - OK, I can confirm that the patch indeed fixes this problem but then the command sequence still is awful: [INFO] [scm:checkout {execution: export-inplace}] [INFO] Removing /srv/dev/test/target/upstream-sources [INFO] Executing: /bin/sh -c cd /srv/dev/test/target && git clone --branch develop http://git.myserver.localdomain/other.git /srv/dev/test/target/upstream-sources [INFO] Working directory: /srv/dev/test/target [INFO] Executing: /bin/sh -c cd /tmp && git ls-remote http://git.myserver.localdomain/other.git [INFO] Working directory: /tmp [INFO] Executing: /bin/sh -c cd /srv/dev/test/target/upstream-sources && git pull http://git.myserver.localdomain/other.git develop:develop [INFO] Working directory: /srv/dev/test/target/upstream-sources [INFO] Executing: /bin/sh -c cd /srv/dev/test/target/upstream-sources && git checkout develop [INFO] Working directory: /srv/dev/test/target/upstream-sources [INFO] Executing: /bin/sh -c cd /srv/dev/test/target/upstream-sources && git ls-files [INFO] Working directory: /srv/dev/test/target/upstream-sources What I would expect is this: [INFO] [scm:checkout {execution: export-inplace}] [INFO] Removing /srv/dev/test/target/upstream-sources [INFO] Executing: /bin/sh -c cd /srv/dev/test/target && git clone --branch develop http://git.myserver.localdomain/other.git /srv/dev/test/target/upstream-sources [INFO] Working directory: /srv/dev/test/target [INFO] Executing: /bin/sh -c cd /tmp && git ls-remote http://git.myserver.localdomain/other.git [INFO] Working directory: /tmp [INFO] Executing: /bin/sh -c cd /srv/dev/test/target/upstream-sources && git ls-files [INFO] Working directory: /srv/dev/test/target/upstream-sources ...so drop the additional pull and checkout - doesn't make any sense in git, really.
        Hide
        Olivier Lamy added a comment -

        Having a look at the code and that looks to be fixed (but issue not closed).
        @Ancoron Luciferis: can you try with last SNAPSHOT ?

        Show
        Olivier Lamy added a comment - Having a look at the code and that looks to be fixed (but issue not closed). @Ancoron Luciferis: can you try with last SNAPSHOT ?
        Hide
        Ancoron Luciferis added a comment -

        Using the latest 1.7-SNAPSHOT I now see the same output as with the patch applied to 1.6.

        Show
        Ancoron Luciferis added a comment - Using the latest 1.7-SNAPSHOT I now see the same output as with the patch applied to 1.6.
        Olivier Lamy made changes -
        Assignee Olivier Lamy [ olamy ]
        Fix Version/s 1.7 [ 18136 ]
        Olivier Lamy made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Olivier Lamy
            Reporter:
            Daniel Strassenburg
          • Votes:
            12 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: