diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-09-10 08:38:37 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-09-10 08:38:37 -0700 |
| commit | a6f2bea1acc73fcf34154756f043594ace6e3ec8 (patch) | |
| tree | 949ddd8e7b1041fc15babdfa2cfb860a99c57c5b /t | |
| parent | c073a070363222dcdc24b2cde692f8ca1bd65233 (diff) | |
| parent | a190cc5ca59f0143cb28abb57a5c5f520fbc0afa (diff) | |
Merge branch 'ap/var-broken-down-idents' into seenseen
* ap/var-broken-down-idents:
var: support broken-down idents, signing key, multiple args, and -z
Diffstat (limited to 't')
| -rwxr-xr-x | t/t0007-git-var.sh | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh index 2b60317758..75f688a1b1 100755 --- a/t/t0007-git-var.sh +++ b/t/t0007-git-var.sh @@ -276,4 +276,131 @@ test_expect_success '`git var -l` works even without HOME' ' ) ' +test_expect_success 'get author identity components' ' + test_tick && + echo "$GIT_AUTHOR_NAME" >expect.name && + echo "$GIT_AUTHOR_EMAIL" >expect.email && + echo "$GIT_AUTHOR_DATE" >expect.date && + git var GIT_AUTHOR_NAME >actual.name && + git var GIT_AUTHOR_EMAIL >actual.email && + git var GIT_AUTHOR_DATE >actual.date && + test_cmp expect.name actual.name && + test_cmp expect.email actual.email && + test_cmp expect.date actual.date +' + +test_expect_success 'get committer identity components' ' + test_tick && + echo "$GIT_COMMITTER_NAME" >expect.name && + echo "$GIT_COMMITTER_EMAIL" >expect.email && + echo "$GIT_COMMITTER_DATE" >expect.date && + git var GIT_COMMITTER_NAME >actual.name && + git var GIT_COMMITTER_EMAIL >actual.email && + git var GIT_COMMITTER_DATE >actual.date && + test_cmp expect.name actual.name && + test_cmp expect.email actual.email && + test_cmp expect.date actual.date +' + +test_expect_success 'get multiple variables' ' + test_tick && + cat >expect <<-EOF && + $GIT_AUTHOR_NAME + $GIT_AUTHOR_EMAIL + $GIT_COMMITTER_NAME + $GIT_COMMITTER_EMAIL + EOF + git var GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL >actual && + test_cmp expect actual +' + +test_expect_success 'get multiple variables with -z' ' + test_tick && + printf "%sQ%sQ" "$GIT_AUTHOR_NAME" "$GIT_AUTHOR_EMAIL" >expect && + git var -z GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL >actual.raw && + nul_to_q <actual.raw >actual && + test_cmp expect actual +' + +test_expect_success 'get multi-valued variable with -z' ' + TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" && + HOME="$TRASHDIR" XDG_CONFIG_HOME="$TRASHDIR/foo" git var -z GIT_CONFIG_GLOBAL >actual.raw && + printf "%sQ%sQ" "$TRASHDIR/foo/git/config" "$TRASHDIR/.gitconfig" >expect && + nul_to_q <actual.raw >actual && + test_cmp expect actual +' + +test_expect_success 'git var -l -z' ' + git var -l -z >actual && + tr "\0" "\n" <actual >actual.lines && + echo "$GIT_AUTHOR_NAME" >expect && + sed -n "/^GIT_AUTHOR_NAME$/{n;p;}" actual.lines >actual.author && + test_cmp expect actual.author && + echo false >expect && + sed -n "/^core\.bare$/{n;p;}" actual.lines >actual.bare && + test_cmp expect actual.bare +' + +test_expect_success 'get GIT_SIGNING_KEY with user.signingkey configured' ' + test_config user.signingkey "TEST_KEY_ID" && + echo "TEST_KEY_ID" >expect && + git var GIT_SIGNING_KEY >actual && + test_cmp expect actual +' + +test_expect_success 'get GIT_SIGNING_KEY fails when unset' ' + test_config user.signingkey "" && + test_must_fail git var GIT_SIGNING_KEY +' + +test_expect_success 'git var -l lists new variables' ' + git var -l >actual && + test_grep "^GIT_AUTHOR_NAME=" actual && + test_grep "^GIT_AUTHOR_EMAIL=" actual && + test_grep "^GIT_AUTHOR_DATE=" actual && + test_grep "^GIT_COMMITTER_NAME=" actual && + test_grep "^GIT_COMMITTER_EMAIL=" actual && + test_grep "^GIT_COMMITTER_DATE=" actual +' + +test_expect_success 'git var -l lists GIT_SIGNING_KEY when configured' ' + test_config user.signingkey "TEST_KEY_ID" && + git var -l >actual && + test_grep "^GIT_SIGNING_KEY=TEST_KEY_ID" actual +' + +test_expect_success 'options must precede variable arguments' ' + test_must_fail git var GIT_AUTHOR_NAME -z +' + +test_expect_success 'get multiple variables with unset variable outputs blank record' ' + test_config user.signingkey "" && + cat >expect <<-EOF && + $GIT_AUTHOR_NAME + + $GIT_COMMITTER_NAME + EOF + git var GIT_AUTHOR_NAME GIT_SIGNING_KEY GIT_COMMITTER_NAME >actual && + test_cmp expect actual +' + +test_expect_success 'get multiple variables with -z and unset variable' ' + test_config user.signingkey "" && + printf "%sQ%sQ" "$GIT_AUTHOR_NAME" "Q$GIT_COMMITTER_NAME" >expect && + git var -z GIT_AUTHOR_NAME GIT_SIGNING_KEY GIT_COMMITTER_NAME >actual.raw && + nul_to_q <actual.raw >actual && + test_cmp expect actual +' + +test_expect_success 'get multiple variables including multi-valued variable with -z' ' + TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" && + printf "%sQ%sQ%sQQ%sQ" "$GIT_AUTHOR_NAME" \ + "$TRASHDIR/foo/git/config" "$TRASHDIR/.gitconfig" \ + "$GIT_AUTHOR_EMAIL" >expect && + HOME="$TRASHDIR" XDG_CONFIG_HOME="$TRASHDIR/foo" \ + git var -z GIT_AUTHOR_NAME GIT_CONFIG_GLOBAL GIT_AUTHOR_EMAIL >actual.raw && + nul_to_q <actual.raw >actual && + test_cmp expect actual +' + test_done |
