Skip to content

Commit d9758cf

Browse files
committed
Merge branch 'ah/log-decorate-default-to-auto'
The default behaviour of "git log" in an interactive session has been changed to enable "--decorate". * ah/log-decorate-default-to-auto: log: if --decorate is not given, default to --decorate=auto
2 parents d1d3d46 + 940a911 commit d9758cf

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

builtin/log.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ struct line_opt_callback_data {
5252
struct string_list args;
5353
};
5454

55+
static int auto_decoration_style(void)
56+
{
57+
return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
58+
}
59+
5560
static int parse_decoration_style(const char *var, const char *value)
5661
{
5762
switch (git_config_maybe_bool(var, value)) {
@@ -67,7 +72,7 @@ static int parse_decoration_style(const char *var, const char *value)
6772
else if (!strcmp(value, "short"))
6873
return DECORATE_SHORT_REFS;
6974
else if (!strcmp(value, "auto"))
70-
return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
75+
return auto_decoration_style();
7176
return -1;
7277
}
7378

@@ -405,6 +410,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
405410
if (decoration_style < 0)
406411
decoration_style = 0; /* maybe warn? */
407412
return 0;
413+
} else {
414+
decoration_style = auto_decoration_style();
408415
}
409416
if (!strcmp(var, "log.showroot")) {
410417
default_show_root = git_config_bool(var, value);

t/t4202-log.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='git log'
44

55
. ./test-lib.sh
66
. "$TEST_DIRECTORY/lib-gpg.sh"
7+
. "$TEST_DIRECTORY/lib-terminal.sh"
78

89
test_expect_success setup '
910
@@ -520,7 +521,7 @@ test_expect_success 'log --graph with merge' '
520521
'
521522

522523
test_expect_success 'log.decorate configuration' '
523-
git log --oneline >expect.none &&
524+
git log --oneline --no-decorate >expect.none &&
524525
git log --oneline --decorate >expect.short &&
525526
git log --oneline --decorate=full >expect.full &&
526527
@@ -576,6 +577,13 @@ test_expect_success 'log.decorate configuration' '
576577
577578
'
578579

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+
579587
test_expect_success 'reflog is expected format' '
580588
git log -g --abbrev-commit --pretty=oneline >expect &&
581589
git reflog >actual &&

0 commit comments

Comments
 (0)