From: "Alexey I. Froloff" <raorn@altlinux.org>
To: Zsh list <zsh-workers@zsh.org>
Cc: "Alexey I. Froloff" <raorn@altlinux.org>
Subject: [PATCH] _git: offer files relative to current directory
Date: Mon, 7 Dec 2009 00:52:33 +0300 [thread overview]
Message-ID: <1260136353-20093-1-git-send-email-raorn@altlinux.org> (raw)
In-Reply-To: <20091205174551.GF3344@altlinux.org>
When offering repository files (cached, deleted, changed, etc), make
sure that paths are relative to current directory, as git expects.
Signed-off-by: Alexey I. Froloff <raorn@altlinux.org>
---
Completion/Unix/Command/_git | 61 +++++++++++++++++++++++++++++++++++++++---
1 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index e483133..5371fd5 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -2773,19 +2773,70 @@ __git_stages () {
__git_guard $* "[[:digit:]]#" 'stage'
}
+(( $+functions[__git_files_relative] )) ||
+__git_files_relative () {
+ local rawfiles files file f_parts prefix p_parts tmp
+
+ prefix=$(_call_program gitprefix git rev-parse --show-prefix 2>/dev/null)
+ __git_command_successful || return
+
+ # Empty prefix, no modifications
+ if (( $#prefix == 0 )); then
+ print $1
+ return
+ fi
+
+ rawfiles=(${(ps:\0:)1})
+ files=()
+
+ # Now we assume that we've given "absolute" paths list with "root"
+ # being repository top directory. $prefix is also "absolute" path.
+ for file in $rawfiles; do
+ # Collapse "/./" and "//", strip "/." and "/" from tail (I know,
+ # this is a bit paranoid).
+ f_parts=(${(s:/:)"${${${${file//\/\///}//\/.\///}%%/.}%%/}"})
+ p_parts=(${(s:/:)"${${${${prefix//\/\///}//\/.\///}%%/.}%%/}"})
+ tmp=()
+
+ # Strip common path prefix.
+ while (( $#f_parts > 0 )) && (( $#p_parts > 0 )) && [[ $f_parts[1] == $p_parts[1] ]]; do
+ f_parts[1]=()
+ p_parts[1]=()
+ done
+
+ # If prefix still not empty, ascend up.
+ while (( $#p_parts > 0 )); do
+ tmp+=..
+ p_parts[1]=()
+ done
+
+ # Add remaining path.
+ tmp=("$tmp[@]" "$f_parts[@]")
+
+ files+=${(j:/:)tmp}
+ done
+
+ print ${(pj:\0:)files}
+}
+
(( $+functions[__git_files] )) ||
__git_files () {
- local expl files ls_opts opts gitdir
+ local expl files ls_opts opts gitdir gitcdup
zparseopts -D -E -a opts -- -cached -deleted -modified -others -ignored -unmerged -killed
gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
__git_command_successful || return
+ gitcdup=$(_call_program gitcdup git rev-parse --show-cdup 2>/dev/null)
+ __git_command_successful || return
+
ls_opts=("--exclude-per-directory=.gitignore")
[[ -f "$gitdir/info/exclude" ]] && ls_opts+="--exclude-from=$gitdir/info/exclude"
- files=(${(ps:\0:)"$(_call_program files git ls-files -z $ls_opts $opts 2>/dev/null)"})
+ files=$(_call_program files git ls-files -z --full-name $ls_opts $opts -- $gitcdup 2>/dev/null)
+ __git_command_successful || return
+ files=(${(ps:\0:)"$(__git_files_relative $files)"})
__git_command_successful || return
_wanted files expl 'index file' _multi_parts $@ - / files
@@ -2824,9 +2875,11 @@ __git_unmerged_files () {
#this is for git-commit which can take files both git-added and not
(( $+functions[__git_changed_files] )) ||
__git_changed_files () {
- local -a files
+ local files
- files=(${(ps:\0:)"$(_call_program files git diff-index -z --name-only --no-color HEAD 2>/dev/null)"})
+ files=$(_call_program files git diff-index -z --name-only --no-color HEAD 2>/dev/null)
+ __git_command_successful || return
+ files=(${(ps:\0:)"$(__git_files_relative $files)"})
__git_command_successful || return
_wanted files expl 'index file' _multi_parts $@ - / files
--
1.6.5.3
next prev parent reply other threads:[~2009-12-06 21:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-05 0:32 [PATCH] _git: offer changed " Alexey I. Froloff
2009-12-05 12:07 ` Štěpán Němec
2009-12-05 12:42 ` Alexey I. Froloff
2009-12-05 15:12 ` Alexey I. Froloff
2009-12-05 17:00 ` Štěpán Němec
2009-12-05 17:45 ` Alexey I. Froloff
2009-12-06 21:52 ` Alexey I. Froloff [this message]
2009-12-07 22:40 ` [PATCH] _git: offer " Alexey I. Froloff
2009-12-08 10:48 ` Štěpán Němec
2009-12-08 10:50 ` Nikolai Weibull
2009-12-08 11:37 ` Štěpán Němec
2009-12-08 11:45 ` Mikael Magnusson
2009-12-08 11:22 ` Alexey I. Froloff
2009-12-08 11:39 ` Štěpán Němec
2009-12-08 12:07 ` Alexey I. Froloff
2009-12-13 0:08 ` Alexey I. Froloff
2009-12-13 21:33 ` Peter Stephenson
2009-12-13 22:16 ` Nikolai Weibull
2009-12-13 22:22 ` Štěpán Němec
2009-12-14 13:20 ` Jörg Sommer
2009-12-08 12:08 ` [PATCH] _git: offer changed " Alexey I. Froloff
2009-12-08 13:20 ` Štěpán Němec
2009-12-08 13:30 ` Alexey I. Froloff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1260136353-20093-1-git-send-email-raorn@altlinux.org \
--to=raorn@altlinux.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).