Skip to content

Commit cf85f4b

Browse files
committed
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
2 parents f357d46 + 603d0fd commit cf85f4b

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Documentation/blame-options.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ include::line-range-format.txt[]
6464
manual page.
6565

6666
--contents <file>::
67-
Pretend the file being annotated has a commit with the
68-
contents from the named file and a parent of <rev>,
69-
defaulting to HEAD when no <rev> is specified. You may
70-
specify '-' to make the command read from the standard
71-
input for the file contents.
67+
Annotate using the contents from the named file, starting from <rev>
68+
if it is specified, and HEAD otherwise. You may specify '-' to make
69+
the command read from the standard input for the file contents.
7270

7371
--date <format>::
7472
Specifies the format used to output dates. If --date is not

blame.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,12 @@ static struct commit *fake_working_tree_commit(struct repository *r,
208208

209209
origin = make_origin(commit, path);
210210

211-
ident = fmt_ident("Not Committed Yet", "not.committed.yet",
212-
WANT_BLANK_IDENT, NULL, 0);
211+
if (contents_from)
212+
ident = fmt_ident("External file (--contents)", "external.file",
213+
WANT_BLANK_IDENT, NULL, 0);
214+
else
215+
ident = fmt_ident("Not Committed Yet", "not.committed.yet",
216+
WANT_BLANK_IDENT, NULL, 0);
213217
strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n");
214218
for (parent = commit->parents; parent; parent = parent->next)
215219
strbuf_addf(&msg, "parent %s\n",

t/annotate-tests.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,21 @@ test_expect_success 'blame 1 author' '
7272
check_count A 2
7373
'
7474

75+
test_expect_success 'blame working copy' '
76+
test_when_finished "git restore file" &&
77+
echo "1A quick brown fox jumps over the" >file &&
78+
echo "another lazy dog" >>file &&
79+
check_count A 1 "Not Committed Yet" 1
80+
'
81+
7582
test_expect_success 'blame with --contents' '
7683
check_count --contents=file A 2
7784
'
7885

7986
test_expect_success 'blame with --contents changed' '
8087
echo "1A quick brown fox jumps over the" >contents &&
8188
echo "another lazy dog" >>contents &&
82-
check_count --contents=contents A 1 "Not Committed Yet" 1
89+
check_count --contents=contents A 1 "External file (--contents)" 1
8390
'
8491

8592
test_expect_success 'blame in a bare repo without starting commit' '
@@ -109,7 +116,7 @@ test_expect_success 'blame 2 authors' '
109116
'
110117

111118
test_expect_success 'blame with --contents and revision' '
112-
check_count -h testTag --contents=file A 2 "Not Committed Yet" 2
119+
check_count -h testTag --contents=file A 2 "External file (--contents)" 2
113120
'
114121

115122
test_expect_success 'setup B1 lines (branch1)' '

0 commit comments

Comments
 (0)