Re: How to pre-empt git pull merge error?
Thomas Rast writes: > Antoine Pelisse writes: > On Wed, 27 Nov 2013 15:17:27 + Pete Forman 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 > >>> I don't know a simple way to do the pre-merge check without actually >>> doing the merge (other than patching git merge to add a --dry-run >>> option) >> >> Wouldn't that be a nice use-case for git-recursive-merge --index-only >> ($gmane/236753) ? > > Possibly, but most of the use-cases for merge --dry-run are better > answered by the XY Problem question: > > Can you step back and explain what the *underlying* goal is? > > The above sounds a lot like a deployment script, and such scripts are > almost always better served by using an actual deployment tool, or > failing that, by using some form of checkout -f instead, to ensure > that they get whatever they are supposed to deploy. > > (Using a merge to update is really terrible in the face of > non-fast-forward updates, especially when caused by rewriting history > to not include some commits.) It is a deployment script and updates are fast-forward. There was a problem on a test server where a file had been hacked to investigate an issue. The next deploy failed with the merge error. There are three approaches, which might all be done with git or an actual deployment tool. 1. test early, bail out if deploy would fail 2. set target to good state before applying the merge 2a. discard changes 2b. stash changes I intend to use (1). First I will need to clean up the stray files or add more entries into .gitignore. test -z "$(git status --porcelain)" -- Pete Forman http://petef.22web.org/payg.html -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: How to pre-empt git pull merge error?
Antoine Pelisse writes: >>> On Wed, 27 Nov 2013 15:17:27 + >>> Pete Forman 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 >> I don't know a simple way to do the pre-merge check without actually >> doing the merge (other than patching git merge to add a --dry-run >> option) > > Wouldn't that be a nice use-case for git-recursive-merge --index-only > ($gmane/236753) ? As the original mentions "error: Your local changes to ...", I do not think it would be a good fit. I have to say that the safest and sanest way may be to: (1) Commit any such local change(s); server$ git commit -a (2) Pull that down to a pre-deploy repository from the "server"; prepare$ git pull ...to grab the "local changes" above... (3) Merge in whatever the update you want to have on the "server"; prepare$ git merge ...whatever... (4) and then stop the server, fast-forward to the result of (3), and then restart. server$ stop server server$ git pull --ff-only ...the prepared result of (3)... server$ start server -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: How to pre-empt git pull merge error?
Antoine Pelisse writes: >>> On Wed, 27 Nov 2013 15:17:27 + >>> Pete Forman 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 >> I don't know a simple way to do the pre-merge check without actually >> doing the merge (other than patching git merge to add a --dry-run >> option) > > Wouldn't that be a nice use-case for git-recursive-merge --index-only > ($gmane/236753) ? Possibly, but most of the use-cases for merge --dry-run are better answered by the XY Problem question: Can you step back and explain what the *underlying* goal is? The above sounds a lot like a deployment script, and such scripts are almost always better served by using an actual deployment tool, or failing that, by using some form of checkout -f instead, to ensure that they get whatever they are supposed to deploy. (Using a merge to update is really terrible in the face of non-fast-forward updates, especially when caused by rewriting history to not include some commits.) -- Thomas Rast t...@thomasrast.ch -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: How to pre-empt git pull merge error?
>> On Wed, 27 Nov 2013 15:17:27 + >> Pete Forman 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 >>> > I don't know a simple way to do the pre-merge check without actually > doing the merge (other than patching git merge to add a --dry-run > option) Wouldn't that be a nice use-case for git-recursive-merge --index-only ($gmane/236753) ? -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: How to pre-empt git pull merge error?
Konstantin Khomoutov writes: > On Wed, 27 Nov 2013 15:17:27 + > Pete Forman 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 The idea seems to be to stop the server before actually doing the merge (and avoid doing so if the merge is bound to fail). I don't know a simple way to do the pre-merge check without actually doing the merge (other than patching git merge to add a --dry-run option), but you can do a pessimistic check by using the require_work_tree_exists shell function defined in git-sh-setup (copied below, but you can call it from a shell script after doing . "$(git --exec-path)/git-sh-setup"): require_clean_work_tree () { git rev-parse --verify HEAD >/dev/null || exit 1 git update-index -q --ignore-submodules --refresh err=0 if ! git diff-files --quiet --ignore-submodules then echo >&2 "Cannot $1: You have unstaged changes." err=1 fi if ! git diff-index --cached --quiet --ignore-submodules HEAD -- then if [ $err = 0 ] then echo >&2 "Cannot $1: Your index contains uncommitted changes." else echo >&2 "Additionally, your index contains uncommitted changes." fi err=1 fi if [ $err = 1 ] then test -n "$2" && echo >&2 "$2" exit 1 fi } Additionally, you may want to check that the merge is a fast-forward (hence can't result in merge conflict), e.g. by checking that the current commit is the merge base between itself and the commit to merge (git merge-base HEAD $commit). -- Matthieu Moy http://www-verimag.imag.fr/~moy/ -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: How to pre-empt git pull merge error?
On Wed, 27 Nov 2013 15:17:27 + Pete Forman 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 ? -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html