Git fork
at reftables-rust 115 lines 3.9 kB view raw
1#!/bin/sh 2 3test_description='git command aliasing' 4 5. ./test-lib.sh 6 7test_expect_success 'nested aliases - internal execution' ' 8 git config alias.nested-internal-1 nested-internal-2 && 9 git config alias.nested-internal-2 status && 10 git nested-internal-1 >output && 11 test_grep "^On branch " output 12' 13 14test_expect_success 'nested aliases - mixed execution' ' 15 git config alias.nested-external-1 nested-external-2 && 16 git config alias.nested-external-2 "!git nested-external-3" && 17 git config alias.nested-external-3 status && 18 git nested-external-1 >output && 19 test_grep "^On branch " output 20' 21 22test_expect_success 'looping aliases - internal execution' ' 23 git config alias.loop-internal-1 loop-internal-2 && 24 git config alias.loop-internal-2 loop-internal-3 && 25 git config alias.loop-internal-3 loop-internal-2 && 26 test_must_fail git loop-internal-1 2>output && 27 test_grep "^fatal: alias loop detected: expansion of" output 28' 29 30test_expect_success 'looping aliases - deprecated builtins' ' 31 test_config alias.whatchanged pack-redundant && 32 test_config alias.pack-redundant whatchanged && 33 cat >expect <<-EOF && 34 ${SQ}whatchanged${SQ} is aliased to ${SQ}pack-redundant${SQ} 35 ${SQ}pack-redundant${SQ} is aliased to ${SQ}whatchanged${SQ} 36 fatal: alias loop detected: expansion of ${SQ}whatchanged${SQ} does not terminate: 37 whatchanged <== 38 pack-redundant ==> 39 EOF 40 test_must_fail git whatchanged -h 2>actual && 41 test_cmp expect actual 42' 43 44# This test is disabled until external loops are fixed, because would block 45# the test suite for a full minute. 46# 47#test_expect_failure 'looping aliases - mixed execution' ' 48# git config alias.loop-mixed-1 loop-mixed-2 && 49# git config alias.loop-mixed-2 "!git loop-mixed-1" && 50# test_must_fail git loop-mixed-1 2>output && 51# test_grep "^fatal: alias loop detected: expansion of" output 52#' 53 54test_expect_success 'run-command formats empty args properly' ' 55 test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw && 56 sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual && 57 echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect && 58 test_cmp expect actual 59' 60 61test_expect_success 'tracing a shell alias with arguments shows trace of prepared command' ' 62 cat >expect <<-EOF && 63 trace: start_command: SHELL -c ${SQ}echo \$* "\$@"${SQ} ${SQ}echo \$*${SQ} arg 64 EOF 65 git config alias.echo "!echo \$*" && 66 env GIT_TRACE=1 git echo arg 2>output && 67 # redact platform differences 68 sed -n -e "s/^\(trace: start_command:\) .* -c /\1 SHELL -c /p" output >actual && 69 test_cmp expect actual 70' 71 72can_alias_deprecated_builtin () { 73 cmd="$1" && 74 # some git(1) commands will fail for `-h` (the case for 75 # git-status as of 2025-09-07) 76 test_might_fail git status -h >expect && 77 test_file_not_empty expect && 78 test_might_fail git -c alias."$cmd"=status "$cmd" -h >actual && 79 test_cmp expect actual 80} 81 82test_expect_success 'can alias-shadow deprecated builtins' ' 83 for cmd in $(git --list-cmds=deprecated) 84 do 85 can_alias_deprecated_builtin "$cmd" || return 1 86 done 87' 88 89test_expect_success 'can alias-shadow via two deprecated builtins' ' 90 # some git(1) commands will fail... (see above) 91 test_might_fail git status -h >expect && 92 test_file_not_empty expect && 93 test_might_fail git -c alias.whatchanged=pack-redundant \ 94 -c alias.pack-redundant=status whatchanged -h >actual && 95 test_cmp expect actual 96' 97 98cannot_alias_regular_builtin () { 99 cmd="$1" && 100 # some git(1) commands will fail... (see above) 101 test_might_fail git "$cmd" -h >expect && 102 test_file_not_empty expect && 103 test_might_fail git -c alias."$cmd"=status "$cmd" -h >actual && 104 test_cmp expect actual 105} 106 107test_expect_success 'cannot alias-shadow a sample of regular builtins' ' 108 for cmd in grep check-ref-format interpret-trailers \ 109 checkout-index fast-import diagnose rev-list prune 110 do 111 cannot_alias_regular_builtin "$cmd" || return 1 112 done 113' 114 115test_done