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

[PATCH v2 2/5] t3034: add rename threshold tests

From
FAFelipe Gonçalves Assis <felipeg.assis@gmail.com>
Date
Feb 21, 2016, 22:59 UTC
Message-ID
<1456095545-20201-3-git-send-email-felipegassis@gmail.com>
In-Reply-To
<1456095545-20201-1-git-send-email-felipegassis@gmail.com>

10ae752 (merge-recursive: option to specify rename threshold, 2010-09-27) introduced this feature but did not include any tests.

The tests use the new option --find-renames, which replaces the then introduced and now deprecated option --rename-threshold.

Also update name and description of t3032 for consistency: "merge-recursive options" -> "merge-recursive space options"

Signed-off-by: Felipe Gonçalves Assis <felipegassis@gmail.com>
---
Now this already introduces the final names and descriptions for the tests.

The test for threshold truncation was kept for now. Please confirm whether it is desirable.

New tests were added at the end to check that invalid arguments to find-renames= such as negative and non-numbers error out.

 ...s.sh => t3032-merge-recursive-space-options.sh} |   2 +-
 t/t3034-merge-recursive-rename-options.sh          | 159 +++++++++++++++++++++
 2 files changed, 160 insertions(+), 1 deletion(-)
 rename t/{t3032-merge-recursive-options.sh => t3032-merge-recursive-space-options.sh} (99%)
 create mode 100755 t/t3034-merge-recursive-rename-options.sh
diff --git a/t/t3032-merge-recursive-options.sh b/t/t3032-merge-recursive-space-options.sh
similarity index 99%
rename from t/t3032-merge-recursive-options.sh
rename to t/t3032-merge-recursive-space-options.sh
index 4029c9c..b56180e 100755
--- a/t/t3032-merge-recursive-options.sh
+++ b/t/t3032-merge-recursive-space-options.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-test_description='merge-recursive options
+test_description='merge-recursive space options
 
 * [master] Clarify
  ! [remote] Remove cruft
