* [PATCH] _git: Support completion from outside of a worktree when --git-dir/--work-tree are specified on the command line
@ 2020-01-16 17:05 Daniel Shahaf
2020-01-16 17:10 ` Roman Perepelitsa
2020-01-16 18:56 ` Daniel Shahaf
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Shahaf @ 2020-01-16 17:05 UTC (permalink / raw)
To: zsh-workers
Revised version of workers/41523.
---
The original patch used ${(e)} but that would execute command substitutions in
cases such as «--git-dir=$(pwd)». ${(Q)${~foo}} doesn't have that problem.
The problem it does have is that «--git-dir=$HOME/foo» doesn't expand $HOME.
A syntax that performs "safe" expansions — i.e., those that can be done without
running arbitrary code — would be useful, both in completion and in widgets
(e.g., z-sy-h would find that useful).
For 5.9.
Cheers,
Daniel
(Someone ran into the problem and the fix on IRC.)
Completion/Unix/Command/_git | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 7f2c206c1..350414bd5 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -7077,21 +7077,22 @@ __git_files_relative () {
(( $+functions[__git_files] )) ||
__git_files () {
- local compadd_opts opts tag description gitcdup gitprefix files expl
+ local compadd_opts opts tag description gittoplevel gitprefix files expl
zparseopts -D -E -a compadd_opts V+: J+: 1 2 o+: n f x+: X+: M+: P: S: r: R: q F:
zparseopts -D -E -a opts -- -cached -deleted -modified -others -ignored -unmerged -killed x+: --exclude+:
tag=$1 description=$2; shift 2
- gitcdup=$(_call_program gitcdup git rev-parse --show-cdup 2>/dev/null)
+ gittoplevel=$(_call_program toplevel git rev-parse --show-toplevel 2>/dev/null)
__git_command_successful $pipestatus || return 1
+ [[ -n $gittoplevel ]] && gittoplevel+="/"
gitprefix=$(_call_program gitprefix git rev-parse --show-prefix 2>/dev/null)
__git_command_successful $pipestatus || return 1
# TODO: --directory should probably be added to $opts when --others is given.
- local pref=$gitcdup$gitprefix$PREFIX
+ local pref=$gittoplevel$gitprefix$PREFIX
# First allow ls-files to pattern-match in case of remote repository
files=(${(0)"$(_call_program files git ls-files -z --exclude-standard ${(q)opts} -- ${(q)${pref:+$pref\*}:-.} 2>/dev/null)"})
@@ -8133,7 +8134,8 @@ _git() {
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:git-$words[1]:
- (( $+opt_args[--git-dir] )) && local -x GIT_DIR=$opt_args[--git-dir]
+ (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}}
+ (( $+opt_args[--work-tree] )) && local -x GIT_WORK_TREE=${(Q)${~opt_args[--work-tree]}}
if ! _call_function ret _git-$words[1]; then
if [[ $words[1] = \!* ]]; then
words[1]=${words[1]##\!}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] _git: Support completion from outside of a worktree when --git-dir/--work-tree are specified on the command line
2020-01-16 17:05 [PATCH] _git: Support completion from outside of a worktree when --git-dir/--work-tree are specified on the command line Daniel Shahaf
@ 2020-01-16 17:10 ` Roman Perepelitsa
2020-01-16 18:56 ` Daniel Shahaf
1 sibling, 0 replies; 3+ messages in thread
From: Roman Perepelitsa @ 2020-01-16 17:10 UTC (permalink / raw)
To: Daniel Shahaf; +Cc: Zsh hackers list
Thank you! This was driving me nuts.
Roman
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] _git: Support completion from outside of a worktree when --git-dir/--work-tree are specified on the command line
2020-01-16 17:05 [PATCH] _git: Support completion from outside of a worktree when --git-dir/--work-tree are specified on the command line Daniel Shahaf
2020-01-16 17:10 ` Roman Perepelitsa
@ 2020-01-16 18:56 ` Daniel Shahaf
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2020-01-16 18:56 UTC (permalink / raw)
To: zsh-workers
Daniel Shahaf wrote on Thu, Jan 16, 2020 at 17:05:38 +0000:
> +++ b/Completion/Unix/Command/_git
> @@ -7077,21 +7077,22 @@ __git_files_relative () {
> - local pref=$gitcdup$gitprefix$PREFIX
> + local pref=$gittoplevel$gitprefix$PREFIX
Following a conversation of IRC I changed this line to account for the case
that $PREFIX is an absolute path. Revised patch:
[adding a marker line for git am -c]
8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--
From 7bbc8efc83bd2d549c9034f11a2b23d07ad18d18 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <danielsh@apache.org>
Date: Thu, 16 Jan 2020 16:42:20 +0000
Subject: [PATCH] _git: Support completion from outside of a worktree when
--git-dir/--work-tree are specified on the command line
Revised version of workers/41523.
---
Completion/Unix/Command/_git | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 7f2c206c1..3bc9158f5 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -7077,21 +7077,23 @@ __git_files_relative () {
(( $+functions[__git_files] )) ||
__git_files () {
- local compadd_opts opts tag description gitcdup gitprefix files expl
+ local compadd_opts opts tag description gittoplevel gitprefix files expl
zparseopts -D -E -a compadd_opts V+: J+: 1 2 o+: n f x+: X+: M+: P: S: r: R: q F:
zparseopts -D -E -a opts -- -cached -deleted -modified -others -ignored -unmerged -killed x+: --exclude+:
tag=$1 description=$2; shift 2
- gitcdup=$(_call_program gitcdup git rev-parse --show-cdup 2>/dev/null)
+ gittoplevel=$(_call_program toplevel git rev-parse --show-toplevel 2>/dev/null)
__git_command_successful $pipestatus || return 1
+ [[ -n $gittoplevel ]] && gittoplevel+="/"
gitprefix=$(_call_program gitprefix git rev-parse --show-prefix 2>/dev/null)
__git_command_successful $pipestatus || return 1
# TODO: --directory should probably be added to $opts when --others is given.
- local pref=$gitcdup$gitprefix$PREFIX
+ local pref=${(Q)${~PREFIX}}
+ [[ $pref[1] == '/' ]] || pref=$gittoplevel$gitprefix$pref
# First allow ls-files to pattern-match in case of remote repository
files=(${(0)"$(_call_program files git ls-files -z --exclude-standard ${(q)opts} -- ${(q)${pref:+$pref\*}:-.} 2>/dev/null)"})
@@ -8133,7 +8135,8 @@ _git() {
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:git-$words[1]:
- (( $+opt_args[--git-dir] )) && local -x GIT_DIR=$opt_args[--git-dir]
+ (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}}
+ (( $+opt_args[--work-tree] )) && local -x GIT_WORK_TREE=${(Q)${~opt_args[--work-tree]}}
if ! _call_function ret _git-$words[1]; then
if [[ $words[1] = \!* ]]; then
words[1]=${words[1]##\!}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-16 18:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 17:05 [PATCH] _git: Support completion from outside of a worktree when --git-dir/--work-tree are specified on the command line Daniel Shahaf
2020-01-16 17:10 ` Roman Perepelitsa
2020-01-16 18:56 ` Daniel Shahaf
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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).