a8c0c4de06bf6f1d087153b2166d3b91882835a6

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #1864 from Stibbons/gsemet_push_git_plugin

Improvement in the git plugin

Diff

  1diff --git a/plugins/git/README.md b/plugins/git/README.md
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..8462dda1cdff0af675651fb744c6ba91258b7ad7
  4--- /dev/null
  5+++ b/plugins/git/README.md
  6@@ -0,0 +1,4 @@
  7+## git
  8+**Maintainer:** [Stibbons](https://github.com/Stibbons)
  9+
 10+This plugin adds several git aliases and increase the completion function provided by zsh
 11diff --git a/plugins/git/_git-branch b/plugins/git/_git-branch
 12new file mode 100644
 13index 0000000000000000000000000000000000000000..86d03bc30eeb1a7c0349b20bfcf83f46b95f6d8c
 14--- /dev/null
 15+++ b/plugins/git/_git-branch
 16@@ -0,0 +1,62 @@
 17+#compdef git-branch
 18+
 19+_git-branch () 
 20+{
 21+  declare l c m d
 22+
 23+  l='--color --no-color -r -a --all -v --verbose --abbrev --no-abbrev'
 24+  c='-l -f --force -t --track --no-track --set-upstream --contains --merged --no-merged'
 25+  m='-m -M'
 26+  d='-d -D'
 27+
 28+  declare -a dependent_creation_args
 29+  if (( words[(I)-r] == 0 )); then
 30+    dependent_creation_args=(
 31+      "($l $m $d): :__git_branch_names"
 32+      "::start-point:__git_revisions")
 33+  fi
 34+
 35+  declare -a dependent_deletion_args
 36+  if (( words[(I)-d] || words[(I)-D] )); then
 37+    dependent_creation_args=
 38+    dependent_deletion_args=(
 39+      '-r[delete only remote-tracking branches]')
 40+    if (( words[(I)-r] )); then
 41+      dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_remote_branch_names'
 42+    else
 43+      dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_branch_names'
 44+    fi
 45+  fi
 46+
 47+  declare -a dependent_modification_args
 48+  if (( words[(I)-m] || words[(I)-M] )); then
 49+    dependent_creation_args=
 50+    dependent_modification_args=(
 51+      ':old or new branch name:__git_branch_names'
 52+      '::new branch name:__git_branch_names')
 53+  fi
 54+
 55+  _arguments -w -S -s \
 56+    "($c $m $d --no-color :)--color=-[turn on branch coloring]:: :__git_color_whens" \
 57+    "($c $m $d : --color)--no-color[turn off branch coloring]" \
 58+    "($c $m      -a --all)-r[list or delete only remote-tracking branches]" \
 59+    "($c $m $d : -r)"{-a,--all}"[list both remote-tracking branches and local branches]" \
 60+    "($c $m $d : -v --verbose)"{-v,--verbose}'[show SHA1 and commit subject line for each head]' \
 61+    "($c $m $d :)--abbrev=[set minimum SHA1 display-length]: :__git_guard_number length" \
 62+    "($c $m $d :)--no-abbrev[do not abbreviate sha1s]" \
 63+    "($l $m $d)-l[create the branch's reflog]" \
 64+    "($l $m $d -f --force)"{-f,--force}"[force the creation of a new branch]" \
 65+    "($l $m $d -t --track)"{-t,--track}"[set up configuration so that pull merges from the start point]" \
 66+    "($l $m $d)--no-track[override the branch.autosetupmerge configuration variable]" \
 67+    "($l $m $d)--set-upstream[set up configuration so that pull merges]" \
 68+    "($l $m $d)--contains=[only list branches which contain the specified commit]: :__git_committishs" \
 69+    "($l $m $d)--merged=[only list branches which are fully contained by HEAD]: :__git_committishs" \
 70+    "($l $m $d)--no-merged=[do not list branches which are fully contained by HEAD]: :__git_committishs" \
 71+    $dependent_creation_args \
 72+    "($l $c $d -M)-m[rename a branch and the corresponding reflog]" \
 73+    "($l $c $d -m)-M[rename a branch even if the new branch-name already exists]" \
 74+    $dependent_modification_args \
 75+    "($l $c $m -D)-d[delete a fully merged branch]" \
 76+    "($l $c $m -d)-D[delete a branch]" \
 77+    $dependent_deletion_args
 78+}
 79diff --git a/plugins/git/_git-remote b/plugins/git/_git-remote
 80new file mode 100644
 81index 0000000000000000000000000000000000000000..4ba62a357b8872baf2e64d643668144ec4a77985
 82--- /dev/null
 83+++ b/plugins/git/_git-remote
 84@@ -0,0 +1,74 @@
 85+#compdef git-remote
 86+
 87+# NOTE: --track is undocumented.
 88+# TODO: --track, -t, --master, and -m should take remote branches, I guess.
 89+# NOTE: --master is undocumented.
 90+# NOTE: --fetch is undocumented.
 91+_git-remote () {
 92+  local curcontext=$curcontext state line
 93+  declare -A opt_args
 94+
 95+  _arguments -C \
 96+    ':command:->command' \
 97+    '*::options:->options' && ret=0
 98+
 99+  case $state in
100+    (command)
101+      declare -a commands
102+
103+      commands=(
104+        'add:add a new remote'
105+        'show:show information about a given remote'
106+        'prune:delete all stale tracking branches for a given remote'
107+        'update:fetch updates for a set of remotes'
108+        'rm:remove a remote from .git/config and all associated tracking branches'
109+        'rename:rename a remote from .git/config and update all associated tracking branches'
110+        'set-head:sets or deletes the default branch'
111+        'set-branches:changes the list of branches tracked by the named remote.'
112+        'set-url:changes URL remote points to.'
113+        )
114+
115+      _describe -t commands 'sub-command' commands && ret=0
116+      ;;
117+    (options)
118+      case $line[1] in
119+        (add)
120+          _arguments \
121+            '*'{--track,-t}'[track given branch instead of default glob refspec]:branch:__git_branch_names' \
122+            '(--master -m)'{--master,-m}'[set the remote'\''s HEAD to point to given master branch]:branch:__git_branch_names' \
123+            '(--fetch -f)'{--fetch,-f}'[run git-fetch on the new remote after it has been created]' \
124+            ':branch name:__git_remotes' \
125+            ':url:_urls' && ret=0
126+          ;;
127+        (show)
128+          _arguments \
129+            '-n[do not contact the remote for a list of branches]' \
130+            ':remote:__git_remotes' && ret=0
131+          ;;
132+        (prune)
133+          _arguments \
134+            '(--dry-run -n)'{-n,--dry-run}'[do not actually prune, only list what would be done]' \
135+            ':remote:__git_remotes' && ret=0
136+          ;;
137+        (update)
138+          __git_remote-groups && ret=0
139+          ;;
140+        (rm)
141+          __git_remotes && ret=0
142+          ;;
143+        (rename)
144+          __git_remotes && ret=0
145+          ;;
146+        (set-url)
147+          _arguments \
148+            '*--push[manipulate push URLs]' \
149+            '(--add)--add[add URL]' \
150+            '(--delete)--delete[delete URLs]' \
151+            ':branch name:__git_remotes' \
152+            ':url:_urls' && ret=0
153+          ;;
154+          
155+      esac
156+      ;;
157+  esac
158+}
159diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
160index 6f2f59df30b6de419c16b502f4c3854fb6bc874e..0d7e182e42ff7a798d775b2b8138acbc6decf997 100644
161--- a/plugins/git/git.plugin.zsh
162+++ b/plugins/git/git.plugin.zsh
163@@ -37,6 +37,12 @@ alias grset='git remote set-url'
164 compdef _git grset=git-remote
165 alias grup='git remote update'
166 compdef _git grset=git-remote
167+alias grbi='git rebase -i'
168+compdef _git grbi=git-rebase
169+alias grbc='git rebase --continue'
170+compdef _git grbc=git-rebase
171+alias grba='git rebase --abort'
172+compdef _git grba=git-rebase
173 alias gb='git branch'
174 compdef _git gb=git-branch
175 alias gba='git branch -a'
176@@ -65,6 +71,13 @@ alias grhh='git reset HEAD --hard'
177 alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
178 alias gf='git ls-files | grep'
179 alias gpoat='git push origin --all && git push origin --tags'
180+alias gmt='git mergetool --no-prompt'
181+compdef _git gm=git-mergetool
182+
183+alias gg='git gui citool'
184+alias gga='git gui citool --amend'
185+alias gk='gitk --all --branches'
186+alias gss='git stash show --text'
187 
188 # Will cd into the top of the current repository
189 # or submodule.