Skip to content

Commit 8b504db

Browse files
qneillgitster
authored andcommitted
blame: add blame.showEmail configuration
Complement existing --show-email option with fallback configuration variable, with tests. Signed-off-by: Quentin Neill <quentin.neill@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3d4a3ff commit 8b504db

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

Documentation/git-blame.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ include::blame-options.txt[]
7676
-e::
7777
--show-email::
7878
Show the author email instead of author name (Default: off).
79+
This can also be controlled via the `blame.showEmail` config
80+
option.
7981

8082
-w::
8183
Ignore whitespace when comparing the parent's version and

builtin/blame.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,14 @@ static int git_blame_config(const char *var, const char *value, void *cb)
21852185
blank_boundary = git_config_bool(var, value);
21862186
return 0;
21872187
}
2188+
if (!strcmp(var, "blame.showemail")) {
2189+
int *output_option = cb;
2190+
if (git_config_bool(var, value))
2191+
*output_option |= OUTPUT_SHOW_EMAIL;
2192+
else
2193+
*output_option &= ~OUTPUT_SHOW_EMAIL;
2194+
return 0;
2195+
}
21882196
if (!strcmp(var, "blame.date")) {
21892197
if (!value)
21902198
return config_error_nonbool(var);
@@ -2528,7 +2536,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
25282536
unsigned int range_i;
25292537
long anchor;
25302538

2531-
git_config(git_blame_config, NULL);
2539+
git_config(git_blame_config, &output_option);
25322540
init_revisions(&revs, NULL);
25332541
revs.date_mode = blame_date_mode;
25342542
DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV);

t/t8002-blame.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,66 @@ test_expect_success 'blame --show-email' '
1919
"<E at test dot git>" 1
2020
'
2121

22+
test_expect_success 'setup showEmail tests' '
23+
echo "bin: test number 1" >one &&
24+
git add one &&
25+
GIT_AUTHOR_NAME=name1 \
26+
GIT_AUTHOR_EMAIL=email1@test.git \
27+
git commit -m First --date="2010-01-01 01:00:00" &&
28+
cat >expected_n <<-\EOF &&
29+
(name1 2010-01-01 01:00:00 +0000 1) bin: test number 1
30+
EOF
31+
cat >expected_e <<-\EOF
32+
(<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1
33+
EOF
34+
'
35+
36+
find_blame () {
37+
sed -e 's/^[^(]*//'
38+
}
39+
40+
test_expect_success 'blame with no options and no config' '
41+
git blame one >blame &&
42+
find_blame <blame >result &&
43+
test_cmp expected_n result
44+
'
45+
46+
test_expect_success 'blame with showemail options' '
47+
git blame --show-email one >blame1 &&
48+
find_blame <blame1 >result &&
49+
test_cmp expected_e result &&
50+
git blame -e one >blame2 &&
51+
find_blame <blame2 >result &&
52+
test_cmp expected_e result &&
53+
git blame --no-show-email one >blame3 &&
54+
find_blame <blame3 >result &&
55+
test_cmp expected_n result
56+
'
57+
58+
test_expect_success 'blame with showEmail config false' '
59+
git config blame.showEmail false &&
60+
git blame one >blame1 &&
61+
find_blame <blame1 >result &&
62+
test_cmp expected_n result &&
63+
git blame --show-email one >blame2 &&
64+
find_blame <blame2 >result &&
65+
test_cmp expected_e result &&
66+
git blame -e one >blame3 &&
67+
find_blame <blame3 >result &&
68+
test_cmp expected_e result &&
69+
git blame --no-show-email one >blame4 &&
70+
find_blame <blame4 >result &&
71+
test_cmp expected_n result
72+
'
73+
74+
test_expect_success 'blame with showEmail config true' '
75+
git config blame.showEmail true &&
76+
git blame one >blame1 &&
77+
find_blame <blame1 >result &&
78+
test_cmp expected_e result &&
79+
git blame --no-show-email one >blame2 &&
80+
find_blame <blame2 >result &&
81+
test_cmp expected_n result
82+
'
83+
2284
test_done

0 commit comments

Comments
 (0)