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>
This commit is contained in:

committed by
Junio C Hamano

parent
c0f9c70589
commit
940a911f8e
@ -52,6 +52,11 @@ struct line_opt_callback_data {
|
|||||||
struct string_list args;
|
struct string_list args;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int auto_decoration_style(void)
|
||||||
|
{
|
||||||
|
return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_decoration_style(const char *var, const char *value)
|
static int parse_decoration_style(const char *var, const char *value)
|
||||||
{
|
{
|
||||||
switch (git_config_maybe_bool(var, value)) {
|
switch (git_config_maybe_bool(var, value)) {
|
||||||
@ -67,7 +72,7 @@ static int parse_decoration_style(const char *var, const char *value)
|
|||||||
else if (!strcmp(value, "short"))
|
else if (!strcmp(value, "short"))
|
||||||
return DECORATE_SHORT_REFS;
|
return DECORATE_SHORT_REFS;
|
||||||
else if (!strcmp(value, "auto"))
|
else if (!strcmp(value, "auto"))
|
||||||
return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0;
|
return auto_decoration_style();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,6 +410,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
|
|||||||
if (decoration_style < 0)
|
if (decoration_style < 0)
|
||||||
decoration_style = 0; /* maybe warn? */
|
decoration_style = 0; /* maybe warn? */
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
decoration_style = auto_decoration_style();
|
||||||
}
|
}
|
||||||
if (!strcmp(var, "log.showroot")) {
|
if (!strcmp(var, "log.showroot")) {
|
||||||
default_show_root = git_config_bool(var, value);
|
default_show_root = git_config_bool(var, value);
|
||||||
|
@ -4,6 +4,7 @@ test_description='git log'
|
|||||||
|
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
. "$TEST_DIRECTORY/lib-gpg.sh"
|
. "$TEST_DIRECTORY/lib-gpg.sh"
|
||||||
|
. "$TEST_DIRECTORY/lib-terminal.sh"
|
||||||
|
|
||||||
test_expect_success setup '
|
test_expect_success setup '
|
||||||
|
|
||||||
@ -520,7 +521,7 @@ test_expect_success 'log --graph with merge' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'log.decorate configuration' '
|
test_expect_success 'log.decorate configuration' '
|
||||||
git log --oneline >expect.none &&
|
git log --oneline --no-decorate >expect.none &&
|
||||||
git log --oneline --decorate >expect.short &&
|
git log --oneline --decorate >expect.short &&
|
||||||
git log --oneline --decorate=full >expect.full &&
|
git log --oneline --decorate=full >expect.full &&
|
||||||
|
|
||||||
@ -576,6 +577,13 @@ test_expect_success 'log.decorate configuration' '
|
|||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success TTY 'log output on a TTY' '
|
||||||
|
git log --oneline --decorate >expect.short &&
|
||||||
|
|
||||||
|
test_terminal git log --oneline >actual &&
|
||||||
|
test_cmp expect.short actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'reflog is expected format' '
|
test_expect_success 'reflog is expected format' '
|
||||||
git log -g --abbrev-commit --pretty=oneline >expect &&
|
git log -g --abbrev-commit --pretty=oneline >expect &&
|
||||||
git reflog >actual &&
|
git reflog >actual &&
|
||||||
|
Reference in New Issue
Block a user