Skip to contentSkip to conversation

Fix: fix comment for __git_complete_worktree_paths

PATCH In review Sardorbek Imomaliev via GitGitGadget 2 participants 4 messages Apr 29, 2021 – May 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix: fix comment for __git_complete_worktree_paths

From: Sardorbek Imomaliev <[email protected]>

Completion helper function fails for zsh because of wrongly put comment

---
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-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-943/imomaliev/fix/git-completion-worktree-subcommands-comment-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/943

 contrib/completion/git-completion.bash | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
contrib/completion/git-completion.bash +2 -2
index dfa735ea6299..b2e158edaf6b 100644
@@ -3268,9 +3268,9 @@ _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.
 	__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')"
 }
 

base-commit: 311531c9de557d25ac087c1637818bd2aad6eb3a

Signature · 1 line
gitgitgadget
#1 lore raw

"Sardorbek Imomaliev via GitGitGadget" <[email protected]>

Quoted 1 line · writes:

Subject: Re: [PATCH] Fix: fix comment for __git_complete_worktree_paths

In this project, we write what area of the codebase the change affects before the colon (I'll give you an example later).

Quoted 3 lines

From: Sardorbek Imomaliev <[email protected]>

Completion helper function fails for zsh because of wrongly put comment

Isn't it a bug in zsh that it does not understand that the comment is about the command placed on the downstream of the pipe, like this example?

echo a b c |
# upcase the input (a comment about the next line) tr a-z A-Z

Apparently bash is happy with the existing code, and dash and ksh seems to be OK with the above construct, too.

Perhaps rephrase the log message like this instead?

[PATCH] completion: work around zsh comment but in __git_complete_worktree_paths

In 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, 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.

It might also be necessary to consider rephrasing the comment itself, not just "Move the comment", to make sure that it is still appropriate when used as a comment to cover the whole pipeline---the original was meant to explain what happens in the downstream only.

Thanks.

Quoted 18 lines
contrib/completion/git-completion.bash +2 -2
index dfa735ea6299..b2e158edaf6b 100644
@@ -3268,9 +3268,9 @@ _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.
 	__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')"
 }
 

base-commit: 311531c9de557d25ac087c1637818bd2aad6eb3a

#2 lore raw

PATCH v2 1/1 work around zsh comment in __git_complete_worktree_paths

In reply to Sardorbek Imomaliev via GitGitGadget

From: Sardorbek Imomaliev <[email protected]>

[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.

---
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 <[email protected]>

## 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.

@@ 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(-)
contrib/completion/git-completion.bash +3 -2
index 49e76e9d08cd..73f9fcf493c4 100644
@@ -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')"
 }
 

base-commit: 7e391989789db82983665667013a46eabc6fc570

Signature · 1 line
gitgitgadget
#3 lore raw

Re: [PATCH v2] work around zsh comment in __git_complete_worktree_paths

"Sardorbek Imomaliev via GitGitGadget" <[email protected]>

Quoted 6 lines · writes:
contrib/completion/git-completion.bash +0 -0
index 49e76e9d08cd..73f9fcf493c4 100644
@@ -3268,9 +3268,10 @@ _git_whatchanged ()
 __git_complete_worktree_paths ()

contrib/completion/git-completion.bash _git_whatchanged () · line 3276

Quoted 10 lines
contrib/completion/git-completion.bash +3 -2
 {
 	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.