Skip to content

Commit 603d0fd

Browse files
jacob-kellergitster
authored andcommitted
blame: use different author name for fake commit generated by --contents
When the --contents option is used with git blame, and the contents of the file have lines which can't be annotated by the history being blamed, the user will see an author of "Not Committed Yet". This is similar to the way blame handles working tree contents when blaming without a revision. This is slightly confusing since this data isn't the working copy and while it is technically "not committed yet", its also coming from an external file. Replace this author name with "External file (--contents)" to better differentiate such lines from actual working copy lines. Suggested-by: Junio C Hamano <[email protected]> Suggested-by: Glen Choo <[email protected]> Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7580f92 commit 603d0fd

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
@@ -206,8 +206,12 @@ static struct commit *fake_working_tree_commit(struct repository *r,
206206

207207
origin = make_origin(commit, path);
208208

209-
ident = fmt_ident("Not Committed Yet", "not.committed.yet",
210-
WANT_BLANK_IDENT, NULL, 0);
209+
if (contents_from)
210+
ident = fmt_ident("External file (--contents)", "external.file",
211+
WANT_BLANK_IDENT, NULL, 0);
212+
else
213+
ident = fmt_ident("Not Committed Yet", "not.committed.yet",
214+
WANT_BLANK_IDENT, NULL, 0);
211215
strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n");
212216
for (parent = commit->parents; parent; parent = parent->next)
213217
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)