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

[PATCH 1/5 v2] t7607: use test-lib functions and check MERGE_HEAD

From
Clemens Buchacher <drizzd@aon.at>
Date
Oct 10, 2010, 08:35 UTC
Message-ID
<20101010083543.GA12186@localhost>
In-Reply-To
<20101010063527.GC23100@burratino>

Use the test_commit and test_path_is_missing functions from the test library.

Also make sure that a merge which fails due to pre-merge checks aborts properly and does not leave MERGE_HEAD behind.

The "will not overwrite removed file" test is an exception to this. It notices the untracked file at a stage where the merge is already well under way. Therefore we cannot abort the merge without major restructuring. See the following thread for more details.

http://mid.gmane.org/7vskopwxej.fsf@gitster.siamese.dyndns.org
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
On Sun, Oct 10, 2010 at 01:35:27AM -0500, Jonathan Nieder wrote:
> 
> The main change (checking that MERGE_HEAD is not present
> for a merge that fails due to pre-merge checks) seems good.
Thanks. This new version incorporates all of your suggestions.
Clemens
 t/t7607-merge-overwrite.sh |   38 +++++++++++++++-----------------------
 1 files changed, 15 insertions(+), 23 deletions(-)
diff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh
index d82349a..b8fab54 100755
--- a/t/t7607-merge-overwrite.sh
+++ b/t/t7607-merge-overwrite.sh
@@ -7,48 +7,38 @@ 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 &&
+	test_commit c0 c0.c &&
+	test_commit c1 c1.c &&
+	test_commit c1a c1.c "c1 a" &&
 	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 &&
+	test_commit c2 c2.c &&
 	echo "VERY IMPORTANT CHANGES" > important
 '
 
 test_expect_success 'will not overwrite untracked file' '
 	git reset --hard c1 &&
-	cat important > c2.c &&
+	cp important c2.c &&
 	test_must_fail git merge c2 &&
+	test_path_is_missing .git/MERGE_HEAD &&
 	test_cmp important c2.c
 '
 
 test_expect_success 'will not overwrite new file' '
 	git reset --hard c1 &&
-	cat important > c2.c &&
+	cp important c2.c &&
 	git add c2.c &&
 	test_must_fail git merge c2 &&
+	test_path_is_missing .git/MERGE_HEAD &&
 	test_cmp important c2.c
 '
 
 test_expect_success 'will not overwrite staged changes' '
 	git reset --hard c1 &&
-	cat important > c2.c &&
+	cp important c2.c &&
 	git add c2.c &&
 	rm c2.c &&
 	test_must_fail git merge c2 &&
+	test_path_is_missing .git/MERGE_HEAD &&
 	git checkout c2.c &&
 	test_cmp important c2.c
 '
@@ -57,7 +47,7 @@ test_expect_success 'will not overwrite removed file' '
 	git reset --hard c1 &&
 	git rm c1.c &&
 	git commit -m "rm c1.c" &&
-	cat important > c1.c &&
+	cp important c1.c &&
 	test_must_fail git merge c1a &&
 	test_cmp important c1.c
 '
@@ -66,9 +56,10 @@ 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 &&
+	cp important c1.c &&
 	git add c1.c &&
 	test_must_fail git merge c1a &&
+	test_path_is_missing .git/MERGE_HEAD &&
 	test_cmp important c1.c
 '
 
@@ -76,10 +67,11 @@ 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 &&
+	cp important c1.c &&
 	git add c1.c &&
 	rm c1.c &&
 	test_must_fail git merge c1a &&
+	test_path_is_missing .git/MERGE_HEAD &&
 	git checkout c1.c &&
 	test_cmp important c1.c
 '
-- 
1.7.1.571.gba4d01
Previous: Jonathan NiederNext: Junio C Hamano
Message 16 of 39 in “git merge, .gitignore, and silently overwriting untracked files”
  1. Joshua JensenAug 17, 2010
  2. Junio C HamanoAug 17, 2010
  3. optionally disable overwriting of ignored filesClemens Buchacher, Aug 18, 2010
  4. Jakub NarebskiAug 19, 2010
  5. Clemens BuchacherAug 20, 2010
  6. Joshua JensenAug 20, 2010
  7. Junio C HamanoAug 20, 2010
  8. Clemens BuchacherAug 21, 2010
  9. Junio C HamanoAug 22, 2010
  10. Clemens BuchacherAug 22, 2010
  11. Kevin BallardOct 9, 2010
  12. Clemens BuchacherAug 21, 2010
  13. 0/5 do not overwrite untracked files in leading pathClemens Buchacher, Oct 9, 2010
  14. 1/5 t7607: use test_commit and test_must_failClemens Buchacher, Oct 9, 2010
  15. Jonathan NiederOct 10, 2010
  16. 1/5 t7607: use test-lib functions and check MERGE_HEADClemens Buchacher, Oct 10, 2010
  17. Junio C HamanoOct 13, 2010
  18. Junio C HamanoOct 13, 2010
  19. 2/5 t7607: add leading-path testsClemens Buchacher, Oct 9, 2010
  20. Johannes SixtOct 9, 2010
  21. 2/5 t7607: add leading-path testsClemens Buchacher, Oct 10, 2010
  22. 3/5 add function check_ok_to_remove()Clemens Buchacher, Oct 9, 2010
  23. Junio C HamanoOct 13, 2010
  24. 4/5 lstat_cache: optionally return match_lenClemens Buchacher, Oct 9, 2010
  25. 5/5 do not overwrite files in leading pathClemens Buchacher, Oct 9, 2010
  26. Junio C HamanoOct 13, 2010
  27. Clemens BuchacherOct 13, 2010
  28. Clemens BuchacherOct 15, 2010
  29. Junio C HamanoOct 15, 2010
  30. Junio C HamanoAug 20, 2010
  31. optionally disable overwriting of ignored filesClemens Buchacher, Aug 21, 2010
  32. Matthieu MoyAug 23, 2010
  33. Heiko VoigtAug 31, 2010
  34. Matthieu MoyAug 23, 2010
  35. Holger HellmuthAug 23, 2010
  36. Clemens BuchacherAug 23, 2010
  37. Junio C HamanoAug 23, 2010
  38. Clemens BuchacherAug 24, 2010
  39. Junio C HamanoAug 24, 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.