How to pre-empt git pull merge error?

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

How to pre-empt git pull merge error?

From: Pete Forman <hidden>
Date: 2016-06-15 22:59:20

I am looking for a way of detecting up front whether a git pull or git
merge would fail. The sort of script I want to perform is to update a
server.

    git fetch
    git okay
    stop server
    backup data
    git merge
    start server

Here git okay is a place holder for the command I am asking for.

If a file has been changed outside of a commit then git pull fails with
the following error.

error: Your local changes to '...' would be overwritten by merge.
Aborting. Please, commit your changes or stash them before you can
merge.

I would like git okay to perform the pre-merge checks described in git
merge and return non-zero status so that the script aborts before the
server is stopped.

Possibilities I have looked for and not found include git merge
--dry-run. My best line of thought is git status --porcelain |
pre-merge-okay. That seems like a lot of work to make a pre-merge-okay
that deals with things like benign untracked files.

I have also asked this question on Stack Overflow but received no
answers.

http://stackoverflow.com/questions/20221383/

-- 
Pete Forman

Re: How to pre-empt git pull merge error?

From: Konstantin Khomoutov <hidden>
Date: 2016-06-15 22:59:20

On Wed, 27 Nov 2013 15:17:27 +0000
Pete Forman [off-list ref] wrote:
I am looking for a way of detecting up front whether a git pull or git
merge would fail. The sort of script I want to perform is to update a
server.

    git fetch
    git okay
    stop server
    backup data
    git merge
    start server

Here git okay is a place holder for the command I am asking for.

If a file has been changed outside of a commit then git pull fails
with the following error.

error: Your local changes to '...' would be overwritten by merge.
Aborting. Please, commit your changes or stash them before you can
merge.
What's wrong with "git okay" being

if git merge whatever 2>/dev/null; then
  ... OK path
else
  ... "merge failed" path
fi

?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help