4

I use pygit2 (libgit2 wrapper for python) and before creating a merge commit—i.e. commit with two parents—I would like to do a GitHub-like dry-run check to make sure that branches can, in fact, be auto-merged.

The obvious approach would be to loop over all commits since the branch point and check, line-by-line, for conflicts. But I think (hope?) there might be a better approach.

Anton Kovalyov
  • 2,808
  • 1
  • 22
  • 11
  • You might want to look into [`git merge-tree`](http://man.he.net/man1/git-merge-tree). I found it via [this answer](http://stackoverflow.com/questions/501407/is-there-a-git-merge-dry-run-option/6283843#6283843) to a previous question about how to do a dry run of a git merge. – daxelrod Sep 16 '11 at 01:17
  • You should update your question title to ask how to do it in pygit, and specify that you don't want to do it from the command line – Andy Sep 16 '11 at 01:46

1 Answers1

2

GitHub does this, I believe, by running the git merge some_branch command and checking the return status; for a conflicting merge, the git merge command returns 1.

$ git merge test1 
Auto-merging HELLO
CONFLICT (content): Merge conflict in HELLO
Automatic merge failed; fix conflicts and then commit the result.
$ echo $?
1

Do this in a throwaway branch, stemming off what will become the merge base.

Edit: The merge.verbosity option, when set to "0", may also be of some use (not sure how you can apply this to pygit without shelling out):

Controls the amount of output shown by the recursive merge strategy. Level 0 outputs nothing except a final error message if conflicts were detected. Level 1 outputs only conflicts, 2 outputs conflicts and file changes. Level 5 and above outputs debugging information. The default is level 2. Can be overridden by the GIT_MERGE_VERBOSITY environment variable.

See the "Configuration" section of the man page on git merge at http://linux.die.net/man/1/git-merge.

Nathan Kleyn
  • 5,103
  • 3
  • 32
  • 49