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

[PATCH v3 1/2] Add test to describe expectation of blame --reverse with branched history

From
Max Kirillov <max@max630.net>
Date
Oct 22, 2015, 04:07 UTC
Message-ID
<1445486859-21906-2-git-send-email-max@max630.net>
In-Reply-To
<1445486859-21906-1-git-send-email-max@max630.net>

If history contains merges from feature branches, `blame --reverse` reports not the commit when the line was actually edited, but head of the last merged branch which was created before the edit.

As a workaround, `blame --reverse --first-parent` could be used to find the merge of branch containing the edit, but it was disabled in 95a4fb0eac, because incorrectly specified range could produce in unexpected and meaningless result.

Add tests which describe ideal functionality with and without `--first-parent`.

Signed-off-by: Max Kirillov <max@max630.net>
---
 t/t8009-blame-reverse.sh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100755 t/t8009-blame-reverse.sh
diff --git a/t/t8009-blame-reverse.sh b/t/t8009-blame-reverse.sh
new file mode 100755
index 0000000..9f40613
--- /dev/null
+++ b/t/t8009-blame-reverse.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+test_description='git blame reverse'
+. ./test-lib.sh
+
+test_expect_success setup '
+	test_commit A0 file.t line0 &&
+	test_commit A1 &&
+	git reset --hard A0 &&
+	test_commit B1 &&
+	test_commit B2 file.t line0changed &&
+	git reset --hard A1 &&
+	test_merge A2 B2 &&
+	git reset --hard A1 &&
+	test_commit C1 &&
+	git reset --hard A2 &&
+	test_merge A3 C1
+	'
+
+test_expect_failure 'blame --reverse finds B1, not C1' '
+	git blame --porcelain --reverse A0..A3 -- file.t >actual_full &&
+	head -1 <actual_full | sed -e "sX .*XX" >actual &&
+	git rev-parse B1 >expect &&
+	test_cmp expect actual
+	'
+
+test_expect_failure 'blame --reverse --first-parent finds A1' '
+	git blame --porcelain --reverse --first-parent A0..A3 -- file.t >actual_full &&
+	head -1 <actual_full | sed -e "sX .*XX" >actual &&
+	git rev-parse A1 >expect &&
+	test_cmp expect actual
+	'
+
+test_done
-- 
2.3.4.2801.g3d0809b
Previous: Max KirillovNext: Max Kirillov
Message 2 of 13 in “blame: allow blame --reverse --first-parent when it makes sense”
  1. 0/2 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 22, 2015
  2. 1/2 Add test to describe expectation of blame --reverse with branched historyMax Kirillov, Oct 22, 2015
  3. 2/2 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 22, 2015
  4. 0/4 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 26, 2015
  5. 0/4 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 26, 2015
  6. Max KirillovOct 26, 2015
  7. 1/3 Add test to describe expectation of blame --reverse with branched historyMax Kirillov, Oct 26, 2015
  8. Max KirillovOct 26, 2015
  9. Junio C HamanoOct 26, 2015
  10. Max KirillovOct 27, 2015
  11. Junio C HamanoOct 27, 2015
  12. 2/3 blame: extract find_single_finalMax Kirillov, Oct 26, 2015
  13. 3/3 blame: allow blame --reverse --first-parent when it makes senseMax Kirillov, Oct 26, 2015

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.