Teach bash how to complete git-rebase.
As git-rebase is a popular command bash should know how to complete reference names and its long options. We only support completions which make sense given the current state of the repository, that way users don't get shown --continue/--skip/--abort on the first execution. Also added support for long option --strategy to git-merge, as I missed that option earlier and just noticed it while implementing git-rebase. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Nov 27, 2006 at 03:42 UTC
61d926a3cdb8f03147580de53e448fc22370cbb1
1 file changed
+32
-6
contrib/completion/git-completion.bash
+32
-6
@@ -367,16 +367,16 @@ _git_merge ()
367
case "$cur" in
368
--*)
369
COMPREPLY=($(compgen -W "
370
- --no-commit --no-summary --squash
370
+ --no-commit --no-summary --squash --strategy
371
" -- "$cur"))
372
return
373
esac
374
- if [ $COMP_CWORD -gt 1 -a X-s = "X${COMP_WORDS[COMP_CWORD-1]}" ]
375
- then
374
+ case "${COMP_WORDS[COMP_CWORD-1]}" in
375
+ -s|--strategy)
376
COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
377
- else
378
- COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
379
- fi
377
+ return
378
+ esac
379
+ COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
380
}
381
382
_git_merge_base ()
@@ -443,6 +443,30 @@ _git_push ()
443
esac
444
}
445
446
+_git_rebase ()
447
+{
448
+ local cur="${COMP_WORDS[COMP_CWORD]}"
449
+ if [ -d .dotest ]; then
450
+ COMPREPLY=($(compgen -W "
451
+ --continue --skip --abort
452
+ " -- "$cur"))
453
+ return
454
+ fi
455
+ case "$cur" in
456
+ --*)
457
+ COMPREPLY=($(compgen -W "
458
+ --onto --merge --strategy
459
+ " -- "$cur"))
460
+ return
461
+ esac
462
+ case "${COMP_WORDS[COMP_CWORD-1]}" in
463
+ -s|--strategy)
464
+ COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
465
+ return
466
+ esac
467
+ COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
468
+}
469
+
470
_git_reset ()
471
{
472
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -500,6 +524,7 @@ _git ()
524
name-rev) _git_name_rev ;;
525
pull) _git_pull ;;
526
push) _git_push ;;
527
+ rebase) _git_rebase ;;
528
reset) _git_reset ;;
529
show) _git_show ;;
530
show-branch) _git_log ;;
@@ -532,6 +557,7 @@ complete -o default -F _git_merge_base git-merge-base
557
complete -o default -F _git_name_rev git-name-rev
558
complete -o default -o nospace -F _git_pull git-pull
559
complete -o default -o nospace -F _git_push git-push
560
+complete -o default -F _git_rebase git-rebase
561
complete -o default -F _git_reset git-reset
562
complete -o default -F _git_show git-show
563
complete -o default -o nospace -F _git_log git-show-branch