From 2cd134f2c538a9cb7b0946ace6004489eba9535f Mon Sep 17 00:00:00 2001 From: Brian Lyles Date: Mon, 25 Mar 2024 02:25:12 -0500 Subject: [PATCH 1/2] pretty: update tests to use `test_config` These tests use raw `git config` calls, which is an older style that can cause config to bleed between tests if not manually unset. `test_config` ensures that config is unset at the end of each test automatically. `test_config` is chosen over `git -c` since `test_config` still ends up calling `git config` which seems slightly more realistic to how pretty formats would be defined normally. Suggested-by: Jeff King Signed-off-by: Brian Lyles Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 4cf8a77667..e14cce6d70 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -30,40 +30,38 @@ test_expect_success 'set up basic repos' ' >bar && git add foo && test_tick && - git config i18n.commitEncoding $test_encoding && + test_config i18n.commitEncoding $test_encoding && commit_msg $test_encoding | git commit -F - && git add bar && test_tick && - git commit -m "add bar" && - git config --unset i18n.commitEncoding + git commit -m "add bar" ' test_expect_success 'alias builtin format' ' git log --pretty=oneline >expected && - git config pretty.test-alias oneline && + test_config pretty.test-alias oneline && git log --pretty=test-alias >actual && test_cmp expected actual ' test_expect_success 'alias masking builtin format' ' git log --pretty=oneline >expected && - git config pretty.oneline "%H" && + test_config pretty.oneline "%H" && git log --pretty=oneline >actual && test_cmp expected actual ' test_expect_success 'alias user-defined format' ' git log --pretty="format:%h" >expected && - git config pretty.test-alias "format:%h" && + test_config pretty.test-alias "format:%h" && git log --pretty=test-alias >actual && test_cmp expected actual ' test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' - git config i18n.logOutputEncoding $test_encoding && + test_config i18n.logOutputEncoding $test_encoding && git log --oneline >expected-s && git log --pretty="tformat:%h %s" >actual-s && - git config --unset i18n.logOutputEncoding && test_cmp expected-s actual-s ' @@ -75,34 +73,34 @@ test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' ' test_expect_success 'alias user-defined tformat' ' git log --pretty="tformat:%h" >expected && - git config pretty.test-alias "tformat:%h" && + test_config pretty.test-alias "tformat:%h" && git log --pretty=test-alias >actual && test_cmp expected actual ' test_expect_success 'alias non-existent format' ' - git config pretty.test-alias format-that-will-never-exist && + test_config pretty.test-alias format-that-will-never-exist && test_must_fail git log --pretty=test-alias ' test_expect_success 'alias of an alias' ' git log --pretty="tformat:%h" >expected && - git config pretty.test-foo "tformat:%h" && - git config pretty.test-bar test-foo && + test_config pretty.test-foo "tformat:%h" && + test_config pretty.test-bar test-foo && git log --pretty=test-bar >actual && test_cmp expected actual ' test_expect_success 'alias masking an alias' ' git log --pretty=format:"Two %H" >expected && - git config pretty.duplicate "format:One %H" && - git config --add pretty.duplicate "format:Two %H" && + test_config pretty.duplicate "format:One %H" && + test_config pretty.duplicate "format:Two %H" --add && git log --pretty=duplicate >actual && test_cmp expected actual ' test_expect_success 'alias loop' ' - git config pretty.test-foo test-bar && - git config pretty.test-bar test-foo && + test_config pretty.test-foo test-bar && + test_config pretty.test-bar test-foo && test_must_fail git log --pretty=test-foo ' From f999d5188b4060aa0f784a6f4cf1574ea352a1e7 Mon Sep 17 00:00:00 2001 From: Brian Lyles Date: Mon, 25 Mar 2024 02:25:13 -0500 Subject: [PATCH 2/2] pretty: find pretty formats case-insensitively User-defined pretty formats are stored in config, which is meant to use case-insensitive matching for names as noted in config.txt's 'Syntax' section: All the other lines [...] are recognized as setting variables, in the form 'name = value' [...]. The variable names are case-insensitive, [...]. When a user specifies one of their format aliases with an uppercase in it, however, it is not found. $ git config pretty.testAlias %h $ git config --list | grep pretty pretty.testalias=%h $ git log --format=testAlias -1 fatal: invalid --pretty format: testAlias $ git log --format=testalias -1 3c2a3fdc38 This is true whether the name in the config file uses any uppercase characters or not. Use case-insensitive comparisons when identifying format aliases. Co-authored-by: Jeff King Signed-off-by: Brian Lyles Signed-off-by: Junio C Hamano --- pretty.c | 2 +- t/t4205-log-pretty-formats.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pretty.c b/pretty.c index 1e1e21878c..558622cf2b 100644 --- a/pretty.c +++ b/pretty.c @@ -140,7 +140,7 @@ static struct cmt_fmt_map *find_commit_format_recursive(const char *sought, for (i = 0; i < commit_formats_len; i++) { size_t match_len; - if (!starts_with(commit_formats[i].name, sought)) + if (!istarts_with(commit_formats[i].name, sought)) continue; match_len = strlen(commit_formats[i].name); diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index e14cce6d70..bf36e7b0ae 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -58,6 +58,14 @@ test_expect_success 'alias user-defined format' ' test_cmp expected actual ' +test_expect_success 'alias user-defined format is matched case-insensitively' ' + git log --pretty="format:%h" >expected && + test_config pretty.testone "format:%h" && + test_config pretty.testtwo testOne && + git log --pretty=testTwo >actual && + test_cmp expected actual +' + test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' test_config i18n.logOutputEncoding $test_encoding && git log --oneline >expected-s &&