35060 + 35072: completion: git: split __git_heads into local and remote

It is useful to have this distinction visually.

This also uses `--format=%(refname:short)` directly with `git
for-each-ref`.
This commit is contained in:
Daniel Hahler 2015-05-08 15:41:01 +02:00 committed by Daniel Shahaf
parent ffdeb1c257
commit b884853756
3 changed files with 29 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2015-05-12 Daniel Hahler <git@thequod.de>
* 35060 + 35072: Completion/Unix/Command/_git: completion: git: split
__git_heads into local and remote
2015-05-12 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
* 35075: Doc/Zsh/builtins.yo, Doc/Zsh/calsys.yo,

View File

@ -5614,10 +5614,16 @@ __git_commits () {
(( $+functions[__git_heads] )) ||
__git_heads () {
__git_heads_local
__git_heads_remote
}
(( $+functions[__git_heads_local] )) ||
__git_heads_local () {
local gitdir expl start
declare -a heads
heads=(${${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname)"' refs/heads refs/remotes 2>/dev/null)"}#refs/(heads|remotes)/})
heads=(${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname:short)" refs/heads' 2>/dev/null)"})
gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
if __git_command_successful $pipestatus; then
for f in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
@ -5626,7 +5632,17 @@ __git_heads () {
[[ -f $gitdir/refs/stash ]] && heads+=stash
fi
_wanted heads expl head compadd "$@" -a - heads
_wanted heads-local expl "local head" compadd "$@" -a - heads
}
(( $+functions[__git_heads_remote] )) ||
__git_heads_remote () {
local gitdir expl start
declare -a heads
heads=(${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname:short)" refs/remotes' 2>/dev/null)"})
_wanted heads-remote expl "remote head" compadd "$@" -a - heads
}
(( $+functions[__git_commit_objects] )) ||

6
README
View File

@ -117,6 +117,12 @@ New behaviour:
0.5
4) The _git completion used to offer both local and remote heads under the
tag 'heads'. The tag has now been split into 'heads-local' and
'heads-remote' in all contexts that existed in 5.0.7. The --fixup/--squash
context still uses the tag 'heads' (but this may change in a future release).
Incompatibilities between 5.0.2 and 5.0.5
-----------------------------------------