git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC PATCH] completion: support excluding refs
@ 2016-08-24  8:41 Chris Packham
  2016-08-24 16:52 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Packham @ 2016-08-24  8:41 UTC (permalink / raw)
  To: git; +Cc: Chris Packham

Allow completion of refs with a ^ prefix. This allows completion of
commands like 'git log HEAD ^origin/master'.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
I often find myself using variations of 'git log HEAD ^origin/master' to
see commits that I have locally that have not been pushed. It is also
useful when reviewing changes before integrating them e.g. 'git fetch
...; git log FETCH_HEAD ^origin/master'.

 contrib/completion/git-completion.bash | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 9c8f738..21016bf 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -338,7 +338,7 @@ __git_tags ()
 __git_refs ()
 {
 	local i hash dir="$(__gitdir "${1-}")" track="${2-}"
-	local format refs
+	local format refs pfx
 	if [ -d "$dir" ]; then
 		case "$cur" in
 		refs|refs/*)
@@ -347,14 +347,15 @@ __git_refs ()
 			track=""
 			;;
 		*)
+			[[ "$cur" == ^* ]] && pfx="^"
 			for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
-				if [ -e "$dir/$i" ]; then echo $i; fi
+				if [ -e "$dir/$i" ]; then echo $pfx$i; fi
 			done
 			format="refname:short"
 			refs="refs/tags refs/heads refs/remotes"
 			;;
 		esac
-		git --git-dir="$dir" for-each-ref --format="%($format)" \
+		git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
 			$refs
 		if [ -n "$track" ]; then
 			# employ the heuristic used by git checkout
-- 
2.9.2.518.ged577c6.dirty


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

* Re: [RFC PATCH] completion: support excluding refs
  2016-08-24  8:41 [RFC PATCH] completion: support excluding refs Chris Packham
@ 2016-08-24 16:52 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2016-08-24 16:52 UTC (permalink / raw)
  To: Chris Packham; +Cc: git

Chris Packham <judge.packham@gmail.com> writes:

> Allow completion of refs with a ^ prefix. This allows completion of
> commands like 'git log HEAD ^origin/master'.
> ...
> +			[[ "$cur" == ^* ]] && pfx="^"
>  			for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
> -				if [ -e "$dir/$i" ]; then echo $i; fi
> +				if [ -e "$dir/$i" ]; then echo $pfx$i; fi
>  			done
>  			format="refname:short"
>  			refs="refs/tags refs/heads refs/remotes"
>  			;;
>  		esac
> -		git --git-dir="$dir" for-each-ref --format="%($format)" \
> +		git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
>  			$refs

That looks like a reasonable approach to me (but I am no expert in
this area myself).


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

end of thread, other threads:[~2016-08-24 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-24  8:41 [RFC PATCH] completion: support excluding refs Chris Packham
2016-08-24 16:52 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).