Skip to content

Commit 30159e5

Browse files
committed
Merge branch 'rr/completion-branch-config'
Two-level configuration variable names in "branch.*" and "remote.*" hierarchies whose variables are predominantly three-level where not completed by hitting a <TAB> in bash and zsh completions. * rr/completion-branch-config: completion: fix remote.pushdefault completion: fix branch.autosetup(merge|rebase) completion: introduce __gitcomp_nl_append () zsh completion: find matching custom bash completion
2 parents 3b9d69e + c39a2f1 commit 30159e5

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

contrib/completion/git-completion.bash

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,22 @@ _get_comp_words_by_ref ()
178178
}
179179
fi
180180

181-
__gitcompadd ()
181+
__gitcompappend ()
182182
{
183-
local i=0
183+
local i=${#COMPREPLY[@]}
184184
for x in $1; do
185185
if [[ "$x" == "$3"* ]]; then
186186
COMPREPLY[i++]="$2$x$4"
187187
fi
188188
done
189189
}
190190

191+
__gitcompadd ()
192+
{
193+
COMPREPLY=()
194+
__gitcompappend "$@"
195+
}
196+
191197
# Generates completion reply, appending a space to possible completion words,
192198
# if necessary.
193199
# It accepts 1 to 4 arguments:
@@ -218,6 +224,14 @@ __gitcomp ()
218224
esac
219225
}
220226

227+
# Variation of __gitcomp_nl () that appends to the existing list of
228+
# completion candidates, COMPREPLY.
229+
__gitcomp_nl_append ()
230+
{
231+
local IFS=$'\n'
232+
__gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
233+
}
234+
221235
# Generates completion reply from newline-separated possible completion words
222236
# by appending a space to all of them.
223237
# It accepts 1 to 4 arguments:
@@ -229,8 +243,8 @@ __gitcomp ()
229243
# appended.
230244
__gitcomp_nl ()
231245
{
232-
local IFS=$'\n'
233-
__gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
246+
COMPREPLY=()
247+
__gitcomp_nl_append "$@"
234248
}
235249

236250
# Generates completion reply with compgen from newline-separated possible
@@ -1827,6 +1841,7 @@ _git_config ()
18271841
branch.*)
18281842
local pfx="${cur%.*}." cur_="${cur#*.}"
18291843
__gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1844+
__gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
18301845
return
18311846
;;
18321847
guitool.*.*)
@@ -1869,6 +1884,7 @@ _git_config ()
18691884
remote.*)
18701885
local pfx="${cur%.*}." cur_="${cur#*.}"
18711886
__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1887+
__gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
18721888
return
18731889
;;
18741890
url.*.*)

contrib/completion/git-completion.zsh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ if [ -z "$script" ]; then
3030
local -a locations
3131
local e
3232
locations=(
33+
$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
3334
'/etc/bash_completion.d/git' # fedora, old debian
3435
'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
3536
'/usr/share/bash-completion/git' # gentoo
36-
$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
3737
)
3838
for e in $locations; do
3939
test -f $e && script="$e" && break
@@ -76,6 +76,14 @@ __gitcomp_nl ()
7676
compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
7777
}
7878

79+
__gitcomp_nl_append ()
80+
{
81+
emulate -L zsh
82+
83+
local IFS=$'\n'
84+
compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
85+
}
86+
7987
__gitcomp_file ()
8088
{
8189
emulate -L zsh

0 commit comments

Comments
 (0)