{"thread":{"id":"23004","subject":"[PATCH] stash: dont save during a conflicted merge","startedAt":"2010-03-13T03:40:33Z","lastAt":"2010-03-16T03:05:03Z","messageCount":3,"participants":["Dave Olszewski","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"136694","messageId":"1268451633-30046-1-git-send-email-cxreg@pobox.com","threadId":"23004","inReplyTo":null,"subject":"[PATCH] stash: dont save during a conflicted merge","fromName":"Dave Olszewski","fromEmail":"cxreg@pobox.com","sentAt":"2010-03-13T03:40:33Z","receivedAt":"2010-03-13T03:40:33Z","isPatch":true,"sender":{"key":"cxreg@pobox.com","avatar":"https://avatars.githubusercontent.com/u/55474?v=4"},"body":"Similar to commit c8c562a, if a user is resolving conflicts, they may\nthink it wise to stash their current work tree and git pull to see if\nthere are additional changes on the remote.\n\nThe stash will fail to save if the index contains unmerged entries, but\nif the conflicts are resolved, the stash will succeed, and both\nMERGE_HEAD and MERGE_MSG will be removed.  This is probably a mistake,\nand we should warn the user and refuse to stash.\n\nSigned-off-by: Dave Olszewski <cxreg@pobox.com>\n---\n git-stash.sh     |    5 +++++\n t/t3903-stash.sh |   19 +++++++++++++++++++\n 2 files changed, 24 insertions(+), 0 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex aa47e54..1a70f8d 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -172,6 +172,11 @@ save_stash () {\n \ttest -f \"$GIT_DIR/logs/$ref_stash\" ||\n \t\tclear_stash || die \"Cannot initialize stash\"\n \n+\tif test -f \"$GIT_DIR/MERGE_HEAD\"\n+\tthen\n+\t\tdie \"You have not concluded your merge. (MERGE_HEAD exists)\";\n+\tfi\n+\n \tcreate_stash \"$stash_msg\"\n \n \t# Make sure the reflog for stash is kept.\ndiff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\nindex 476e5ec..9915f4f 100755\n--- a/t/t3903-stash.sh\n+++ b/t/t3903-stash.sh\n@@ -228,4 +228,23 @@ test_expect_success 'stash --invalid-option' '\n \ttest bar,bar2 = $(cat file),$(cat file2)\n '\n \n+test_expect_success 'stash during merge' '\n+\tgit branch other &&\n+\tgit checkout master &&\n+\techo conflict > conflict &&\n+\tgit add conflict &&\n+\tgit commit -m \"conflict\" &&\n+\tgit checkout other &&\n+\techo other content > conflict &&\n+\tgit add conflict &&\n+\tgit commit -m \"other branch conflict\" &&\n+\tgit checkout master &&\n+\ttest_must_fail git merge other &&\n+\ttest_must_fail git stash &&\n+\tgit add . &&\n+\tgit status &&\n+\ttest_must_fail git stash &&\n+\tgit reset --hard\n+'\n+\n test_done\n-- \n1.7.0.2.200.ga611.dirty\n"},{"id":"136886","messageId":"7vhbohdygu.fsf@alter.siamese.dyndns.org","threadId":"23004","inReplyTo":"1268451633-30046-1-git-send-email-cxreg@pobox.com","subject":"Re: [PATCH] stash: dont save during a conflicted merge","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-15T22:14:25Z","receivedAt":"2010-03-15T22:14:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dave Olszewski <cxreg@pobox.com> writes:\n\n> Similar to commit c8c562a, if a user is resolving conflicts, they may\n> think it wise to stash their current work tree and git pull to see if\n> there are additional changes on the remote.\n>\n> The stash will fail to save if the index contains unmerged entries, but\n> if the conflicts are resolved, the stash will succeed, and both\n> MERGE_HEAD and MERGE_MSG will be removed.  This is probably a mistake,\n> and we should warn the user and refuse to stash.\n\nWarning is probably Ok, but refusing with die() might be too much.\n\nWhen trying a topic with more than one integration branches (think\n\"master\", \"next, \"pu\"), and the merge is a bit too hairy that I am not\nvery confident with the resolution, I've deliberately used stash to record\na tentative conflict resolution to avoid contaminating my rerere database:\n\n    $ git merge topic\n    ... heavy conflicts, manually \"resolved\" to a dubious result ...\n    $ git rerere clear\n    $ git stash save \"tentative merge of topic\"\n    $ git stash apply\n    ... test test test ...\n    $ git reset --hard\n    $ git checkout another-integration-branch\n    $ git stash apply\n    ... test test test ...\n    ... repeat the above for other integration branches ...\n\nThis is using the stash as a glorified form of\n\n    $ git diff HEAD >./+save-tentative-merge\n\nand then applying it to other integration branches to test out\n\n    $ git reset --hard\n    $ git checkout another-integration-branch\n    $ git apply ./+save-tentative-merge\n\nbut it actually is better than diff/apply because stash application uses a\nreal three-way merge.\n\nSo I am not entirely happy with this feature-removal.\n"},{"id":"136915","messageId":"alpine.DEB.2.00.1003151954050.4362@narbuckle.genericorp.net","threadId":"23004","inReplyTo":"7vhbohdygu.fsf@alter.siamese.dyndns.org","subject":"Re: Re: [PATCH] stash: dont save during a conflicted merge","fromName":"Dave Olszewski","fromEmail":"cxreg@pobox.com","sentAt":"2010-03-16T03:05:03Z","receivedAt":"2010-03-16T03:05:03Z","isPatch":true,"sender":{"key":"cxreg@pobox.com","avatar":"https://avatars.githubusercontent.com/u/55474?v=4"},"body":"On Mon, 15 Mar 2010, Junio C Hamano wrote:\n\n> Dave Olszewski <cxreg@pobox.com> writes:\n>\n>> Similar to commit c8c562a, if a user is resolving conflicts, they may\n>> think it wise to stash their current work tree and git pull to see if\n>> there are additional changes on the remote.\n>>\n>> The stash will fail to save if the index contains unmerged entries, but\n>> if the conflicts are resolved, the stash will succeed, and both\n>> MERGE_HEAD and MERGE_MSG will be removed.  This is probably a mistake,\n>> and we should warn the user and refuse to stash.\n>\n> Warning is probably Ok, but refusing with die() might be too much.\n>\n> When trying a topic with more than one integration branches (think\n> \"master\", \"next, \"pu\"), and the merge is a bit too hairy that I am not\n> very confident with the resolution, I've deliberately used stash to record\n> a tentative conflict resolution to avoid contaminating my rerere database:\n>\n>    $ git merge topic\n>    ... heavy conflicts, manually \"resolved\" to a dubious result ...\n>    $ git rerere clear\n>    $ git stash save \"tentative merge of topic\"\n>    $ git stash apply\n>    ... test test test ...\n>    $ git reset --hard\n>    $ git checkout another-integration-branch\n>    $ git stash apply\n>    ... test test test ...\n>    ... repeat the above for other integration branches ...\n>\n> This is using the stash as a glorified form of\n>\n>    $ git diff HEAD >./+save-tentative-merge\n>\n> and then applying it to other integration branches to test out\n>\n>    $ git reset --hard\n>    $ git checkout another-integration-branch\n>    $ git apply ./+save-tentative-merge\n>\n> but it actually is better than diff/apply because stash application uses a\n> real three-way merge.\n>\n> So I am not entirely happy with this feature-removal.\n\nThis is an interesting use-case.  If you determine that your resolution\nis satisfactory, how then do you complete your merge?  You can't apply a\nstash on a dirty index, and the MERGE_* files are gone.  It seems like\nusing this workflow to \"pause\" and resume a merge is difficult, although\nit's exactly the thing that led to this patch in the first place.  Maybe\ngit-stash could hold onto those files somehow if they exist when saving?\n"}]}