diff mbox series

[v2] work around zsh comment in __git_complete_worktree_paths

Message ID pull.943.v2.git.1620059347674.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit f2acf763e29a3696fef268a9e8dc421e807df7f2
Headers show
Series [v2] work around zsh comment in __git_complete_worktree_paths | expand

Commit Message

Sardorbek Imomaliev May 3, 2021, 4:29 p.m. UTC
From: Sardorbek Imomaliev <sardorbek.imomaliev@gmail.com>

[PATCH]: contrib/completion/git-completion.bash, there is a construct
where comment lines are placed between the command that is on
the upstream of a pipe and the command that is on the downstream
of a pipe in __git_complete_worktree_paths function.

Unfortunately, this script is also used by Zsh completion, but
Zsh mishandles this construct when "interactive_comments" option is not
set (by default it is off on macOS), resulting in a breakage:

$ git worktree remove [TAB]
$ git worktree remove __git_complete_worktree_paths:7: command not found: #

Move the comment, even though it explains what happens on the
downstream of the pipe and logically belongs where it is right
now, before the entire pipeline, to work around this problem.

Signed-off-by: Sardorbek Imomaliev <sardorbek.imomaliev@gmail.com>
---
    Fix: wrongly put comment for __git_complete_worktree_paths completion
    helper function
    
    git completion script fails for zsh
    
    $ git worktree remove [TAB]
    $ git worktree remove __git_complete_worktree_paths:7: command not found: #
    

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-943%2Fimomaliev%2Ffix%2Fgit-completion-worktree-subcommands-comment-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-943/imomaliev/fix/git-completion-worktree-subcommands-comment-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/943

Range-diff vs v1:

 1:  89a2a4d66b73 ! 1:  60ba6801e0f5 Fix: fix comment for __git_complete_worktree_paths
     @@ Metadata
      Author: Sardorbek Imomaliev <sardorbek.imomaliev@gmail.com>
      
       ## Commit message ##
     -    Fix: fix comment for __git_complete_worktree_paths
     +    work around zsh comment in __git_complete_worktree_paths
      
     -    Completion helper function fails for zsh because of wrongly put comment
     +    [PATCH]: contrib/completion/git-completion.bash, there is a construct
     +    where comment lines are placed between the command that is on
     +    the upstream of a pipe and the command that is on the downstream
     +    of a pipe in __git_complete_worktree_paths function.
     +
     +    Unfortunately, this script is also used by Zsh completion, but
     +    Zsh mishandles this construct when "interactive_comments" option is not
     +    set (by default it is off on macOS), resulting in a breakage:
     +
     +    $ git worktree remove [TAB]
     +    $ git worktree remove __git_complete_worktree_paths:7: command not found: #
     +
     +    Move the comment, even though it explains what happens on the
     +    downstream of the pipe and logically belongs where it is right
     +    now, before the entire pipeline, to work around this problem.
      
          Signed-off-by: Sardorbek Imomaliev <sardorbek.imomaliev@gmail.com>
      
     @@ contrib/completion/git-completion.bash: _git_whatchanged ()
       __git_complete_worktree_paths ()
       {
       	local IFS=$'\n'
     -+	# Skip the first entry: it's the path of the main worktree,
     -+	# which can't be moved, removed, locked, etc.
     ++	# Generate completion reply from worktree list skipping the first
     ++	# entry: it's the path of the main worktree, which can't be moved,
     ++	# removed, locked, etc.
       	__gitcomp_nl "$(git worktree list --porcelain |
      -		# Skip the first entry: it's the path of the main worktree,
      -		# which can't be moved, removed, locked, etc.


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


base-commit: 7e391989789db82983665667013a46eabc6fc570

Comments

Junio C Hamano May 4, 2021, 3:18 a.m. UTC | #1
"Sardorbek Imomaliev via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 49e76e9d08cd..73f9fcf493c4 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -3268,9 +3268,10 @@ _git_whatchanged ()
>  __git_complete_worktree_paths ()
>  {
>  	local IFS=$'\n'
> +	# Generate completion reply from worktree list skipping the first
> +	# entry: it's the path of the main worktree, which can't be moved,
> +	# removed, locked, etc.
>  	__gitcomp_nl "$(git worktree list --porcelain |
> -		# Skip the first entry: it's the path of the main worktree,
> -		# which can't be moved, removed, locked, etc.
>  		sed -n -e '2,$ s/^worktree //p')"
>  }

Makes sense.  Thanks, will queue.
diff mbox series

Patch

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 49e76e9d08cd..73f9fcf493c4 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3268,9 +3268,10 @@  _git_whatchanged ()
 __git_complete_worktree_paths ()
 {
 	local IFS=$'\n'
+	# Generate completion reply from worktree list skipping the first
+	# entry: it's the path of the main worktree, which can't be moved,
+	# removed, locked, etc.
 	__gitcomp_nl "$(git worktree list --porcelain |
-		# Skip the first entry: it's the path of the main worktree,
-		# which can't be moved, removed, locked, etc.
 		sed -n -e '2,$ s/^worktree //p')"
 }