diff --git a/t/t3034-merge-recursive-rename-options.sh b/t/t3034-merge-recursive-rename-options.sh
new file mode 100755
index 0000000..7ae7f83
--- /dev/null
+++ b/t/t3034-merge-recursive-rename-options.sh
@@ -0,0 +1,159 @@
+#!/bin/sh
+
+test_description='merge-recursive rename options
+
+Test rename detection by examining rename/delete conflicts.
+
+Similarity index:
+R100 a-old a-new
+R075 b-old b-new
+R050 c-old c-new
+R025 d-old d-new
+'
+
+. ./test-lib.sh
+
+get_expected_stages () {
+	git checkout rename -- $1-new &&
+	git ls-files --stage $1-new >expected-stages-undetected-$1 &&
+	sed "s/ 0	/ 2	/" <expected-stages-undetected-$1 \
+		>expected-stages-detected-$1 &&
+	git read-tree -u --reset HEAD
+}
+
+rename_detected () {
+	git ls-files --stage $1-old $1-new >stages-actual-$1 &&
+	test_cmp expected-stages-detected-$1 stages-actual-$1
+}
+
+rename_undetected () {
+	git ls-files --stage $1-old $1-new >stages-actual-$1 &&
+	test_cmp expected-stages-undetected-$1 stages-actual-$1
+}
+
+check_common () {
+	git ls-files --stage >stages-actual &&
+	test_line_count = 4 stages-actual
+}
+
+check_find_renames_25 () {
+	check_common &&
+	rename_detected a &&
+	rename_detected b &&
+	rename_detected c &&
+	rename_detected d
+}
+
+check_find_renames_50 () {
+	check_common &&
+	rename_detected a &&
+	rename_detected b &&
+	rename_detected c &&
+	rename_undetected d
+}
+
+check_find_renames_75 () {
+	check_common &&
+	rename_detected a &&
+	rename_detected b &&
+	rename_undetected c &&
+	rename_undetected d
+}
+
+check_find_renames_100 () {
+	check_common &&
+	rename_detected a &&
+	rename_undetected b &&
+	rename_undetected c &&
+	rename_undetected d
+}
+
+test_expect_success setup '
+	cat <<-\EOF >a-old &&
+	aa1
+	aa2
+	aa3
+	aa4
+	EOF
+	sed s/aa/bb/ <a-old >b-old &&
+	sed s/aa/cc/ <a-old >c-old &&
+	sed s/aa/dd/ <a-old >d-old &&
+	git add [a-d]-old &&
+	git commit -m base &&
+	git rm [a-d]-old &&
+	git commit -m delete &&
+	git checkout -b rename HEAD^ &&
+	cp a-old a-new &&
+	sed 1,1s/./x/ <b-old >b-new &&
+	sed 1,2s/./x/ <c-old >c-new &&
+	sed 1,3s/./x/ <d-old >d-new &&
+	git add [a-d]-new &&
+	git rm [a-d]-old &&
+	git commit -m rename &&
+	get_expected_stages a &&
+	get_expected_stages b &&
+	get_expected_stages c &&
+	get_expected_stages d
+'
+
+test_expect_success 'default similarity threshold is 50%' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive HEAD^ -- HEAD master &&
+	check_find_renames_50
+'
+
+test_expect_success 'low rename threshold' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive --find-renames=25 HEAD^ -- HEAD master &&
+	check_find_renames_25
+'
+
+test_expect_success 'high rename threshold' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive --find-renames=75 HEAD^ -- HEAD master &&
+	check_find_renames_75
+'
+
+test_expect_success 'exact renames only' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive --find-renames=100% HEAD^ -- HEAD master &&
+	check_find_renames_100
+'
+
+test_expect_success 'rename threshold is truncated' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive --find-renames=200% HEAD^ -- HEAD master &&
+	check_find_renames_100
+'
+
+test_expect_success 'last wins in --find-renames=<m> --find-renames=<n>' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive --find-renames=25 --find-renames=75 HEAD^ -- HEAD master &&
+	check_find_renames_75
+'
+
+test_expect_success 'assumption for further tests: trivial merge succeeds' '
+	git read-tree --reset -u HEAD &&
+	git merge-recursive HEAD -- HEAD HEAD &&
+	git diff --quiet --cached &&
+	git merge-recursive --find-renames=25 HEAD -- HEAD HEAD &&
+	git diff --quiet --cached &&
+	git merge-recursive --find-renames=75 HEAD -- HEAD HEAD &&
+	git diff --quiet --cached &&
+	git merge-recursive --find-renames=100% HEAD -- HEAD HEAD &&
+	git diff --quiet --cached
+'
+
+test_expect_success '--find-renames rejects negative argument' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive --find-renames=-25 HEAD -- HEAD HEAD &&
+	git diff --quiet --cached
+'
+
+test_expect_success '--find-renames rejects non-numbers' '
+	git read-tree --reset -u HEAD &&
+	test_must_fail git merge-recursive --find-renames=0xf HEAD -- HEAD HEAD &&
+	git diff --quiet --cached
+'
+
+test_done
-- 
2.7.1.492.gd821b20
Previous: Felipe Gonçalves AssisNext: Junio C Hamano
Message 3 of 11 in “Tests and fixes for merge-recursive rename options”
  1. 0/5 Tests and fixes for merge-recursive rename optionsFelipe Gonçalves Assis, Feb 21, 2016
  2. 1/5 merge-strategies.txt: fix typoFelipe Gonçalves Assis, Feb 21, 2016
  3. 2/5 t3034: add rename threshold testsFelipe Gonçalves Assis, Feb 21, 2016
  4. Junio C HamanoFeb 22, 2016
  5. 3/5 t3034: test option to disable renamesFelipe Gonçalves Assis, Feb 21, 2016
  6. 4/5 t3034: test deprecated interfaceFelipe Gonçalves Assis, Feb 21, 2016
  7. 5/5 merge-recursive: find-renames resets thresholdFelipe Gonçalves Assis, Feb 21, 2016
  8. Junio C HamanoFeb 22, 2016
  9. Felipe Gonçalves AssisFeb 22, 2016
  10. Junio C HamanoFeb 22, 2016
  11. Felipe Gonçalves AssisFeb 22, 2016

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.