git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>
Subject: [PATCH 14/30] directory rename detection: tests for handling overwriting dirty files
Date: Fri, 10 Nov 2017 11:05:34 -0800	[thread overview]
Message-ID: <20171110190550.27059-15-newren@gmail.com> (raw)
In-Reply-To: <20171110190550.27059-1-newren@gmail.com>

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t6043-merge-rename-directories.sh | 401 ++++++++++++++++++++++++++++++++++++
 1 file changed, 401 insertions(+)

diff --git a/t/t6043-merge-rename-directories.sh b/t/t6043-merge-rename-directories.sh
index 7af8962512..4066b08767 100755
--- a/t/t6043-merge-rename-directories.sh
+++ b/t/t6043-merge-rename-directories.sh
@@ -2873,4 +2873,405 @@ test_expect_failure '10e-check: Does git complain about untracked file that is n
 	test "random" = "$(cat z/c)"
 '
 
+###########################################################################
+# SECTION 11: Handling dirty (not up-to-date) files
+#
+# unpack_trees(), upon which the recursive merge algorithm is based, aborts
+# the operation if untracked or dirty files would be deleted or overwritten
+# by the merge.  Unfortunately, unpack_trees() does not understand renames,
+# and if it doesn't abort, then it muddies up the working directory before
+# we even get to the point of detecting renames, so we need some special
+# handling.  This was true even of normal renames, but there are additional
+# codepaths that need special handling with directory renames.  Add
+# testcases for both renamed-by-directory-rename-detection and standard
+# rename cases.
+###########################################################################
+
+# Testcase 11a, Avoid losing dirty contents with simple rename
+#   Commit A: z/{a,b_v1},
+#   Commit B: z/{a,c_v1}, and z/c_v1 has uncommitted mods
+#   Commit C: z/{a,b_v2}
+#   Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
+#             z/a, staged version of z/c has sha1sum matching C:z/b_v2,
+#             z/c~HEAD with contents of C:z/b_v2,
+#             z/c with uncommitted mods on top of B:z/c_v1
+
+test_expect_success '11a-setup: Avoid losing dirty contents with simple rename' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	mkdir z &&
+	echo a >z/a &&
+	test_seq 1 10 >z/b &&
+	git add z &&
+	test_tick &&
+	git commit -m "A" &&
+
+	git branch A &&
+	git branch B &&
+	git branch C &&
+
+	git checkout B &&
+	git mv z/b z/c &&
+	test_tick &&
+	git commit -m "B" &&
+
+	git checkout C &&
+	echo 11 >>z/b &&
+	git add z/b &&
+	test_tick &&
+	git commit -m "C"
+'
+
+test_expect_failure '11a-check: Avoid losing dirty contents with simple rename' '
+	git checkout B^0 &&
+	echo stuff >>z/c &&
+
+	test_must_fail git merge -s recursive C^0 >out 2>err &&
+	test_i18ngrep "Refusing to lose dirty file at z/c" out &&
+
+	test_seq 1 10 >expected &&
+	echo stuff >>expected &&
+
+	test 2 -eq $(git ls-files -s | wc -l) &&
+	test 1 -eq $(git ls-files -u | wc -l) &&
+	test 4 -eq $(git ls-files -o | wc -l) &&
+
+	test $(git rev-parse :0:z/a) = $(git rev-parse A:z/a) &&
+	test $(git rev-parse :2:z/c) = $(git rev-parse C:z/b) &&
+
+	test "$(git hash-object z/c~HEAD)" = $(git rev-parse C:z/b) &&
+	test_cmp expected z/c
+'
+
+# Testcase 11b, Avoid losing dirty file involved in directory rename
+#   Commit A: z/a,         x/{b,c_v1}
+#   Commit B: z/{a,c_v1},  x/b,       and z/c_v1 has uncommitted mods
+#   Commit C: y/a,         x/{b,c_v2}
+#   Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommited mods untracked,
+#             ERROR_MSG(Refusing to lose dirty file at z/c)
+
+
+test_expect_success '11b-setup: Avoid losing dirty file involved in directory rename' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	mkdir z x &&
+	echo a >z/a &&
+	echo b >x/b &&
+	test_seq 1 10 >x/c &&
+	git add z x &&
+	test_tick &&
+	git commit -m "A" &&
+
+	git branch A &&
+	git branch B &&
+	git branch C &&
+
+	git checkout B &&
+	git mv x/c z/c &&
+	test_tick &&
+	git commit -m "B" &&
+
+	git checkout C &&
+	git mv z y &&
+	echo 11 >>x/c &&
+	git add x/c &&
+	test_tick &&
+	git commit -m "C"
+'
+
+test_expect_failure '11b-check: Avoid losing dirty file involved in directory rename' '
+	git checkout B^0 &&
+	echo stuff >>z/c &&
+
+	git merge -s recursive C^0 >out 2>err &&
+	test_i18ngrep "Refusing to lose dirty file at z/c" out &&
+
+	grep -q stuff */* &&
+	test_seq 1 10 >expected &&
+	echo stuff >>expected &&
+
+	test 3 -eq $(git ls-files -s | wc -l) &&
+	test 0 -eq $(git ls-files -u | wc -l) &&
+	test 0 -eq $(git ls-files -m | wc -l) &&
+	test 4 -eq $(git ls-files -o | wc -l) &&
+
+	test $(git rev-parse :0:x/b) = $(git rev-parse A:x/b) &&
+	test $(git rev-parse :0:y/a) = $(git rev-parse A:z/a) &&
+	test $(git rev-parse :0:y/c) = $(git rev-parse C:x/c) &&
+
+	test "$(git hash-object y/c)" = $(git rev-parse C:x/c) &&
+	test_cmp expected z/c
+'
+
+# Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
+#   Commit A: y/a,         x/{b,c_v1}
+#   Commit B: y/{a,c_v1},  x/b,       and y/c_v1 has uncommitted mods
+#   Commit C: y/{a,c/d},   x/{b,c_v2}
+#   Expected: Abort_msg("following files would be overwritten by merge") +
+#             y/c left untouched (still has uncommitted mods)
+
+test_expect_success '11c-setup: Avoid losing not-uptodate with rename + D/F conflict' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	mkdir y x &&
+	echo a >y/a &&
+	echo b >x/b &&
+	test_seq 1 10 >x/c &&
+	git add y x &&
+	test_tick &&
+	git commit -m "A" &&
+
+	git branch A &&
+	git branch B &&
+	git branch C &&
+
+	git checkout B &&
+	git mv x/c y/c &&
+	test_tick &&
+	git commit -m "B" &&
+
+	git checkout C &&
+	mkdir y/c &&
+	echo d >y/c/d &&
+	echo 11 >>x/c &&
+	git add x/c y/c/d &&
+	test_tick &&
+	git commit -m "C"
+'
+
+test_expect_success '11c-check: Avoid losing not-uptodate with rename + D/F conflict' '
+	git checkout B^0 &&
+	echo stuff >>y/c &&
+
+	test_must_fail git merge -s recursive C^0 >out 2>err &&
+	test_i18ngrep "following files would be overwritten by merge" err &&
+
+	grep -q stuff */* &&
+	test_seq 1 10 >expected &&
+	echo stuff >>expected &&
+
+	test 3 -eq $(git ls-files -s | wc -l) &&
+	test 0 -eq $(git ls-files -u | wc -l) &&
+	test 1 -eq $(git ls-files -m | wc -l) &&
+	test 3 -eq $(git ls-files -o | wc -l) &&
+
+	test $(git rev-parse HEAD) = $(git rev-parse B) &&
+	test_cmp expected y/c
+'
+
+# Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
+#   Commit A: z/a,         x/{b,c_v1}
+#   Commit B: z/{a,c_v1},  x/b,       and z/c_v1 has uncommitted mods
+#   Commit C: y/{a,c/d},   x/{b,c_v2}
+#   Expected: D/F: y/c_v2 vs y/c/d) +
+#             Warning_Msg("Refusing to lose dirty file at z/c) +
+#             y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommited mods
+
+test_expect_success '11d-setup: Avoid losing not-uptodate with rename + D/F conflict' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	mkdir z x &&
+	echo a >z/a &&
+	echo b >x/b &&
+	test_seq 1 10 >x/c &&
+	git add z x &&
+	test_tick &&
+	git commit -m "A" &&
+
+	git branch A &&
+	git branch B &&
+	git branch C &&
+
+	git checkout B &&
+	git mv x/c z/c &&
+	test_tick &&
+	git commit -m "B" &&
+
+	git checkout C &&
+	git mv z y &&
+	mkdir y/c &&
+	echo d >y/c/d &&
+	echo 11 >>x/c &&
+	git add x/c y/c/d &&
+	test_tick &&
+	git commit -m "C"
+'
+
+test_expect_failure '11d-check: Avoid losing not-uptodate with rename + D/F conflict' '
+	git checkout B^0 &&
+	echo stuff >>z/c &&
+
+	test_must_fail git merge -s recursive C^0 >out 2>err &&
+	test_i18ngrep "Refusing to lose dirty file at z/c" out &&
+
+	grep -q stuff */* &&
+	test_seq 1 10 >expected &&
+	echo stuff >>expected &&
+
+	test 4 -eq $(git ls-files -s | wc -l) &&
+	test 1 -eq $(git ls-files -u | wc -l) &&
+	test 5 -eq $(git ls-files -o | wc -l) &&
+
+	test $(git rev-parse :0:x/b) = $(git rev-parse A:x/b) &&
+	test $(git rev-parse :0:y/a) = $(git rev-parse A:z/a) &&
+	test $(git rev-parse :0:y/c/d) = $(git rev-parse C:y/c/d) &&
+	test $(git rev-parse :3:y/c) = $(git rev-parse C:x/c) &&
+
+	test "$(git hash-object y/c~HEAD)" = $(git rev-parse C:x/c) &&
+	test_cmp expected z/c
+'
+
+# Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
+#   Commit A: z/{a,b},      x/{c_1,d}
+#   Commit B: y/{a,b,c_2},  x/d, w/c_1, and y/c_2 has uncommitted mods
+#   Commit C: z/{a,b,c_1},  x/d
+#   Expected: Failed Merge; y/{a,b} + x/d +
+#             CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
+#             ERROR_MSG(Refusing to lose dirty file at y/c)
+#             y/c~C^0 has A:x/c_1 contents
+#             y/c~HEAD has B:y/c_2 contents
+#             y/c has dirty file from before merge
+
+test_expect_success '11e-setup: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	mkdir z x &&
+	echo a >z/a &&
+	echo b >z/b &&
+	echo c >x/c &&
+	echo d >x/d &&
+	git add z x &&
+	test_tick &&
+	git commit -m "A" &&
+
+	git branch A &&
+	git branch B &&
+	git branch C &&
+
+	git checkout B &&
+	git mv z/ y/ &&
+	echo different >y/c &&
+	mkdir w &&
+	git mv x/c w/ &&
+	git add y/c &&
+	test_tick &&
+	git commit -m "B" &&
+
+	git checkout C &&
+	git mv x/c z/ &&
+	test_tick &&
+	git commit -m "C"
+'
+
+test_expect_failure '11e-check: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
+	git checkout B^0 &&
+	echo mods >>y/c &&
+
+	test_must_fail git merge -s recursive C^0 >out 2>err &&
+	test_i18ngrep "CONFLICT (rename/rename)" out &&
+	test_i18ngrep "Refusing to lose dirty file at y/c" out &&
+
+	test 7 -eq $(git ls-files -s | wc -l) &&
+	test 4 -eq $(git ls-files -u | wc -l) &&
+	test 4 -eq $(git ls-files -o | wc -l) &&
+
+	echo different >expected &&
+	echo mods >>expected &&
+
+	test $(git rev-parse :0:y/a) = $(git rev-parse A:z/a) &&
+	test $(git rev-parse :0:y/b) = $(git rev-parse A:z/b) &&
+	test $(git rev-parse :0:x/d) = $(git rev-parse A:x/d) &&
+
+	test $(git rev-parse :1:x/c) = $(git rev-parse A:x/c) &&
+	test $(git rev-parse :2:w/c) = $(git rev-parse A:x/c) &&
+	test $(git rev-parse :2:y/c) = $(git rev-parse B:y/c) &&
+	test $(git rev-parse :3:y/c) = $(git rev-parse A:x/c) &&
+
+	test "$(git hash-object y/c~C^0)" = $(git rev-parse A:x/c) &&
+	test "$(git hash-object y/c~HEAD)" = $(git rev-parse B:y/c) &&
+	test_cmp expected y/c
+'
+
+# Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
+#   Commit A: z/{a,b},        x/{c_1,d_2}
+#   Commit B: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
+#   Commit C: z/{a,b,wham_2}, x/c_1
+#   Expected: Failed Merge; y/{a,b} + untracked y/{wham~C^0,wham~C^HEAD} +
+#             y/wham with dirty changes from before merge +
+#             CONFLICT(rename/rename) x/c vs x/d -> y/wham
+#             ERROR_MSG(Refusing to lose dirty file at y/wham)
+
+test_expect_success '11f-setup: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
+	git rm -rf . &&
+	git clean -fdqx &&
+	rm -rf .git &&
+	git init &&
+
+	mkdir z x &&
+	echo a >z/a &&
+	echo b >z/b &&
+	test_seq 1 10 >x/c &&
+	echo d >x/d &&
+	git add z x &&
+	test_tick &&
+	git commit -m "A" &&
+
+	git branch A &&
+	git branch B &&
+	git branch C &&
+
+	git checkout B &&
+	git mv z/ y/ &&
+	git mv x/c y/wham &&
+	test_tick &&
+	git commit -m "B" &&
+
+	git checkout C &&
+	git mv x/d z/wham &&
+	test_tick &&
+	git commit -m "C"
+'
+
+test_expect_failure '11f-check: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
+	git checkout B^0 &&
+	echo important >>y/wham &&
+
+	test_must_fail git merge -s recursive C^0 >out 2>err &&
+	test_i18ngrep "CONFLICT (rename/rename)" out &&
+	test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
+
+	test 4 -eq $(git ls-files -s | wc -l) &&
+	test 2 -eq $(git ls-files -u | wc -l) &&
+	test 4 -eq $(git ls-files -o | wc -l) &&
+
+	test_seq 1 10 >expected &&
+	echo important >>expected &&
+
+	test $(git rev-parse :0:y/a) = $(git rev-parse A:z/a) &&
+	test $(git rev-parse :0:y/b) = $(git rev-parse A:z/b) &&
+
+	test_must_fail git rev-parse :1:y/wham &&
+	test $(git rev-parse :2:y/wham) = $(git rev-parse A:x/c) &&
+	test $(git rev-parse :3:y/wham) = $(git rev-parse A:x/d) &&
+
+	test_cmp expected y/wham &&
+	test $(git hash-object y/wham~C^0)  = $(git rev-parse A:x/d) &&
+	test $(git hash-object y/wham~HEAD) = $(git rev-parse A:x/c)
+'
+
 test_done
-- 
2.15.0.5.g9567be9905


  parent reply	other threads:[~2017-11-10 19:06 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 19:05 [PATCH 00/30] Add directory rename detection to git Elijah Newren
2017-11-10 19:05 ` [PATCH 01/30] Tighten and correct a few testcases for merging and cherry-picking Elijah Newren
2017-11-13 19:32   ` Stefan Beller
2017-11-10 19:05 ` [PATCH 02/30] merge-recursive: Fix logic ordering issue Elijah Newren
2017-11-13 19:48   ` Stefan Beller
2017-11-13 22:04     ` Elijah Newren
2017-11-13 22:12       ` Stefan Beller
2017-11-13 23:39         ` Elijah Newren
2017-11-13 23:46           ` Stefan Beller
2017-11-10 19:05 ` [PATCH 03/30] merge-recursive: Add explanation for src_entry and dst_entry Elijah Newren
2017-11-13 21:06   ` Stefan Beller
2017-11-13 22:57     ` Elijah Newren
2017-11-13 23:11       ` Stefan Beller
2017-11-14  1:26   ` Junio C Hamano
2017-11-10 19:05 ` [PATCH 04/30] directory rename detection: basic testcases Elijah Newren
2017-11-13 22:04   ` Stefan Beller
2017-11-14  0:57     ` Elijah Newren
2017-11-14  1:21       ` Stefan Beller
2017-11-14  1:40         ` Elijah Newren
2017-11-14  2:03     ` Junio C Hamano
2017-11-10 19:05 ` [PATCH 05/30] directory rename detection: directory splitting testcases Elijah Newren
2017-11-13 23:20   ` Stefan Beller
2017-11-10 19:05 ` [PATCH 06/30] directory rename detection: testcases to avoid taking detection too far Elijah Newren
2017-11-13 23:25   ` Stefan Beller
2017-11-14  1:02     ` Elijah Newren
2017-11-10 19:05 ` [PATCH 07/30] directory rename detection: partially renamed directory testcase/discussion Elijah Newren
2017-11-14  0:07   ` Stefan Beller
2017-11-10 19:05 ` [PATCH 08/30] directory rename detection: files/directories in the way of some renames Elijah Newren
2017-11-14  0:15   ` Stefan Beller
2017-11-14  1:19     ` Elijah Newren
2017-11-10 19:05 ` [PATCH 09/30] directory rename detection: testcases checking which side did the rename Elijah Newren
2017-11-14  0:25   ` Stefan Beller
2017-11-14  1:30     ` Elijah Newren
2017-11-10 19:05 ` [PATCH 10/30] directory rename detection: more involved edge/corner testcases Elijah Newren
2017-11-14  0:42   ` Stefan Beller
2017-11-14 21:11     ` Elijah Newren
2017-11-14 22:47       ` Stefan Beller
2017-11-10 19:05 ` [PATCH 11/30] directory rename detection: testcases exploring possibly suboptimal merges Elijah Newren
2017-11-14 20:33   ` Stefan Beller
2017-11-14 21:42     ` Elijah Newren
2017-11-10 19:05 ` [PATCH 12/30] directory rename detection: miscellaneous testcases to complete coverage Elijah Newren
2017-11-15 20:03   ` Stefan Beller
2017-11-16 21:17     ` Elijah Newren
2017-11-10 19:05 ` [PATCH 13/30] directory rename detection: tests for handling overwriting untracked files Elijah Newren
2017-11-10 19:05 ` Elijah Newren [this message]
2017-11-10 19:05 ` [PATCH 15/30] merge-recursive: Move the get_renames() function Elijah Newren
2017-11-14  4:46   ` Junio C Hamano
2017-11-14 17:41     ` Elijah Newren
2017-11-15  1:20       ` Junio C Hamano
2017-11-10 19:05 ` [PATCH 16/30] merge-recursive: Introduce new functions to handle rename logic Elijah Newren
2017-11-14  4:56   ` Junio C Hamano
2017-11-14  5:14     ` Junio C Hamano
2017-11-14 18:24       ` Elijah Newren
2017-11-10 19:05 ` [PATCH 17/30] merge-recursive: Fix leaks of allocated renames and diff_filepairs Elijah Newren
2017-11-14  4:58   ` Junio C Hamano
2017-11-10 19:05 ` [PATCH 18/30] merge-recursive: Make !o->detect_rename codepath more obvious Elijah Newren
2017-11-10 19:05 ` [PATCH 19/30] merge-recursive: Split out code for determining diff_filepairs Elijah Newren
2017-11-14  5:20   ` Junio C Hamano
2017-11-10 19:05 ` [PATCH 20/30] merge-recursive: Add a new hashmap for storing directory renames Elijah Newren
2017-11-10 19:05 ` [PATCH 21/30] merge-recursive: Add get_directory_renames() Elijah Newren
2017-11-14  5:30   ` Junio C Hamano
2017-11-14 18:38     ` Elijah Newren
2017-11-10 19:05 ` [PATCH 22/30] merge-recursive: Check for directory level conflicts Elijah Newren
2017-11-10 19:05 ` [PATCH 23/30] merge-recursive: Add a new hashmap for storing file collisions Elijah Newren
2017-11-10 19:05 ` [PATCH 24/30] merge-recursive: Add computation of collisions due to dir rename & merging Elijah Newren
2018-06-10 10:56   ` René Scharfe
2018-06-10 11:03     ` René Scharfe
2018-06-10 20:44     ` Jeff King
2018-06-11 15:03     ` Elijah Newren
2018-06-14 17:36     ` Junio C Hamano
2017-11-10 19:05 ` [PATCH 25/30] merge-recursive: Check for file level conflicts then get new name Elijah Newren
2017-11-10 19:05 ` [PATCH 26/30] merge-recursive: When comparing files, don't include trees Elijah Newren
2017-11-10 19:05 ` [PATCH 27/30] merge-recursive: Apply necessary modifications for directory renames Elijah Newren
2017-11-15 20:23   ` Stefan Beller
2017-11-16  3:54     ` Elijah Newren
2017-11-10 19:05 ` [PATCH 28/30] merge-recursive: Avoid clobbering untracked files with " Elijah Newren
2017-11-10 19:05 ` [RFC PATCH 29/30] merge-recursive: Fix overwriting dirty files involved in renames Elijah Newren
2017-11-10 19:05 ` [PATCH 30/30] merge-recursive: Fix remaining directory rename + dirty overwrite cases Elijah Newren
2017-11-10 22:27 ` [PATCH 00/30] Add directory rename detection to git Philip Oakley
2017-11-10 23:26   ` Elijah Newren
2017-11-13 15:04     ` Philip Oakley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171110190550.27059-15-newren@gmail.com \
    --to=newren@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).