Skip to content

Commit cf0ff02

Browse files
felipecgitster
authored andcommitted
completion: work around zsh option propagation bug
When listing commands in zsh (git <TAB><TAB>), all of them will show up, instead of only porcelain ones. The root cause of this is because zsh versions from 4.3.0 to present (4.3.15) do not correctly propagate the SH_WORD_SPLIT option into the subshell in ${foo:=$(bar)} expressions. Because of this bug, the list of all commands was treated as a single word in __git_list_porcelain_commands and did not match any of the patterns that would usually cause plumbing to be excluded. With problematic versions of zsh, after running emulate sh fn () { var='one two' for v in $var; do echo $v; done } x=$(fn) : ${y=$(fn)} printing "$x" results in two lines as expected, but printing "$y" results in a single line because $var is expanded as a single word when evaluating fn to compute y. So avoid the construct, and use an explicit 'test -n "$foo" || foo=$(bar)' instead. [jn: clarified commit message, indentation style fix] Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 828ea97 commit cf0ff02

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

contrib/completion/git-completion.bash

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ __git_merge_strategies=
676676
# is needed.
677677
__git_compute_merge_strategies ()
678678
{
679-
: ${__git_merge_strategies:=$(__git_list_merge_strategies)}
679+
test -n "$__git_merge_strategies" ||
680+
__git_merge_strategies=$(__git_list_merge_strategies)
680681
}
681682

682683
__git_complete_revlist_file ()
@@ -854,7 +855,8 @@ __git_list_all_commands ()
854855
__git_all_commands=
855856
__git_compute_all_commands ()
856857
{
857-
: ${__git_all_commands:=$(__git_list_all_commands)}
858+
test -n "$__git_all_commands" ||
859+
__git_all_commands=$(__git_list_all_commands)
858860
}
859861

860862
__git_list_porcelain_commands ()
@@ -947,7 +949,8 @@ __git_porcelain_commands=
947949
__git_compute_porcelain_commands ()
948950
{
949951
__git_compute_all_commands
950-
: ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
952+
test -n "$__git_porcelain_commands" ||
953+
__git_porcelain_commands=$(__git_list_porcelain_commands)
951954
}
952955

953956
__git_pretty_aliases ()

0 commit comments

Comments
 (0)