# [PATCH] bash completion: add basic support for git-reflog

5 messages from 2010-11-20 to 2010-11-22. Participants: Tay Ray Chuan, SZEDER Gábor, Jonathan Nieder.
Thread: https://gitlist.dev/t/25796

## Tay Ray Chuan, 2010-11-20 17:32

Subject: [PATCH] bash completion: add basic support for git-reflog
Message-ID: <1290274368-3212-1-git-send-email-rctay89@gmail.com>
URL: https://gitlist.dev/e/1290274368-3212-1-git-send-email-rctay89%40gmail.com

```
Add basic completion for the three subcommands - show, expire, delete.
Try completing refs for these too.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 contrib/completion/git-completion.bash |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index f710469..4007ca1 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1632,6 +1632,22 @@ _git_rebase ()
 	__gitcomp "$(__git_refs)"
 }
 
+_git_reflog ()
+{
+	local SUB_CMDS=(show delete expire)
+	local cur="${COMP_WORDS[COMP_CWORD-1]}"
+
+	for val in ${SUB_CMDS[*]}; do
+		if [[ "$val" == "$cur" ]]; then
+			# this is a subcommand
+			__gitcomp "$(__git_refs)"
+			return
+		fi
+	done
+
+	__gitcomp "${SUB_CMDS[*]}"
+}
+
 __git_send_email_confirm_options="always never auto cc compose"
 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
 
-- 
1.7.3.2.496.g9c54

```

## SZEDER Gábor, 2010-11-22 15:24

Subject: Re: [PATCH] bash completion: add basic support for git-reflog
Message-ID: <20101122152409.GA7010@neumann>
URL: https://gitlist.dev/e/20101122152409.GA7010%40neumann
In-Reply-To: <1290274368-3212-1-git-send-email-rctay89@gmail.com>

```
Hi,


On Sun, Nov 21, 2010 at 01:32:48AM +0800, Tay Ray Chuan wrote:
> Add basic completion for the three subcommands - show, expire, delete.
> Try completing refs for these too.

Heh, I've always thought reflog is plumbing, and that's why the
completion script doesn't support it.

> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
> ---
>  contrib/completion/git-completion.bash |   16 ++++++++++++++++
>  1 files changed, 16 insertions(+), 0 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index f710469..4007ca1 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1632,6 +1632,22 @@ _git_rebase ()
>  	__gitcomp "$(__git_refs)"
>  }
>  
> +_git_reflog ()
> +{
> +	local SUB_CMDS=(show delete expire)
> +	local cur="${COMP_WORDS[COMP_CWORD-1]}"
> +
> +	for val in ${SUB_CMDS[*]}; do
> +		if [[ "$val" == "$cur" ]]; then
> +			# this is a subcommand
> +			__gitcomp "$(__git_refs)"
> +			return

This only looks at the previous word on the command line, and leads to
wrong behavior when an option is used:

  $ git reflog expire --verbose <TAB><TAB>
  delete   expire   show     

To prevent this you could use the __git_find_on_cmdline() helper
function and follow how other completion functions use it.


> +		fi
> +	done
> +
> +	__gitcomp "${SUB_CMDS[*]}"
> +}
> +
>  __git_send_email_confirm_options="always never auto cc compose"
>  __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
>  
> -- 
> 1.7.3.2.496.g9c54
> 
> 

```

## Tay Ray Chuan, 2010-11-22 15:50

Subject: Re: [PATCH] bash completion: add basic support for git-reflog
Message-ID: <AANLkTinJPQF-khzViED+ROyojEr9nHrcgwKQWsDugD7Y@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinJPQF-khzViED%2BROyojEr9nHrcgwKQWsDugD7Y%40mail.gmail.com
In-Reply-To: <20101122152409.GA7010@neumann>

