3

The team I am working with would like to use continuous integration to automatically merge two git branches. However we want the continuous integration job to fail if there are merge conflicts, so that the developers can run the merge manually and resolve any issues.

Has anyone had experience of this kind of setup (ideally with TeamCity, but any CI server would be interesting)?

Barnaby Golden
  • 4,176
  • 1
  • 23
  • 28

2 Answers2

2

This can be achieved in TeamCity by using the Automatic Merge Build Feature

enter image description here

The merge will only be performed after a successful build, but if there are any conflicts during the merge it will subsequently fail the build.

More details can be found here - TeamCity Documentation

Hope this helps.

Matt
  • 3,684
  • 1
  • 17
  • 19
0

I wrote a bash script to do this a while back. Actually the full script does this for all open PRs with the test tag in our github repo.

Full script

Relevant bits:

try_merge()
{
    test -n "$1"
    local branch=$1 commit
    if ! commit=$(git rev-parse --verify -q $branch)
    then
        error bogus $branch
        return
    fi
    if bash -c 'set -o pipefail; git branch --contains '$commit' | grep -qw master'
    then
        warning already $branch
        return
    fi
    if git merge --ff-only $branch $commit
    then
        good fast $branch $commit
        return
    fi
    if git merge $branch $commit
    then
        good merge $branch $commit
        return
    fi
    git merge --abort
    error abort $branch $commit
    return
}
o11c
  • 15,265
  • 4
  • 50
  • 75