Interpreting git merge failures
- From
- Scott Bronson <bronson@rinspin.com>
- Date
- Jul 7, 2011, 18:45 UTC
- Message-ID
- <CAKmUPx5Qt2K+7F+BsW3WTmRjodBSrteuyG8p9oRHZuhApTu4+g@mail.gmail.com>
What is the best way to determine why a git merge failed? I'm writing a script that needs to do different things depending on what went wrong.
Right now I'm parsing error messages. It's obviously a bad idea and prone to breakage but it does work. Example:
`git fetch origin #{tag || :master}`
output = `git merge --ff-only FETCH_HEAD 2>&1` # warning, bad idea:
if output =~ /Not possible to fast-forward/
log "has different ancestry from upstream, removing and re-cloning."
remove_and_reclone
elsif msg =~ /You have unstaged changes/ ||
msg =~ /Your local changes [a-z ]* would be overwritten/ ||
msg =~ /commit your changes or stash them before you can merge/
log "has unsaved changes, invalid doc/tags file in upstream repo?"
work_around_tagsfile
elsif msg =~ /untracked working tree files would be overwritten/
log "has conflicting file, removing and re-cloning."
abort # don't blow away unknown file
else
log msg
abort
endThere's got to be a better way! I could special-case each check beforehand using git ls-files and friends but that seems almost as ugly... Hoping a smarter solution exists.
This is for https://github.com/bronson/vim-update-bundles
Thanks!
- Scott