```
Hi,

2010/11/22 SZEDER Gábor <szeder@ira.uka.de>:
> On Sun, Nov 21, 2010 at 01:32:48AM +0800, Tay Ray Chuan wrote:
>> Add basic completion for the three subcommands - show, expire, delete.
>> Try completing refs for these too.
>
> Heh, I've always thought reflog is plumbing, and that's why the
> completion script doesn't support it.

That didn't really cross my mind, I just did this out of my irritation
with its absence.

(After some checking, it's actually part of git-log, so I don't think
it counts as plumbing.)

> This only looks at the previous word on the command line, and leads to
> wrong behavior when an option is used:
>
>  $ git reflog expire --verbose <TAB><TAB>
>  delete   expire   show
>
> To prevent this you could use the __git_find_on_cmdline() helper
> function and follow how other completion functions use it.

Yep I'll look into it.

-- 
Cheers,
Ray Chuan

```

## Tay Ray Chuan, 2010-11-22 17:09

Subject: [PATCH] bash completion: add basic support for git-reflog
Message-ID: <1290445749-4884-1-git-send-email-rctay89@gmail.com>
URL: https://gitlist.dev/e/1290445749-4884-1-git-send-email-rctay89%40gmail.com
In-Reply-To: <AANLkTinJPQF-khzViED+ROyojEr9nHrcgwKQWsDugD7Y@mail.gmail.com>

```
"Promote" the reflog command out of plumbing, so that we now run
completion for it. After all, it's listed under porcelain (ancillary),
and we do run completion for those commands.

Add basic completion for the three subcommands - show, expire, delete.
Try completing refs for these too.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---

Changed from v1: 
 - picked up Gábor's suggestion on using __git_find_on_cmdline()
   to correctly handle situations where subcommands are used with dashed
   options.
 - don't "hide" reflog anymore - run completion for it too.

Gábor: hmm, it really seems that reflog is treated as plumbing - no completion
is done for it. Even get-tar-commit-id (I've never used this before) is treated
better than reflog. Shall do something about it!

 contrib/completion/git-completion.bash |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index f710469..6732b1d 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -735,7 +735,6 @@ __git_list_porcelain_commands ()
 		quiltimport)      : import;;
 		read-tree)        : plumbing;;
 		receive-pack)     : plumbing;;
-		reflog)           : plumbing;;
 		remote-*)         : transport;;
 		repo-config)      : deprecated;;
 		rerere)           : plumbing;;
@@ -1632,6 +1631,18 @@ _git_rebase ()
 	__gitcomp "$(__git_refs)"
 }
 
+_git_reflog ()
+{
+	local subcommands="show delete expire"
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+
+	if [ -z "$subcommand" ]; then
+		__gitcomp "$subcommands"
+	else
+		__gitcomp "$(__git_refs)"
+	fi
+}
+
 __git_send_email_confirm_options="always never auto cc compose"
 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
 
-- 
1.7.3.2.493.g2b058

```

## Jonathan Nieder, 2010-11-22 17:20

Subject: Re: [PATCH] bash completion: add basic support for git-reflog
Message-ID: <20101122172057.GC2084@burratino>
URL: https://gitlist.dev/e/20101122172057.GC2084%40burratino
In-Reply-To: <1290445749-4884-1-git-send-email-rctay89@gmail.com>

```
Tay Ray Chuan wrote:

> Gábor: hmm, it really seems that reflog is treated as plumbing - no completion
> is done for it.

Probably because it is listed as such in command-list.txt.  I guess
the user-facing command for reflog expiration is meant to be "git gc"?

> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1632,6 +1631,18 @@ _git_rebase ()
>  	__gitcomp "$(__git_refs)"
>  }
>  
> +_git_reflog ()
> +{
> +	local subcommands="show delete expire"

People really do seem to use these commands directly, so I'm all for
this.

I wish there were a way to easily point the end user from "git reflog
show" to "git log --walk-reflogs" (to make the list of other accepted
options more obvious) but I can't think of one.

Regards,
Jonathan

```
