git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/10] Teach git-completion.bash how to complete git-merge.
@ 2006-11-27  8:40 Shawn O. Pearce
  2006-11-27 19:12 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Shawn O. Pearce @ 2006-11-27  8:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Now that git-merge is high-level Porcelain users are going to expect
to be able to use it from the command line, in which case we really
should also be able to complete ref names as parameters.

I'm also including completion support for the merge strategies
that are supported by git-merge.sh, should the user wish to use a
different strategy than their default.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index a43a177..28bd0e3 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -81,6 +81,16 @@ __git_remotes ()
 	done
 }
 
+__git_merge_strategies ()
+{
+	sed -n "/^all_strategies='/{
+		s/^all_strategies='//
+		s/'//
+		p
+		q
+		}" "$(git --exec-path)/git-merge"
+}
+
 __git_complete_file ()
 {
 	local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
@@ -240,6 +250,24 @@ _git_log ()
 	esac
 }
 
+_git_merge ()
+{
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		COMPREPLY=($(compgen -W "
+			--no-commit --no-summary --squash
+			" -- "$cur"))
+		return
+	esac
+	if [ $COMP_CWORD -gt 1 -a X-s = "X${COMP_WORDS[COMP_CWORD-1]}" ]
+	then
+		COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
+	else
+		COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
+	fi
+}
+
 _git_merge_base ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -348,6 +376,7 @@ _git ()
 	log)         _git_log ;;
 	ls-remote)   _git_ls_remote ;;
 	ls-tree)     _git_ls_tree ;;
+	merge)       _git_merge;;
 	merge-base)  _git_merge_base ;;
 	pull)        _git_pull ;;
 	push)        _git_push ;;
@@ -376,6 +405,7 @@ complete -o default -o nospace -F _git_fetch git-fetch
 complete -o default -o nospace -F _git_log git-log
 complete -o default            -F _git_ls_remote git-ls-remote
 complete -o default -o nospace -F _git_ls_tree git-ls-tree
+complete -o default            -F _git_merge git-merge
 complete -o default            -F _git_merge_base git-merge-base
 complete -o default -o nospace -F _git_pull git-pull
 complete -o default -o nospace -F _git_push git-push
-- 
1.4.4.1.ge3fb

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/10] Teach git-completion.bash how to complete git-merge.
  2006-11-27  8:40 [PATCH 1/10] Teach git-completion.bash how to complete git-merge Shawn O. Pearce
@ 2006-11-27 19:12 ` Junio C Hamano
  2006-11-27 20:12   ` Shawn Pearce
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2006-11-27 19:12 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: git

"Shawn O. Pearce" <spearce@spearce.org> writes:

> +__git_merge_strategies ()
> +{
> +	sed -n "/^all_strategies='/{
> +		s/^all_strategies='//
> +		s/'//
> +		p
> +		q
> +		}" "$(git --exec-path)/git-merge"
> +}
> +

Shouldn't we load and compute this once and keep the result in a
variable (say $__git_merge_strategies)?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/10] Teach git-completion.bash how to complete git-merge.
  2006-11-27 19:12 ` Junio C Hamano
@ 2006-11-27 20:12   ` Shawn Pearce
  0 siblings, 0 replies; 3+ messages in thread
From: Shawn Pearce @ 2006-11-27 20:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano <junkio@cox.net> wrote:
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > +__git_merge_strategies ()
> > +{
> > +	sed -n "/^all_strategies='/{
> > +		s/^all_strategies='//
> > +		s/'//
> > +		p
> > +		q
> > +		}" "$(git --exec-path)/git-merge"
> > +}
> > +
> 
> Shouldn't we load and compute this once and keep the result in a
> variable (say $__git_merge_strategies)?

Sure.  See my latest 4 patch series.  :-)
 
-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-11-27 20:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-27  8:40 [PATCH 1/10] Teach git-completion.bash how to complete git-merge Shawn O. Pearce
2006-11-27 19:12 ` Junio C Hamano
2006-11-27 20:12   ` Shawn Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).