# [PATCH 0/2] git-stash: clear rerere state on conflict

3 messages from 2012-07-06 to 2012-07-06. Participants: Phil Hord.
Thread: https://gitlist.dev/t/30969

## Phil Hord, 2012-07-06 16:22

Subject: [PATCH 0/2] git-stash: clear rerere state on conflict
Message-ID: <1341591772-26251-1-git-send-email-hordp@cisco.com>
URL: https://gitlist.dev/e/1341591772-26251-1-git-send-email-hordp%40cisco.com

```
This patch series adds a failing test and then a fix for the condition
discussed in these threads:

http://article.gmane.org/gmane.comp.version-control.git/177224
http://article.gmane.org/gmane.comp.version-control.git/201045
http://article.gmane.org/gmane.comp.version-control.git/200178/match=merge_rr

I previously floated this wrong-headed test after the same problem:
http://article.gmane.org/gmane.comp.version-control.git/177231

[PATCH 1/2] test: mergetool ignores rerere in git-stash
[PATCH 2/2] Clear rerere status during stash conflict

```

## Phil Hord, 2012-07-06 16:22

Subject: [PATCH 1/2] test: mergetool ignores rerere in git-stash
Message-ID: <1341591772-26251-2-git-send-email-hordp@cisco.com>
URL: https://gitlist.dev/e/1341591772-26251-2-git-send-email-hordp%40cisco.com
In-Reply-To: <1341591772-26251-1-git-send-email-hordp@cisco.com>

```
Add a failing test to confirm the leftover rerere
state files interfere with git-mergetool during a
conflicted stash apply.

Signed-off-by: Phil Hord <hordp@cisco.com>
---
 t/t7610-mergetool.sh | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index f5e16fc..2796c53 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -55,6 +55,16 @@ test_expect_success 'setup' '
     git rm file12 &&
     git commit -m "branch1 changes" &&
 
+    git checkout -b stash1 master &&
+    echo stash1 change file11 >file11 &&
+    git add file11 &&
+    git commit -m "stash1 changes" &&
+
+    git checkout -b stash2 master &&
+    echo stash2 change file11 >file11 &&
+    git add file11 &&
+    git commit -m "stash2 changes" &&
+
     git checkout master &&
     git submodule update -N &&
     echo master updated >file1 &&
@@ -193,7 +203,25 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' '
     git reset --hard
 '
 
+test_expect_failure 'mergetool ignores rerere in git-stash conflicts'  '
+    git checkout -b stash3 stash1 &&
+    git config rerere.enabled true &&
+    echo "Conflicting stash content" >file11 &&
+    git stash &&
+    test_must_fail git merge stash2 &&
+    echo resolved >file11 &&
+    git add file11 &&
+    git commit -mResolved-previous-conflict &&
+    test -e .git/MERGE_RR &&
+    test_must_fail git stash apply &&
+    test_must_fail test -e .git/MERGE_RR &&
+    test -n "$(git ls-files -u)" &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" != "No files need merging"
+'
+
 test_expect_success 'mergetool takes partial path' '
+    git reset --hard
     git config rerere.enabled false &&
     git checkout -b test12 branch1 &&
     git submodule update -N &&
-- 
1.7.11.1.213.gb567ea5.dirty

```

## Phil Hord, 2012-07-06 16:22

Subject: [PATCH 2/2] Clear rerere status during stash conflict
Message-ID: <1341591772-26251-3-git-send-email-hordp@cisco.com>
URL: https://gitlist.dev/e/1341591772-26251-3-git-send-email-hordp%40cisco.com
In-Reply-To: <1341591772-26251-1-git-send-email-hordp@cisco.com>

```
The presence of a GIT_DIR/MERGE_RR file indicates we
were resolving a merge which had rerere candidates for
recording.  But the file does not get deleted after
all resolutions are completed.  This is ok for most
cases because the file will get replaced when the
next merge happens.  But stash apply directly uses
a merge backend, which is not supported by rerere.
The prior rerere state is left behind (in MERGE_RR)
rather than being cleaned up or overwritten as it
would with a normal merge.

This then confuses mergetool who thinks a rerere
operation is in play when it is not.

When we encounter a conflicted stash,  ask rerere to
clean up with 'git rerere clear'.  This is safe to do
since we know that rerere is not taking part in this
conflict resolution, and any previous unresolved rerere
activity would have prevented us from attempting the
stash apply in the first place.

Change the test for this flaw to expect success.

Signed-off-by: Phil Hord <hordp@cisco.com>
Mentored-by: Junio C Hamano <gitster@pobox.com>
---
 git-stash.sh         | 1 +
 t/t7610-mergetool.sh | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/git-stash.sh b/git-stash.sh
index 4e2c7f8..5bd45ef 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -469,6 +469,7 @@ apply_stash () {
 	else
 		# Merge conflict; keep the exit status from merge-recursive
 		status=$?
+		git rerere clear
 		if test -n "$INDEX_OPTION"
 		then
 			gettextln "Index was not unstashed." >&2
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 2796c53..99e8c1d 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -203,7 +203,7 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' '
     git reset --hard
 '
 
-test_expect_failure 'mergetool ignores rerere in git-stash conflicts'  '
+test_expect_success 'mergetool ignores rerere in git-stash conflicts'  '
     git checkout -b stash3 stash1 &&
     git config rerere.enabled true &&
     echo "Conflicting stash content" >file11 &&
-- 
1.7.11.1.213.gb567ea5.dirty

```
