git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] stash: dont save during a conflicted merge

From
Dave Olszewski <cxreg@pobox.com>
Date
Mar 13, 2010, 03:40 UTC
Message-ID
<1268451633-30046-1-git-send-email-cxreg@pobox.com>

Similar to commit c8c562a, if a user is resolving conflicts, they may think it wise to stash their current work tree and git pull to see if there are additional changes on the remote.

The stash will fail to save if the index contains unmerged entries, but if the conflicts are resolved, the stash will succeed, and both MERGE_HEAD and MERGE_MSG will be removed. This is probably a mistake, and we should warn the user and refuse to stash.

Signed-off-by: Dave Olszewski <cxreg@pobox.com>
---
 git-stash.sh     |    5 +++++
 t/t3903-stash.sh |   19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index aa47e54..1a70f8d 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -172,6 +172,11 @@ save_stash () {
 	test -f "$GIT_DIR/logs/$ref_stash" ||
 		clear_stash || die "Cannot initialize stash"
 
+	if test -f "$GIT_DIR/MERGE_HEAD"
+	then
+		die "You have not concluded your merge. (MERGE_HEAD exists)";
+	fi
+
 	create_stash "$stash_msg"
 
 	# Make sure the reflog for stash is kept.
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 476e5ec..9915f4f 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -228,4 +228,23 @@ test_expect_success 'stash --invalid-option' '
 	test bar,bar2 = $(cat file),$(cat file2)
 '
 
+test_expect_success 'stash during merge' '
+	git branch other &&
+	git checkout master &&
+	echo conflict > conflict &&
+	git add conflict &&
+	git commit -m "conflict" &&
+	git checkout other &&
+	echo other content > conflict &&
+	git add conflict &&
+	git commit -m "other branch conflict" &&
+	git checkout master &&
+	test_must_fail git merge other &&
+	test_must_fail git stash &&
+	git add . &&
+	git status &&
+	test_must_fail git stash &&
+	git reset --hard
+'
+
 test_done
-- 
1.7.0.2.200.ga611.dirty
Next: Junio C Hamano
Message 1 of 3 in “stash: dont save during a conflicted merge”
  1. stash: dont save during a conflicted mergeDave Olszewski, Mar 13, 2010
  2. Junio C HamanoMar 15, 2010
  3. Dave OlszewskiMar 16, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.