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

[PATCH 5/7] t8015: Add tests for git blame -F

From
ATAleks Todorov <aleks.todorov.1337@gmail.com>
Date
Mar 1, 2025, 21:45 UTC
Message-ID
<20250301214652.536439-6-aleks.todorov.1337@gmail.com>
In-Reply-To
<20250301214652.536439-1-aleks.todorov.1337@gmail.com>
Include three tests, testing each facet of the implementation:
  - an empty format test to confirm that the flag is available and
    correctly hooked into git (respects empty format and does not emit
    any blame metadata)
  - a default format test to confirm that both the existing log
    specifiers and the new blame-specific specifiers %F and %L are
    expanded as expected
  - a config test to confirm that the blame.format config is available
    under the correct name and used by the program
Signed-off-by: Aleks Todorov <aleks.todorov.1337@gmail.com>
---
 t/meson.build           |  1 +
 t/t8015-blame-format.sh | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100755 t/t8015-blame-format.sh
diff --git a/t/meson.build b/t/meson.build
index 780939d49f..da798fbc88 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -958,6 +958,7 @@ integration_tests = [
   't8012-blame-colors.sh',
   't8013-blame-ignore-revs.sh',
   't8014-blame-ignore-fuzzy.sh',
+  't8015-blame-format.sh',
   't9001-send-email.sh',
   't9002-column.sh',
   't9003-help-autocorrect.sh',
diff --git a/t/t8015-blame-format.sh b/t/t8015-blame-format.sh
new file mode 100755
index 0000000000..8d05310d5d
--- /dev/null
+++ b/t/t8015-blame-format.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+test_description='git blame -F option'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	echo line1 >file &&
+	git add file &&
+	git commit -m commit1 &&
+	echo line2 >>file &&
+	git add file &&
+	git commit -m commit2 &&
+	shortId1=$(git rev-parse HEAD^ | cut -c 1-8) &&
+	shortId2=$(git rev-parse HEAD | cut -c 1-8)
+'
+
+test_expect_success 'empty format' '
+	echo "line1\nline2" >expect &&
+	git blame file -F "" >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'default format' '
+	echo "$shortId1 file (A U Thor 2005-04-01 13:14:15 +0200 1) line1" >expect &&
+	echo "$shortId2 file (A U Thor 2005-04-01 13:14:15 +0200 2) line2" >>expect &&
+	git blame file -F "%h %F (%an %ai %L) " >/tmp/actual &&
+	test_cmp expect /tmp/actual
+'
+
+test_expect_success 'blame.format config' '
+	echo "$shortId1 file (A U Thor 2005-04-01 13:14:15 +0200 1) line1" >expect &&
+	echo "$shortId2 file (A U Thor 2005-04-01 13:14:15 +0200 2) line2" >>expect &&
+	git config blame.format "%h %F (%an %ai %L) " &&
+	git blame file >/tmp/actual &&
+	test_cmp expect /tmp/actual
+'
+
+test_done
-- 
2.43.0
Previous: Aleks TodorovNext: Aleks Todorov
Message 6 of 8 in “Add Format Specifier for Blame”
  1. 0/7 Add Format Specifier for BlameAleks Todorov, Mar 1, 2025
  2. 1/7 builtin/blame: Accept a user-specified formatAleks Todorov, Mar 1, 2025
  3. 2/7 builtin/blame: Add blame.format config optionAleks Todorov, Mar 1, 2025
  4. 3/7 pretty: Add F and L format specifiersAleks Todorov, Mar 1, 2025
  5. 4/7 builtin/blame: Expand format when availableAleks Todorov, Mar 1, 2025
  6. 5/7 t8015: Add tests for git blame -FAleks Todorov, Mar 1, 2025
  7. 6/7 Documentation: Move placeholders to separate fileAleks Todorov, Mar 1, 2025
  8. 7/7 Documentation: Add docs for blame formatAleks Todorov, Mar 1, 2025

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.