log: if --decorate is not given, default to --decorate=auto
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alex Henrie committed
Mar 23, 2017 at 23:46 UTC
940a911f8ec00e291a66c2d1ed05293a38ae6138
2 files changed
+17
-2
builtin/log.c
+8
-1
@@ -52,6 +52,11 @@ struct line_opt_callback_data {
52
struct string_list args;
53
};
54
55
+static int auto_decoration_style(void)
56
+{
57
+ return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
58
+}
59
+
60
static int parse_decoration_style(const char *var, const char *value)
61
{
62
switch (git_config_maybe_bool(var, value)) {
@@ -67,7 +72,7 @@ static int parse_decoration_style(const char *var, const char *value)
72
else if (!strcmp(value, "short"))
73
return DECORATE_SHORT_REFS;
74
else if (!strcmp(value, "auto"))
70
- return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
75
+ return auto_decoration_style();
76
return -1;
77
}
78
@@ -405,6 +410,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
410
if (decoration_style < 0)
411
decoration_style = 0; /* maybe warn? */
412
return 0;
413
+ } else {
414
+ decoration_style = auto_decoration_style();
415
}
416
if (!strcmp(var, "log.showroot")) {
417
default_show_root = git_config_bool(var, value);
t/t4202-log.sh
+9
-1
@@ -4,6 +4,7 @@ test_description='git log'
4
5
. ./test-lib.sh
6
. "$TEST_DIRECTORY/lib-gpg.sh"
7
+. "$TEST_DIRECTORY/lib-terminal.sh"
8
9
test_expect_success setup '
10
@@ -520,7 +521,7 @@ test_expect_success 'log --graph with merge' '
521
'
522
523
test_expect_success 'log.decorate configuration' '
523
- git log --oneline >expect.none &&
524
+ git log --oneline --no-decorate >expect.none &&
525
git log --oneline --decorate >expect.short &&
526
git log --oneline --decorate=full >expect.full &&
527
@@ -576,6 +577,13 @@ test_expect_success 'log.decorate configuration' '
577
578
'
579
580
+test_expect_success TTY 'log output on a TTY' '
581
+ git log --oneline --decorate >expect.short &&
582
+
583
+ test_terminal git log --oneline >actual &&
584
+ test_cmp expect.short actual
585
+'
586
+
587
test_expect_success 'reflog is expected format' '
588
git log -g --abbrev-commit --pretty=oneline >expect &&
589
git reflog >actual &&