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

[PATCH] modify/delete conflict resolution overwrites untracked file

From
Clemens Buchacher <drizzd@aon.at>
Date
Dec 10, 2008, 20:12 UTC
Message-ID
<20081210201259.GA12928@localhost>

If a file was removed in HEAD, but modified in MERGE_HEAD, recursive merge will result in a "CONFLICT (delete/modify)". If the (now untracked) file already exists and was not added to the index, it is overwritten with the conflict resolution contents.

In similar situations (cf. test 2), the merge would abort with
"error: Untracked working tree 'file' would be overwritten by merge."
The same should happen in this case.
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
If it's a regression, it dates far back, since 1.5.0 fails as well.

I don't have time to look into this until Saturday. I won't complain if someone beats me to it. ;-)

Clemens
 t/t7607-merge-overwrite.sh |   87 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100755 t/t7607-merge-overwrite.sh
diff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh
new file mode 100755
index 0000000..513097c
--- /dev/null
+++ b/t/t7607-merge-overwrite.sh
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+test_description='git-merge
+
+Do not overwrite changes.'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	echo c0 > c0.c &&
+	git add c0.c &&
+	git commit -m c0 &&
+	git tag c0 &&
+	echo c1 > c1.c &&
+	git add c1.c &&
+	git commit -m c1 &&
+	git tag c1 &&
+	git reset --hard c0 &&
+	echo c2 > c2.c &&
+	git add c2.c &&
+	git commit -m c2 &&
+	git tag c2 &&
+	git reset --hard c1 &&
+	echo "c1 a" > c1.c &&
+	git add c1.c &&
+	git commit -m "c1 a" &&
+	git tag c1a &&
+	echo "VERY IMPORTANT CHANGES" > important
+'
+
+test_expect_success 'will not overwrite untracked file' '
+	git reset --hard c1 &&
+	cat important > c2.c &&
+	! git merge c2 &&
+	test_cmp important c2.c
+'
+
+test_expect_success 'will not overwrite new file' '
+	git reset --hard c1 &&
+	cat important > c2.c &&
+	git add c2.c &&
+	! git merge c2 &&
+	test_cmp important c2.c
+'
+
+test_expect_success 'will not overwrite staged changes' '
+	git reset --hard c1 &&
+	cat important > c2.c &&
+	git add c2.c &&
+	rm c2.c &&
+	! git merge c2 &&
+	git checkout c2.c &&
+	test_cmp important c2.c
+'
+
+test_expect_failure 'will not overwrite removed file' '
+	git reset --hard c1 &&
+	git rm c1.c &&
+	git commit -m "rm c1.c" &&
+	cat important > c1.c &&
+	! git merge c1a &&
+	test_cmp important c1.c
+'
+
+test_expect_success 'will not overwrite re-added file' '
+	git reset --hard c1 &&
+	git rm c1.c &&
+	git commit -m "rm c1.c" &&
+	cat important > c1.c &&
+	git add c1.c &&
+	! git merge c1a &&
+	test_cmp important c1.c
+'
+
+test_expect_success 'will not overwrite removed file with staged changes' '
+	git reset --hard c1 &&
+	git rm c1.c &&
+	git commit -m "rm c1.c" &&
+	cat important > c1.c &&
+	git add c1.c &&
+	rm c1.c &&
+	! git merge c1a &&
+	git checkout c1.c &&
+	test_cmp important c1.c
+'
+
+test_done
-- 
1.6.0
Next: Junio C Hamano
Message 1 of 24 in “modify/delete conflict resolution overwrites untracked file”
  1. modify/delete conflict resolution overwrites untracked fileClemens Buchacher, Dec 10, 2008
  2. Junio C HamanoDec 10, 2008
  3. Clemens BuchacherDec 10, 2008
  4. Junio C HamanoDec 10, 2008
  5. Clemens BuchacherDec 11, 2008
  6. Junio C HamanoDec 11, 2008
  7. Clemens BuchacherDec 15, 2008
  8. Junio C HamanoDec 15, 2008
  9. Junio C HamanoDec 15, 2008
  10. Johannes SchindelinDec 15, 2008
  11. Junio C HamanoDec 15, 2008
  12. Johannes SchindelinDec 15, 2008
  13. Clemens BuchacherDec 15, 2008
  14. Junio C HamanoDec 15, 2008
  15. Mike RalphsonDec 15, 2008
  16. Johannes SchindelinDec 15, 2008
  17. Mike RalphsonDec 15, 2008
  18. Junio C HamanoDec 15, 2008
  19. Clemens BuchacherDec 15, 2008
  20. Junio C HamanoDec 16, 2008
  21. Jakub NarebskiDec 16, 2008
  22. Clemens BuchacherDec 28, 2008
  23. Junio C HamanoDec 28, 2008
  24. Clemens BuchacherDec 28, 2008

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.