Merge branch 'jk/blame-fake-commit-label'

The output given by "git blame" that attributes a line to contents
taken from the file specified by the "--contents" option shows it
differently from a line attributed to the working tree file.

* jk/blame-fake-commit-label:
  blame: use different author name for fake commit generated by --contents
This commit is contained in:
Junio C Hamano 2023-05-02 10:13:34 -07:00
commit cf85f4b3bd
3 changed files with 18 additions and 9 deletions

View File

@ -64,11 +64,9 @@ include::line-range-format.txt[]
manual page. manual page.
--contents <file>:: --contents <file>::
Pretend the file being annotated has a commit with the Annotate using the contents from the named file, starting from <rev>
contents from the named file and a parent of <rev>, if it is specified, and HEAD otherwise. You may specify '-' to make
defaulting to HEAD when no <rev> is specified. You may the command read from the standard input for the file contents.
specify '-' to make the command read from the standard
input for the file contents.
--date <format>:: --date <format>::
Specifies the format used to output dates. If --date is not Specifies the format used to output dates. If --date is not

View File

@ -208,8 +208,12 @@ static struct commit *fake_working_tree_commit(struct repository *r,
origin = make_origin(commit, path); origin = make_origin(commit, path);
ident = fmt_ident("Not Committed Yet", "not.committed.yet", if (contents_from)
WANT_BLANK_IDENT, NULL, 0); ident = fmt_ident("External file (--contents)", "external.file",
WANT_BLANK_IDENT, NULL, 0);
else
ident = fmt_ident("Not Committed Yet", "not.committed.yet",
WANT_BLANK_IDENT, NULL, 0);
strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n"); strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n");
for (parent = commit->parents; parent; parent = parent->next) for (parent = commit->parents; parent; parent = parent->next)
strbuf_addf(&msg, "parent %s\n", strbuf_addf(&msg, "parent %s\n",

View File

@ -72,6 +72,13 @@ test_expect_success 'blame 1 author' '
check_count A 2 check_count A 2
' '
test_expect_success 'blame working copy' '
test_when_finished "git restore file" &&
echo "1A quick brown fox jumps over the" >file &&
echo "another lazy dog" >>file &&
check_count A 1 "Not Committed Yet" 1
'
test_expect_success 'blame with --contents' ' test_expect_success 'blame with --contents' '
check_count --contents=file A 2 check_count --contents=file A 2
' '
@ -79,7 +86,7 @@ test_expect_success 'blame with --contents' '
test_expect_success 'blame with --contents changed' ' test_expect_success 'blame with --contents changed' '
echo "1A quick brown fox jumps over the" >contents && echo "1A quick brown fox jumps over the" >contents &&
echo "another lazy dog" >>contents && echo "another lazy dog" >>contents &&
check_count --contents=contents A 1 "Not Committed Yet" 1 check_count --contents=contents A 1 "External file (--contents)" 1
' '
test_expect_success 'blame in a bare repo without starting commit' ' test_expect_success 'blame in a bare repo without starting commit' '
@ -109,7 +116,7 @@ test_expect_success 'blame 2 authors' '
' '
test_expect_success 'blame with --contents and revision' ' test_expect_success 'blame with --contents and revision' '
check_count -h testTag --contents=file A 2 "Not Committed Yet" 2 check_count -h testTag --contents=file A 2 "External file (--contents)" 2
' '
test_expect_success 'setup B1 lines (branch1)' ' test_expect_success 'setup B1 lines (branch1)' '