Why does branch merging not work in Bamboo OnDemand?
Asked by Alexander Aickin:

I've been trying out Bamboo OnDemand to get a sense for how automatic branch merging works, but I haven't been able to get it to ever work correctly. I made a simple repo on Bitbucket, put a simple maven prototype project into it and got it built. Then, I checked a simple failing test in called testBreaksInFeature into a branch called feature. I checked in an extra comment to master. The feature branch's build started failing in Bamboo, as expected, and the master branch did not. All good so far.

Next, I turned on branch merging, using Gatekeeper, and ran the build again. This time, to my surprise the build worked: no failing test. I logged into the elastic instance, sudo'ed up, and found the working directory for the job. Weirdly, git status revealed that the current branch was feature, and the staged changes in the directory were a deletion of the new test in the feature branch plus the addition of the comment from master. In other words, rather than being a merge from feature to master, it was a changeset that just turned feature into what master already had.

I was trying to figure out what was going on, so I replaced /usr/bin/git with a script that would log every call to git and then pass through to the real git. I found that Bamboo was calling the following sequence of commands:

* git version
* git fetch [https://name:password@bitbucket.org/name/reponame.git](https://name:password%40bitbucket.org/name/reponame.git) +refs/heads/master:refs/heads/master --update-head-ok
* git log -1 --format=%d --decorate=full a5a15ef91007c154a3d95f0974280da71ffdffeb
* git checkout -f master
* git version
* git fetch [https://name:password@bitbucket.org/name/reponame.git +refs/heads/feature:refs/heads/feature](https://name:password%40bitbucket.org/name/reponame.git%C2%A0+refs/heads/feature:refs/heads/feature) --update-head-ok
* git merge --no-commit b9474bd09ecaab814df6179b715fb17299f0805f
* git status --porcelain --untracked-files=no

I ran this sequence of commands in the working directory on the elastic instance, and then ran git status. That showed that I was still on master, and the staged changes were a clean merge from feature, failing test and all. But when I run the build with Gatekeeper, the working directory instead ends up on feature branch with bad changes staged that get rid of all feature changes.  
What could be going on here? I set the elastic instance to have a git capability of /usr/bin/git, which I presume is right. I've logged all calls to that version of git, but the build's sequence of calls to /usr/bin/git works just fine when you run it manually.  
Is Bamboo somehow using a combination of command line git and JGit in a way that's screwing up? How is my repo getting in this state before the build?


Answers:
author: Alexander Aickin
body: Thanks!

Glad to hear that the Git capability will be default; it was really, really confusing to figure out what was wrong with branch merging at first (with Github the error message was something like "Error merging branch: null", while with Bitbucket there was at least a stack trace, although it was not super helpful).

I opened a support ticket for the issue as you suggested: [JST-42618](https://support.atlassian.com/browse/JST-42618) .

comments: author: Alexander Aickin
body: Worth noting that this feature works better, but not perfectly with Mercurial. Gatekeeper seems to work correctly with branch merging (hooray!), but for some reason, merging back to master on a clean feature branch build gives "Failure Reason Exception during push: null" (boo!).


author: Przemek Bruski
body: > I set the elastic instance to have a git capability of /usr/bin/git

That's correct. Update on Monday will add that capabilty be default.
> Is Bamboo somehow using a combination of command line git and JGit in a way that's screwing up?

Possibly. I think it's best if you contacted support, we will be able to figure out what's happening there.


Tags: cloud