Skip to content

Commit f53352f

Browse files
spearceJunio C Hamano
authored andcommitted
Teach bash how to complete git-format-patch.
Provide completion for currently known long options supported by git-format-patch as well as the revision list specification argument, which is generally either a refname or in the form a..b. Since _git_log was the only code that knew how to complete a..b, but we want to start adding option support to _git_log also refactor the a..b completion logic out into its own function. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent d3d717a commit f53352f

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

contrib/completion/git-completion.bash

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ __git_complete_file ()
144144
esac
145145
}
146146

147+
__git_complete_revlist ()
148+
{
149+
local pfx cur="${COMP_WORDS[COMP_CWORD]}"
150+
case "$cur" in
151+
*...*)
152+
pfx="${cur%...*}..."
153+
cur="${cur#*...}"
154+
COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
155+
;;
156+
*..*)
157+
pfx="${cur%..*}.."
158+
cur="${cur#*..}"
159+
COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
160+
;;
161+
*)
162+
COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
163+
;;
164+
esac
165+
}
166+
147167
__git_commands ()
148168
{
149169
local i IFS=" "$'\n'
@@ -290,6 +310,26 @@ _git_fetch ()
290310
esac
291311
}
292312

313+
_git_format_patch ()
314+
{
315+
local cur="${COMP_WORDS[COMP_CWORD]}"
316+
case "$cur" in
317+
--*)
318+
COMPREPLY=($(compgen -W "
319+
--stdout --attach --thread
320+
--output-directory
321+
--numbered --start-number
322+
--keep-subject
323+
--signoff
324+
--in-reply-to=
325+
--full-index --binary
326+
" -- "$cur"))
327+
return
328+
;;
329+
esac
330+
__git_complete_revlist
331+
}
332+
293333
_git_ls_remote ()
294334
{
295335
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -303,22 +343,7 @@ _git_ls_tree ()
303343

304344
_git_log ()
305345
{
306-
local pfx cur="${COMP_WORDS[COMP_CWORD]}"
307-
case "$cur" in
308-
*...*)
309-
pfx="${cur%...*}..."
310-
cur="${cur#*...}"
311-
COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
312-
;;
313-
*..*)
314-
pfx="${cur%..*}.."
315-
cur="${cur#*..}"
316-
COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
317-
;;
318-
*)
319-
COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
320-
;;
321-
esac
346+
__git_complete_revlist
322347
}
323348

324349
_git_merge ()
@@ -450,6 +475,7 @@ _git ()
450475
diff) _git_diff ;;
451476
diff-tree) _git_diff_tree ;;
452477
fetch) _git_fetch ;;
478+
format-patch) _git_format_patch ;;
453479
log) _git_log ;;
454480
ls-remote) _git_ls_remote ;;
455481
ls-tree) _git_ls_tree ;;
@@ -480,6 +506,7 @@ complete -o default -F _git_checkout git-checkout
480506
complete -o default -o nospace -F _git_diff git-diff
481507
complete -o default -F _git_diff_tree git-diff-tree
482508
complete -o default -o nospace -F _git_fetch git-fetch
509+
complete -o default -o nospace -F _git_format_patch git-format-patch
483510
complete -o default -o nospace -F _git_log git-log
484511
complete -o default -F _git_ls_remote git-ls-remote
485512
complete -o default -o nospace -F _git_ls_tree git-ls-tree
@@ -503,6 +530,7 @@ complete -o default -F _git_branch git-branch.exe
503530
complete -o default -o nospace -F _git_cat_file git-cat-file.exe
504531
complete -o default -o nospace -F _git_diff git-diff.exe
505532
complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
533+
complete -o default -o nospace -F _git_format_patch git-format-patch.exe
506534
complete -o default -o nospace -F _git_log git-log.exe
507535
complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
508536
complete -o default -F _git_merge_base git-merge-base.exe

0 commit comments

Comments
 (0)