Merge pull request #1864 from Stibbons/gsemet_push_git_plugin

Improvement in the git plugin
This commit is contained in:
Robby Russell 2013-06-25 09:25:38 -07:00
commit a8c0c4de06
4 changed files with 153 additions and 0 deletions

4
plugins/git/README.md Normal file
View File

@ -0,0 +1,4 @@
## git
**Maintainer:** [Stibbons](https://github.com/Stibbons)
This plugin adds several git aliases and increase the completion function provided by zsh

62
plugins/git/_git-branch Normal file
View File

@ -0,0 +1,62 @@
#compdef git-branch
_git-branch ()
{
declare l c m d
l='--color --no-color -r -a --all -v --verbose --abbrev --no-abbrev'
c='-l -f --force -t --track --no-track --set-upstream --contains --merged --no-merged'
m='-m -M'
d='-d -D'
declare -a dependent_creation_args
if (( words[(I)-r] == 0 )); then
dependent_creation_args=(
"($l $m $d): :__git_branch_names"
"::start-point:__git_revisions")
fi
declare -a dependent_deletion_args
if (( words[(I)-d] || words[(I)-D] )); then
dependent_creation_args=
dependent_deletion_args=(
'-r[delete only remote-tracking branches]')
if (( words[(I)-r] )); then
dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_remote_branch_names'
else
dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_branch_names'
fi
fi
declare -a dependent_modification_args
if (( words[(I)-m] || words[(I)-M] )); then
dependent_creation_args=
dependent_modification_args=(
':old or new branch name:__git_branch_names'
'::new branch name:__git_branch_names')
fi
_arguments -w -S -s \
"($c $m $d --no-color :)--color=-[turn on branch coloring]:: :__git_color_whens" \
"($c $m $d : --color)--no-color[turn off branch coloring]" \
"($c $m -a --all)-r[list or delete only remote-tracking branches]" \
"($c $m $d : -r)"{-a,--all}"[list both remote-tracking branches and local branches]" \
"($c $m $d : -v --verbose)"{-v,--verbose}'[show SHA1 and commit subject line for each head]' \
"($c $m $d :)--abbrev=[set minimum SHA1 display-length]: :__git_guard_number length" \
"($c $m $d :)--no-abbrev[do not abbreviate sha1s]" \
"($l $m $d)-l[create the branch's reflog]" \
"($l $m $d -f --force)"{-f,--force}"[force the creation of a new branch]" \
"($l $m $d -t --track)"{-t,--track}"[set up configuration so that pull merges from the start point]" \
"($l $m $d)--no-track[override the branch.autosetupmerge configuration variable]" \
"($l $m $d)--set-upstream[set up configuration so that pull merges]" \
"($l $m $d)--contains=[only list branches which contain the specified commit]: :__git_committishs" \
"($l $m $d)--merged=[only list branches which are fully contained by HEAD]: :__git_committishs" \
"($l $m $d)--no-merged=[do not list branches which are fully contained by HEAD]: :__git_committishs" \
$dependent_creation_args \
"($l $c $d -M)-m[rename a branch and the corresponding reflog]" \
"($l $c $d -m)-M[rename a branch even if the new branch-name already exists]" \
$dependent_modification_args \
"($l $c $m -D)-d[delete a fully merged branch]" \
"($l $c $m -d)-D[delete a branch]" \
$dependent_deletion_args
}

74
plugins/git/_git-remote Normal file
View File

@ -0,0 +1,74 @@
#compdef git-remote
# NOTE: --track is undocumented.
# TODO: --track, -t, --master, and -m should take remote branches, I guess.
# NOTE: --master is undocumented.
# NOTE: --fetch is undocumented.
_git-remote () {
local curcontext=$curcontext state line
declare -A opt_args
_arguments -C \
':command:->command' \
'*::options:->options' && ret=0
case $state in
(command)
declare -a commands
commands=(
'add:add a new remote'
'show:show information about a given remote'
'prune:delete all stale tracking branches for a given remote'
'update:fetch updates for a set of remotes'
'rm:remove a remote from .git/config and all associated tracking branches'
'rename:rename a remote from .git/config and update all associated tracking branches'
'set-head:sets or deletes the default branch'
'set-branches:changes the list of branches tracked by the named remote.'
'set-url:changes URL remote points to.'
)
_describe -t commands 'sub-command' commands && ret=0
;;
(options)
case $line[1] in
(add)
_arguments \
'*'{--track,-t}'[track given branch instead of default glob refspec]:branch:__git_branch_names' \
'(--master -m)'{--master,-m}'[set the remote'\''s HEAD to point to given master branch]:branch:__git_branch_names' \
'(--fetch -f)'{--fetch,-f}'[run git-fetch on the new remote after it has been created]' \
':branch name:__git_remotes' \
':url:_urls' && ret=0
;;
(show)
_arguments \
'-n[do not contact the remote for a list of branches]' \
':remote:__git_remotes' && ret=0
;;
(prune)
_arguments \
'(--dry-run -n)'{-n,--dry-run}'[do not actually prune, only list what would be done]' \
':remote:__git_remotes' && ret=0
;;
(update)
__git_remote-groups && ret=0
;;
(rm)
__git_remotes && ret=0
;;
(rename)
__git_remotes && ret=0
;;
(set-url)
_arguments \
'*--push[manipulate push URLs]' \
'(--add)--add[add URL]' \
'(--delete)--delete[delete URLs]' \
':branch name:__git_remotes' \
':url:_urls' && ret=0
;;
esac
;;
esac
}

View File

@ -37,6 +37,12 @@ alias grset='git remote set-url'
compdef _git grset=git-remote
alias grup='git remote update'
compdef _git grset=git-remote
alias grbi='git rebase -i'
compdef _git grbi=git-rebase
alias grbc='git rebase --continue'
compdef _git grbc=git-rebase
alias grba='git rebase --abort'
compdef _git grba=git-rebase
alias gb='git branch'
compdef _git gb=git-branch
alias gba='git branch -a'
@ -65,6 +71,13 @@ alias grhh='git reset HEAD --hard'
alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
alias gf='git ls-files | grep'
alias gpoat='git push origin --all && git push origin --tags'
alias gmt='git mergetool --no-prompt'
compdef _git gm=git-mergetool
alias gg='git gui citool'
alias gga='git gui citool --amend'
alias gk='gitk --all --branches'
alias gss='git stash show --text'
# Will cd into the top of the current repository
# or submodule.