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>
Quentin Neill committed
May 31, 2015 at 14:27 UTC
8b504db309c3b08e8ba7bd425a5fa29c29d8a4d5
3 files changed
+73
-1
Documentation/git-blame.txt
+2
@@ -76,6 +76,8 @@ include::blame-options.txt[]
76
-e::
77
--show-email::
78
Show the author email instead of author name (Default: off).
79
+ This can also be controlled via the `blame.showEmail` config
80
+ option.
81
82
-w::
83
Ignore whitespace when comparing the parent's version and
builtin/blame.c
+9
-1
@@ -2185,6 +2185,14 @@ static int git_blame_config(const char *var, const char *value, void *cb)
2185
blank_boundary = git_config_bool(var, value);
2186
return 0;
2187
}
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
+ }
2196
if (!strcmp(var, "blame.date")) {
2197
if (!value)
2198
return config_error_nonbool(var);
@@ -2528,7 +2536,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2536
unsigned int range_i;
2537
long anchor;
2538
2531
- git_config(git_blame_config, NULL);
2539
+ git_config(git_blame_config, &output_option);
2540
init_revisions(&revs, NULL);
2541
revs.date_mode = blame_date_mode;
2542
DIFF_OPT_SET(&revs.diffopt, ALLOW_TEXTCONV);
t/t8002-blame.sh
+62
@@ -19,4 +19,66 @@ test_expect_success 'blame --show-email' '
19
"<E at test dot git>" 1
20
'
21
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
+
84
test_done