Uploaded image for project: 'Bamboo Data Center'
  1. Bamboo Data Center
  2. BAM-10316

Git checkout leaves the source in a "detached HEAD" state

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Low Low
    • 3.4.1, 4.0
    • None
    • None
    • None

      From CBAC https://confluence-bamboo.atlassian.com/download/CONFREL-CONFRELSTABLE2-RELEASEPREPARE/build_logs/CONFREL-CONFRELSTABLE2-RELEASEPREPARE-84.log

      Cleaning build directory '/opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE'
      Updating source code to revision: bbd338275d823646e4f96679a90140da3fef93b3
      Substituting variable: ${bamboo.confluence.current.stable.branch} with confluence-project-4.1-stable
      Creating local git repository in '/opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE/.git'.
      Fetching branch 'refs/heads/confluence-project-4.1-stable' from 'git@bitbucket.org:atlassian/confluence.git'. Will try to do a shallow fetch.
      From ssh://127.0.0.1:50843/atlassian/confluence
       * branch            confluence-project-4.1-stable -> FETCH_HEAD
      Checking out revision bbd338275d823646e4f96679a90140da3fef93b3.
      Note: checking out 'bbd338275d823646e4f96679a90140da3fef93b3'.
      
      You are in 'detached HEAD' state. You can look around, make experimental
      changes and commit them, and you can discard any commits you make in this
      state without impacting any branches by performing another checkout.
      
      If you want to create a new branch to retain commits you create, you may
      do so (now or later) by using -b with the checkout command again. Example:
      
        git checkout -b new_branch_name
      
      HEAD is now at bbd3382... CONFDEV-6609 resolved a SNAPSHOT
      Updated source code to revision: bbd338275d823646e4f96679a90140da3fef93b3
      Finished task 'Checkout Default Repository'
      

      While this isn't a problem for most uses, the Maven release plugin does require it and craps itself. Apparently jgit did not check out to a detached HEAD

      [INFO] Checking in modified POMs...
      [INFO] Executing: /bin/sh -c cd /opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE && git add -- pom.xml confluence-core/confluence-testutils/pom.xml confluence-core/confluence-bucket/pom.xml confluence-core/confluence-compatibility/pom.xml confluence-core/confluence-upgrade/pom.xml confluence-not-shippable/pom.xml confluence-core/confluence/pom.xml confluence-core/confluence-cache/pom.xml confluence-core/confluence-cache/confluence-cache-ehcache/pom.xml confluence-core/confluence-cache/confluence-cache-coherence/pom.xml confluence-plugins/confluence-misc-plugins/confluence-rpc-plugin/pom.xml confluence-plugins/confluence-misc-plugins/confluence-rest/confluence-rest-plugin/pom.xml confluence-plugins/confluence-misc-plugins/fixedwidth-theme/pom.xml confluence-plugins/confluence-misc-plugins/confluence-tinymce-plugin/pom.xml confluence-plugins/confluence-misc-plugins/confluence-sal/pom.xml confluence-plugins/confluence-misc-plugins/confluence-sal/confluence-sal-base/pom.xml confluence-plugins/confluence-misc-plugins/confluence-sal/confluence-sal-plugin/pom.xml confluence-plugins/confluence-misc-plugins/confluence-sal/confluence-sal-setup-plugin/pom.xml confluence-plugins/confluence-misc-plugins/confluence-keyboard-shortcuts/pom.xml confluence-plugins/confluence-misc-plugins/confluence-core-macros/pom.xml confluence-plugins/confluence-misc-plugins/confluence-dashboard-macros/pom.xml confluence-plugins/confluence-bundled-plugins/pom.xml confluence-plugins/confluence-bundled-plugins/atlassian-editor-plugin/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-aui-staging/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-dashboard-actions/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-drag-and-drop/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-event-service/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-expand-macro/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-gadgets/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-gadgets/gadgets-plugin/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-gadgets/gadgets-plugin-spi/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-mail-archiving/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-paste/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-schedule-admin/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-soy/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-space-directory/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-tdm-merger/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-view-source/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-view-storage-format/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-whats-new/pom.xml confluence-build/confluence-bundled-plugins-library/pom.xml confluence-build/confluence-bundled-plugins-setup-library/pom.xml confluence-plugins/confluence-test-plugins/confluence-functestrpc-plugin/pom.xml confluence-plugins/confluence-test-plugins/confluence-functestxss-plugin/pom.xml confluence-test/confluence-test-support/pom.xml confluence-plugins/confluence-test-plugins/velocity-deprecation-test-plugin/pom.xml confluence-test/confluence-acceptance-test/pom.xml confluence-plugins/confluence-test-plugins/confluence-qunit-plugin/pom.xml confluence-test/atlassian-confluence-pageobjects/pom.xml confluence-core/confluence-webapp/pom.xml confluence-build/confluence-webapp-cluster/pom.xml confluence-studio-project/pom.xml confluence-studio-project/confluence-studio-host-components/pom.xml confluence-studio-project/confluence-studio-plugins/pom.xml confluence-studio-project/confluence-studio-plugins/confluence-studio-common-plugin/pom.xml confluence-studio-project/confluence-studio-plugins/confluence-studio-standalone-plugin/pom.xml confluence-studio-project/confluence-studio-plugins/confluence-studio-theme-plugin/pom.xml confluence-studio-project/confluence-studio-plugins/confluence-studio-space-import-plugin/pom.xml confluence-studio-project/confluence-studio-webapp/pom.xml confluence-studio-project/confluence-studio-ondemand-test/pom.xml confluence-test/confluence-selenium-test/pom.xml confluence-build/confluence-test-runner/pom.xml confluence-build/confluence-test-runner/confluence-crowd-test/pom.xml confluence-build/confluence-test-runner/confluence-multi-test/pom.xml confluence-build/confluence-test-runner/confluence-selenium-runner/pom.xml confluence-test/confluence-webdriver-test/pom.xml confluence-build/confluence-test-runner/confluence-webdriver-runner/pom.xml confluence-build/confluence-test-runner/confluence-parallel-test/pom.xml confluence-build/confluence-test-runner/confluence-roundtrip-test/pom.xml confluence-build/confluence-test-runner/confluence-setup-import-test/pom.xml confluence-build/confluence-test-runner/confluence-qunit-runner/pom.xml confluence-build/confluence-test-runner/confluence-qunit-webapp/pom.xml confluence-build/confluence-test-runner/confluence-load-test/pom.xml confluence-plugins/confluence-test-plugins/editor-test-plugin/pom.xml
      [INFO] Working directory: /opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE
      [INFO] Executing: /bin/sh -c cd /opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE && git status
      [INFO] Working directory: /opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE
      [INFO] Executing: /bin/sh -c cd /opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE && git commit --verbose -F /tmp/maven-scm-114525821.commit pom.xml confluence-core/confluence-testutils/pom.xml confluence-core/confluence-bucket/pom.xml confluence-core/confluence-compatibility/pom.xml confluence-core/confluence-upgrade/pom.xml confluence-not-shippable/pom.xml confluence-core/confluence/pom.xml confluence-core/confluence-cache/pom.xml confluence-core/confluence-cache/confluence-cache-ehcache/pom.xml confluence-core/confluence-cache/confluence-cache-coherence/pom.xml confluence-plugins/confluence-misc-plugins/confluence-rpc-plugin/pom.xml confluence-plugins/confluence-misc-plugins/confluence-rest/confluence-rest-plugin/pom.xml confluence-plugins/confluence-misc-plugins/fixedwidth-theme/pom.xml confluence-plugins/confluence-misc-plugins/confluence-tinymce-plugin/pom.xml confluence-plugins/confluence-misc-plugins/confluence-sal/pom.xml confluence-plugins/confluence-misc-plugins/confluence-sal/confluence-sal-base/pom.xml confluence-plugins/confluence-misc-plugins/confluence-sal/confluence-sal-plugin/pom.xml confluence-plugins/confluence-misc-plugins/confluence-sal/confluence-sal-setup-plugin/pom.xml confluence-plugins/confluence-misc-plugins/confluence-keyboard-shortcuts/pom.xml confluence-plugins/confluence-misc-plugins/confluence-core-macros/pom.xml confluence-plugins/confluence-misc-plugins/confluence-dashboard-macros/pom.xml confluence-plugins/confluence-bundled-plugins/pom.xml confluence-plugins/confluence-bundled-plugins/atlassian-editor-plugin/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-aui-staging/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-dashboard-actions/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-drag-and-drop/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-event-service/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-expand-macro/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-gadgets/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-gadgets/gadgets-plugin/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-gadgets/gadgets-plugin-spi/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-mail-archiving/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-paste/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-schedule-admin/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-soy/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-space-directory/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-tdm-merger/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-view-source/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-view-storage-format/pom.xml confluence-plugins/confluence-bundled-plugins/confluence-whats-new/pom.xml confluence-build/confluence-bundled-plugins-library/pom.xml confluence-build/confluence-bundled-plugins-setup-library/pom.xml confluence-plugins/confluence-test-plugins/confluence-functestrpc-plugin/pom.xml confluence-plugins/confluence-test-plugins/confluence-functestxss-plugin/pom.xml confluence-test/confluence-test-support/pom.xml confluence-plugins/confluence-test-plugins/velocity-deprecation-test-plugin/pom.xml confluence-test/confluence-acceptance-test/pom.xml confluence-plugins/confluence-test-plugins/confluence-qunit-plugin/pom.xml confluence-test/atlassian-confluence-pageobjects/pom.xml confluence-core/confluence-webapp/pom.xml confluence-build/confluence-webapp-cluster/pom.xml confluence-studio-project/pom.xml confluence-studio-project/confluence-studio-host-components/pom.xml confluence-studio-project/confluence-studio-plugins/pom.xml confluence-studio-project/confluence-studio-plugins/confluence-studio-common-plugin/pom.xml confluence-studio-project/confluence-studio-plugins/confluence-studio-standalone-plugin/pom.xml confluence-studio-project/confluence-studio-plugins/confluence-studio-theme-plugin/pom.xml confluence-studio-project/confluence-studio-plugins/confluence-studio-space-import-plugin/pom.xml confluence-studio-project/confluence-studio-webapp/pom.xml confluence-studio-project/confluence-studio-ondemand-test/pom.xml confluence-test/confluence-selenium-test/pom.xml confluence-build/confluence-test-runner/pom.xml confluence-build/confluence-test-runner/confluence-crowd-test/pom.xml confluence-build/confluence-test-runner/confluence-multi-test/pom.xml confluence-build/confluence-test-runner/confluence-selenium-runner/pom.xml confluence-test/confluence-webdriver-test/pom.xml confluence-build/confluence-test-runner/confluence-webdriver-runner/pom.xml confluence-build/confluence-test-runner/confluence-parallel-test/pom.xml confluence-build/confluence-test-runner/confluence-roundtrip-test/pom.xml confluence-build/confluence-test-runner/confluence-setup-import-test/pom.xml confluence-build/confluence-test-runner/confluence-qunit-runner/pom.xml confluence-build/confluence-test-runner/confluence-qunit-webapp/pom.xml confluence-build/confluence-test-runner/confluence-load-test/pom.xml confluence-plugins/confluence-test-plugins/editor-test-plugin/pom.xml
      [INFO] Working directory: /opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE
      [INFO] Executing: /bin/sh -c cd /opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE && git symbolic-ref HEAD
      [INFO] Working directory: /opt/bamboo-agent/xml-data/build-dir/CONFREL-CONFRELSTABLE2-RELEASEPREPARE
      [INFO] ------------------------------------------------------------------------
      [ERROR] BUILD ERROR
      [INFO] ------------------------------------------------------------------------
      [INFO] An error is occurred in the checkin process: Exception while executing SCM command.
      
      Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref
      

      Talking to Stefan Saasen he thinks that if we specified both the -b branch_name and -r revision to the checkout command, it will work

            [BAM-10316] Git checkout leaves the source in a "detached HEAD" state

            Both issues have been fixed in 1.7-m4.
            You could just update the plugin itself (restart of Bamboo required) - so see the fixes.

            I'll see if we can have no DETACHED HEAD at all if SHA1 is used, but so far for native it seems to be normal (Hudson plugin expierience the same problem)

            Marek Went (Inactive) added a comment - Both issues have been fixed in 1.7-m4. You could just update the plugin itself (restart of Bamboo required) - so see the fixes. I'll see if we can have no DETACHED HEAD at all if SHA1 is used, but so far for native it seems to be normal (Hudson plugin expierience the same problem)

            There is definitely a change in behaviour between the jgit and the native git checkout that can still be observed (as it depends on whether the agent has the native git capability) and might affect tasks downstream.

            After checkout using native git:

            • The working copy is on a detached HEAD
            • refs/heads is empty - no local branch exists

            After checkout using jgit:

            • The working copy is on a local branch that matches the branch configured in the repository settings
            • refs/heads therefore contains a branch

            This is affecting our issue driven deployment plugin that is trying to look up the current branch. We are going to rework that but I think it's a bit unfortunate that the behaviour changes depending on whether the agent has the native git capability.

            Stefan Saasen (Inactive) added a comment - There is definitely a change in behaviour between the jgit and the native git checkout that can still be observed (as it depends on whether the agent has the native git capability) and might affect tasks downstream. After checkout using native git: The working copy is on a detached HEAD refs/heads is empty - no local branch exists After checkout using jgit: The working copy is on a local branch that matches the branch configured in the repository settings refs/heads therefore contains a branch This is affecting our issue driven deployment plugin that is trying to look up the current branch. We are going to rework that but I think it's a bit unfortunate that the behaviour changes depending on whether the agent has the native git capability.

            Marek Went (Inactive) added a comment - - edited

            @Mark - of course your scenario would work.
            At least in area of SHA1 / branch for checkout.

            Regarding shallow clones:
            We do try with depth 1. If it fails, we have a fallback to regular fetch - so it covers this case.
            So far we don't try to calculate required depth - however, I can imagine it is doable.

            Marek Went (Inactive) added a comment - - edited @Mark - of course your scenario would work. At least in area of SHA1 / branch for checkout. Regarding shallow clones: We do try with depth 1. If it fails, we have a fallback to regular fetch - so it covers this case. So far we don't try to calculate required depth - however, I can imagine it is doable.

            What I did is additional check between fetch and checkout.
            Iif requested revision is a HEAD of a branch - I use branch name - as this is exactly the same.
            If not - I still use SHA1 as the only proper way.

            We always checkout in Bamboo well defined REVISION - not the tip.

            Marek Went (Inactive) added a comment - What I did is additional check between fetch and checkout. Iif requested revision is a HEAD of a branch - I use branch name - as this is exactly the same. If not - I still use SHA1 as the only proper way. We always checkout in Bamboo well defined REVISION - not the tip.

            Good point, in this case the commit is still on a branch, it's just not the HEAD (or tip) of that branch.

            If you don't do a shallow clone I guess you could still determine a branch that contains that revision, check out that branch and reset it to the given commit?

            Something like:

            git branch --contains SHA1
            #Pick one of the branches listed
            git checkout -b BRANCH origin/BRANCH
            git reset --hard SHA1
            

            Unfortunately that won't work with a shallow clone.

            I don't quite see how fetching a single branch using a shallow clone of depth 1 would work in the scenario Mark described anyway.
            AFAIK git fetch can only fetch refs but not specific commits so every shallow fetch would only ever get the tip of the branch, right?

            So in Marks' example (step 5) git fetch REPO refs/heads/stable would get rev#2 and as it is a shallow clone it wouldn't contain the commit object for rev#1, right (at least if depth is always 1)?

            Note: Not using the tip of a branch would cause the mvn release plugin to fail anyway as it would try to push changes on top of an old commit to the remote.
            This is partly a conceptual problem as it could always be the case that someone else pushes to the remote while the build is running (we usually code freeze during the release build) so I don't think it's a problem that the git plugin needs to consider.

            In general I'm wondering if the scenario Mark described ever worked or whether the git plugin was always checking out the tip?

            Stefan Saasen (Inactive) added a comment - - edited Good point, in this case the commit is still on a branch, it's just not the HEAD (or tip) of that branch. If you don't do a shallow clone I guess you could still determine a branch that contains that revision, check out that branch and reset it to the given commit? Something like: git branch --contains SHA1 #Pick one of the branches listed git checkout -b BRANCH origin/BRANCH git reset --hard SHA1 Unfortunately that won't work with a shallow clone. I don't quite see how fetching a single branch using a shallow clone of depth 1 would work in the scenario Mark described anyway. AFAIK git fetch can only fetch refs but not specific commits so every shallow fetch would only ever get the tip of the branch, right? So in Marks' example (step 5) git fetch REPO refs/heads/stable would get rev#2 and as it is a shallow clone it wouldn't contain the commit object for rev#1, right (at least if depth is always 1)? Note : Not using the tip of a branch would cause the mvn release plugin to fail anyway as it would try to push changes on top of an old commit to the remote. This is partly a conceptual problem as it could always be the case that someone else pushes to the remote while the build is running (we usually code freeze during the release build) so I don't think it's a problem that the git plugin needs to consider. In general I'm wondering if the scenario Mark described ever worked or whether the git plugin was always checking out the tip?

            MarkC added a comment -

            Marek,

            I guess the scenario I still want to work:

            1. 0900AM mchai pushes changes to branch "stable". Revision #1
            2. 0901 - "stable" BAM-STAB-1 plan gets queued with revision #1, with mchai's changes
            3. 0903 - mwent pushes changes to branch "stable". rev #2
            4. 0904 - BAM-STAB-2 gets queued with rev#2
            5. 0910 - BAM-STAB-1 starts building on an agent, updating / checking out the source to rev#1 on branch "stable"

            Won't the change to only check out the branch make this scenario fail?

            MarkC added a comment - Marek, I guess the scenario I still want to work: 0900AM mchai pushes changes to branch "stable". Revision #1 0901 - "stable" BAM-STAB-1 plan gets queued with revision #1, with mchai's changes 0903 - mwent pushes changes to branch "stable". rev #2 0904 - BAM-STAB-2 gets queued with rev#2 0910 - BAM-STAB-1 starts building on an agent, updating / checking out the source to rev#1 on branch "stable" Won't the change to only check out the branch make this scenario fail?

            I think Mark was mentioning the need to base the checkout on a particular revision instead of a branch.
            But I can't see how in Bamboo land a revision couldn't be based on a branch anyway so I think your approach is perfectly valid.

            Stefan Saasen (Inactive) added a comment - I think Mark was mentioning the need to base the checkout on a particular revision instead of a branch. But I can't see how in Bamboo land a revision couldn't be based on a branch anyway so I think your approach is perfectly valid.

            Marek Went (Inactive) added a comment - - edited

            I've added a relatively simple workaround.

            mvn release:prepare and perform can be done on the HEAD of any branch anyway. So instead of creating the new branch - I'm checking if revision I'm building as a release build is a HEAD of my branch (or master of course). If it is - instead of

            git checkout SHA1
            

            I call

            git checkout branch_name
            

            It does the trick - I'm not on detached head any more - and don't create not wanted branch.

            If revision is not the HEAD - release would fail anyway - so detached head is not a problem here.

            BTW - I wonder why git does not check such thing by himself...

            Marek Went (Inactive) added a comment - - edited I've added a relatively simple workaround. mvn release:prepare and perform can be done on the HEAD of any branch anyway. So instead of creating the new branch - I'm checking if revision I'm building as a release build is a HEAD of my branch (or master of course). If it is - instead of git checkout SHA1 I call git checkout branch_name It does the trick - I'm not on detached head any more - and don't create not wanted branch. If revision is not the HEAD - release would fail anyway - so detached head is not a problem here. BTW - I wonder why git does not check such thing by himself...

            Marek Went (Inactive) added a comment - - edited
            git checkout -f -b dummy_branch_name SHA1
            

            1 build:

                                    Fetching branch 'refs/heads/master' from 'git://github.com/atlassian/bamboo-git-plugin.git'. Will try to do a shallow fetch.
            06-Dec-2011 07:37:45 	/usr/local/git/bin/git fetch git://github.com/atlassian/bamboo-git-plugin.git refs/heads/master --verbose --depth 1
            06-Dec-2011 07:37:52 	From git://github.com/atlassian/bamboo-git-plugin
            06-Dec-2011 07:37:52 	* branch            master     -> FETCH_HEAD
            06-Dec-2011 07:37:52 	Checking out revision 20a557010bbaa81938f544a9c9ae3a956b3d3eae.
            06-Dec-2011 07:37:52 	/usr/local/git/bin/git checkout -f -b dummy_branch_name 20a557010bbaa81938f544a9c9ae3a956b3d3eae
            06-Dec-2011 07:37:52 	Switched to a new branch 'dummy_branch_name'
            06-Dec-2011 07:37:52 	Updated source code to revision: 20a557010bbaa81938f544a9c9ae3a956b3d3eae
            

            2 build

            06-Dec-2011 07:38:25 	Updating source code to revision: 20a557010bbaa81938f544a9c9ae3a956b3d3eae
            06-Dec-2011 07:38:25 	/usr/local/git/bin/git version
            06-Dec-2011 07:38:25 	Fetching branch 'refs/heads/master' from 'git://github.com/atlassian/bamboo-git-plugin.git'. Will try to do a shallow fetch.
            06-Dec-2011 07:38:25 	/usr/local/git/bin/git fetch git://github.com/atlassian/bamboo-git-plugin.git refs/heads/master --verbose --depth 1
            06-Dec-2011 07:38:31 	From git://github.com/atlassian/bamboo-git-plugin
            06-Dec-2011 07:38:31 	* branch            master     -> FETCH_HEAD
            06-Dec-2011 07:38:31 	Checking out revision 20a557010bbaa81938f544a9c9ae3a956b3d3eae.
            06-Dec-2011 07:38:31 	/usr/local/git/bin/git checkout -f -b dummy_branch_name 20a557010bbaa81938f544a9c9ae3a956b3d3eae
            06-Dec-2011 07:38:31 	fatal: A branch named 'dummy_branch_name' already exists.
            06-Dec-2011 07:38:31 	Warning: failed to checkout source code to directory '/Users/mwent/projects/bamboo/bamboo-homes/8085/xml-data/build-dir/GR-BG-JOB1', trying to recover...
            06-Dec-2011 07:38:31 	Cleaned source directory '/Users/mwent/projects/bamboo/bamboo-homes/8085/xml-data/build-dir/GR-BG-JOB1'...
            06-Dec-2011 07:38:31 	Checking out revision 20a557010bbaa81938f544a9c9ae3a956b3d3eae.
            06-Dec-2011 07:38:31 	Creating local git repository in '/Users/mwent/projects/bamboo/bamboo-homes/8085/xml-data/build-dir/GR-BG-JOB1/.git'.
            06-Dec-2011 07:38:31 	/usr/local/git/bin/git checkout -f -b dummy_branch_name 20a557010bbaa81938f544a9c9ae3a956b3d3eae
            06-Dec-2011 07:38:31 	Switched to a new branch 'dummy_branch_name'
            06-Dec-2011 07:38:31 	Checkout completed, recover successful.
            06-Dec-2011 07:38:31 	Updated source code to revision: 20a557010bbaa81938f544a9c9ae3a956b3d3eae
            

            So, as branch already exists the second try fails - and we recreate working dir as a fallback for failing checkout. Time consuming

            Generally, creating branch is not a problem - as DETACHED HEAD as well.
            However what we want to fix here is a mvn release:prepare mvn release:perform.
            As we create new branch release:prepare would fail as there are uncommited changes.

            And we don't want to commit local branch to the remote repository, where we create tags in the release procedure.

            Marek Went (Inactive) added a comment - - edited git checkout -f -b dummy_branch_name SHA1 1 build: Fetching branch 'refs/heads/master' from 'git: //github.com/atlassian/bamboo-git-plugin.git' . Will try to do a shallow fetch. 06-Dec-2011 07:37:45 /usr/local/git/bin/git fetch git: //github.com/atlassian/bamboo-git-plugin.git refs/heads/master --verbose --depth 1 06-Dec-2011 07:37:52 From git: //github.com/atlassian/bamboo-git-plugin 06-Dec-2011 07:37:52 * branch master -> FETCH_HEAD 06-Dec-2011 07:37:52 Checking out revision 20a557010bbaa81938f544a9c9ae3a956b3d3eae. 06-Dec-2011 07:37:52 /usr/local/git/bin/git checkout -f -b dummy_branch_name 20a557010bbaa81938f544a9c9ae3a956b3d3eae 06-Dec-2011 07:37:52 Switched to a new branch 'dummy_branch_name' 06-Dec-2011 07:37:52 Updated source code to revision: 20a557010bbaa81938f544a9c9ae3a956b3d3eae 2 build 06-Dec-2011 07:38:25 Updating source code to revision: 20a557010bbaa81938f544a9c9ae3a956b3d3eae 06-Dec-2011 07:38:25 /usr/local/git/bin/git version 06-Dec-2011 07:38:25 Fetching branch 'refs/heads/master' from 'git: //github.com/atlassian/bamboo-git-plugin.git' . Will try to do a shallow fetch. 06-Dec-2011 07:38:25 /usr/local/git/bin/git fetch git: //github.com/atlassian/bamboo-git-plugin.git refs/heads/master --verbose --depth 1 06-Dec-2011 07:38:31 From git: //github.com/atlassian/bamboo-git-plugin 06-Dec-2011 07:38:31 * branch master -> FETCH_HEAD 06-Dec-2011 07:38:31 Checking out revision 20a557010bbaa81938f544a9c9ae3a956b3d3eae. 06-Dec-2011 07:38:31 /usr/local/git/bin/git checkout -f -b dummy_branch_name 20a557010bbaa81938f544a9c9ae3a956b3d3eae 06-Dec-2011 07:38:31 fatal: A branch named 'dummy_branch_name' already exists. 06-Dec-2011 07:38:31 Warning: failed to checkout source code to directory '/Users/mwent/projects/bamboo/bamboo-homes/8085/xml-data/build-dir/GR-BG-JOB1' , trying to recover... 06-Dec-2011 07:38:31 Cleaned source directory '/Users/mwent/projects/bamboo/bamboo-homes/8085/xml-data/build-dir/GR-BG-JOB1' ... 06-Dec-2011 07:38:31 Checking out revision 20a557010bbaa81938f544a9c9ae3a956b3d3eae. 06-Dec-2011 07:38:31 Creating local git repository in '/Users/mwent/projects/bamboo/bamboo-homes/8085/xml-data/build-dir/GR-BG-JOB1/.git' . 06-Dec-2011 07:38:31 /usr/local/git/bin/git checkout -f -b dummy_branch_name 20a557010bbaa81938f544a9c9ae3a956b3d3eae 06-Dec-2011 07:38:31 Switched to a new branch 'dummy_branch_name' 06-Dec-2011 07:38:31 Checkout completed, recover successful. 06-Dec-2011 07:38:31 Updated source code to revision: 20a557010bbaa81938f544a9c9ae3a956b3d3eae So, as branch already exists the second try fails - and we recreate working dir as a fallback for failing checkout. Time consuming Generally, creating branch is not a problem - as DETACHED HEAD as well. However what we want to fix here is a mvn release:prepare mvn release:perform. As we create new branch release:prepare would fail as there are uncommited changes. And we don't want to commit local branch to the remote repository, where we create tags in the release procedure.

            -b branch_name and -r revision to the checkout command, it will work

            Not quite what I meant, you can use:

            git checkout -b branch SHA1
            

            to create and checkout a local branch named branch based on the given commit id.

            Couldn't you just recreate the local branch on every build using something like:

            git branch -f branch SHA1
            

            ?

            The name of the local branch doesn't really matter in this case and the -f forces it to recreate the branch with the given commit id.

            Stefan Saasen (Inactive) added a comment - - edited -b branch_name and -r revision to the checkout command, it will work Not quite what I meant, you can use: git checkout -b branch SHA1 to create and checkout a local branch named branch based on the given commit id. Couldn't you just recreate the local branch on every build using something like: git branch -f branch SHA1 ? The name of the local branch doesn't really matter in this case and the -f forces it to recreate the branch with the given commit id.

              mwent Marek Went (Inactive)
              mark@atlassian.com MarkC
              Affected customers:
              0 This affects my team
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: