a449d53c7e15ca1bcc43952a418bdb9d370c7e21

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

Message

Merge pull request #2790 from ncanceill/plugin-git

[UPDATE] Plugin: git

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/git/README.md b/plugins/git/README.md
  2index 8462dda1cdff0af675651fb744c6ba91258b7ad7..76da2a8aee8a5f4b6f2ac8308faee0f310cf8c75 100644
  3--- a/plugins/git/README.md
  4+++ b/plugins/git/README.md
  5@@ -1,4 +1,10 @@
  6 ## git
  7-**Maintainer:** [Stibbons](https://github.com/Stibbons)
  8 
  9-This plugin adds several git aliases and increase the completion function provided by zsh
 10+**Maintainer:** [@ncanceill](https://github.com/ncanceill)
 11+
 12+This plugin adds many useful aliases and functions.
 13+
 14+### Usage
 15+
 16+See the [wiki](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git) for a list of aliases and functions provided by the plugin.
 17+
 18diff --git a/plugins/git/_git-branch b/plugins/git/_git-branch
 19deleted file mode 100644
 20index 6b9c1a483e92c5c5219a69c6f25f319009db02fd..0000000000000000000000000000000000000000
 21--- a/plugins/git/_git-branch
 22+++ /dev/null
 23@@ -1,83 +0,0 @@
 24-#compdef git-branch
 25-
 26-_git-branch () 
 27-{
 28-  declare l c m d
 29-
 30-  l='--color --no-color -r -a --all -v --verbose --abbrev --no-abbrev'
 31-  c='-l -f --force -t --track --no-track --set-upstream --contains --merged --no-merged'
 32-  m='-m -M'
 33-  d='-d -D'
 34-
 35-  declare -a dependent_creation_args
 36-  if (( words[(I)-r] == 0 )); then
 37-    dependent_creation_args=(
 38-      "($l $m $d): :__git_branch_names"
 39-      "::start-point:__git_revisions")
 40-  fi
 41-
 42-  declare -a dependent_deletion_args
 43-  if (( words[(I)-d] || words[(I)-D] )); then
 44-    dependent_creation_args=
 45-    dependent_deletion_args=(
 46-      '-r[delete only remote-tracking branches]')
 47-    if (( words[(I)-r] )); then
 48-      dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_remote_branch_names'
 49-    else
 50-      dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_branch_names'
 51-    fi
 52-  fi
 53-
 54-  declare -a dependent_modification_args
 55-  if (( words[(I)-m] || words[(I)-M] )); then
 56-    dependent_creation_args=
 57-    dependent_modification_args=(
 58-      ':old or new branch name:__git_branch_names'
 59-      '::new branch name:__git_branch_names')
 60-  fi
 61-
 62-  _arguments -w -S -s \
 63-    "($c $m $d --no-color :)--color=-[turn on branch coloring]:: :__git_color_whens" \
 64-    "($c $m $d : --color)--no-color[turn off branch coloring]" \
 65-    "($c $m      -a --all)-r[list or delete only remote-tracking branches]" \
 66-    "($c $m $d : -r)"{-a,--all}"[list both remote-tracking branches and local branches]" \
 67-    "($c $m $d : -v --verbose)"{-v,--verbose}'[show SHA1 and commit subject line for each head]' \
 68-    "($c $m $d :)--abbrev=[set minimum SHA1 display-length]: :__git_guard_number length" \
 69-    "($c $m $d :)--no-abbrev[do not abbreviate sha1s]" \
 70-    "($l $m $d)-l[create the branch's reflog]" \
 71-    "($l $m $d -f --force)"{-f,--force}"[force the creation of a new branch]" \
 72-    "($l $m $d -t --track)"{-t,--track}"[set up configuration so that pull merges from the start point]" \
 73-    "($l $m $d)--no-track[override the branch.autosetupmerge configuration variable]" \
 74-    "($l $m $d)--set-upstream[set up configuration so that pull merges]" \
 75-    "($l $m $d)--contains=[only list branches which contain the specified commit]: :__git_committishs" \
 76-    "($l $m $d)--merged=[only list branches which are fully contained by HEAD]: :__git_committishs" \
 77-    "($l $m $d)--no-merged=[do not list branches which are fully contained by HEAD]: :__git_committishs" \
 78-    $dependent_creation_args \
 79-    "($l $c $d -M)-m[rename a branch and the corresponding reflog]" \
 80-    "($l $c $d -m)-M[rename a branch even if the new branch-name already exists]" \
 81-    $dependent_modification_args \
 82-    "($l $c $m -D)-d[delete a fully merged branch]" \
 83-    "($l $c $m -d)-D[delete a branch]" \
 84-    $dependent_deletion_args
 85-}
 86-
 87-(( $+functions[__git_ignore_line] )) ||
 88-__git_ignore_line () {
 89-  declare -a ignored
 90-  ignored=()
 91-  ((CURRENT > 1)) &&
 92-    ignored+=(${line[1,CURRENT-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
 93-  ((CURRENT < $#line)) &&
 94-    ignored+=(${line[CURRENT+1,-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
 95-  $* -F ignored
 96-}
 97-
 98-(( $+functions[__git_ignore_line_inside_arguments] )) ||
 99-__git_ignore_line_inside_arguments () {
100-  declare -a compadd_opts
101-
102-  zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F:
103-
104-  __git_ignore_line $* $compadd_opts
105-}
106-
107diff --git a/plugins/git/_git-remote b/plugins/git/_git-remote
108deleted file mode 100644
109index 4ba62a357b8872baf2e64d643668144ec4a77985..0000000000000000000000000000000000000000
110--- a/plugins/git/_git-remote
111+++ /dev/null
112@@ -1,74 +0,0 @@
113-#compdef git-remote
114-
115-# NOTE: --track is undocumented.
116-# TODO: --track, -t, --master, and -m should take remote branches, I guess.
117-# NOTE: --master is undocumented.
118-# NOTE: --fetch is undocumented.
119-_git-remote () {
120-  local curcontext=$curcontext state line
121-  declare -A opt_args
122-
123-  _arguments -C \
124-    ':command:->command' \
125-    '*::options:->options' && ret=0
126-
127-  case $state in
128-    (command)
129-      declare -a commands
130-
131-      commands=(
132-        'add:add a new remote'
133-        'show:show information about a given remote'
134-        'prune:delete all stale tracking branches for a given remote'
135-        'update:fetch updates for a set of remotes'
136-        'rm:remove a remote from .git/config and all associated tracking branches'
137-        'rename:rename a remote from .git/config and update all associated tracking branches'
138-        'set-head:sets or deletes the default branch'
139-        'set-branches:changes the list of branches tracked by the named remote.'
140-        'set-url:changes URL remote points to.'
141-        )
142-
143-      _describe -t commands 'sub-command' commands && ret=0
144-      ;;
145-    (options)
146-      case $line[1] in
147-        (add)
148-          _arguments \
149-            '*'{--track,-t}'[track given branch instead of default glob refspec]:branch:__git_branch_names' \
150-            '(--master -m)'{--master,-m}'[set the remote'\''s HEAD to point to given master branch]:branch:__git_branch_names' \
151-            '(--fetch -f)'{--fetch,-f}'[run git-fetch on the new remote after it has been created]' \
152-            ':branch name:__git_remotes' \
153-            ':url:_urls' && ret=0
154-          ;;
155-        (show)
156-          _arguments \
157-            '-n[do not contact the remote for a list of branches]' \
158-            ':remote:__git_remotes' && ret=0
159-          ;;
160-        (prune)
161-          _arguments \
162-            '(--dry-run -n)'{-n,--dry-run}'[do not actually prune, only list what would be done]' \
163-            ':remote:__git_remotes' && ret=0
164-          ;;
165-        (update)
166-          __git_remote-groups && ret=0
167-          ;;
168-        (rm)
169-          __git_remotes && ret=0
170-          ;;
171-        (rename)
172-          __git_remotes && ret=0
173-          ;;
174-        (set-url)
175-          _arguments \
176-            '*--push[manipulate push URLs]' \
177-            '(--add)--add[add URL]' \
178-            '(--delete)--delete[delete URLs]' \
179-            ':branch name:__git_remotes' \
180-            ':url:_urls' && ret=0
181-          ;;
182-          
183-      esac
184-      ;;
185-  esac
186-}
187diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
188index 9da44881457b2eec4669fc5797468196eb9760cf..e42e096883ec829c52c562b188717c4f177e6d6c 100644
189--- a/plugins/git/git.plugin.zsh
190+++ b/plugins/git/git.plugin.zsh
191@@ -1,177 +1,202 @@
192+# Query/use custom command for `git`.
193+local git_cmd
194+zstyle -s ":vcs_info:git:*:-all-" "command" git_cmd
195+: ${git_cmd:=git}
196+
197+#
198+# Functions
199+#
200+
201+# The current branch name
202+# Usage example: git pull origin $(current_branch)
203+# Using '--quiet' with 'symbolic-ref' will not cause a fatal error (128) if
204+# it's not a symbolic ref, but in a Git repo.
205+function current_branch() {
206+  local ref
207+  ref=$($git_cmd symbolic-ref --quiet HEAD 2> /dev/null)
208+  local ret=$?
209+  if [[ $ret != 0 ]]; then
210+    [[ $ret == 128 ]] && return  # no git repo.
211+    ref=$($git_cmd rev-parse --short HEAD 2> /dev/null) || return
212+  fi
213+  echo ${ref#refs/heads/}
214+}
215+# The list of remotes
216+function current_repository() {
217+  if ! $git_cmd rev-parse --is-inside-work-tree &> /dev/null; then
218+    return
219+  fi
220+  echo $($git_cmd remote -v | cut -d':' -f 2)
221+}
222+# Pretty log messages
223+function _git_log_prettily(){
224+  if ! [ -z $1 ]; then
225+    git log --pretty=$1
226+  fi
227+}
228+# Warn if the current branch is a WIP
229+function work_in_progress() {
230+  if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
231+    echo "WIP!!"
232+  fi
233+}
234+
235+#
236 # Aliases
237+# (sorted alphabetically)
238+#
239+
240 alias g='git'
241-compdef g=git
242-alias gst='git status'
243-compdef _git gst=git-status
244-alias gd='git diff'
245-compdef _git gd=git-diff
246-alias gdc='git diff --cached'
247-compdef _git gdc=git-diff
248-alias gdt='git diff-tree --no-commit-id --name-only -r'
249-compdef _git gdc=git diff-tree --no-commit-id --name-only -r
250-alias gl='git pull'
251-compdef _git gl=git-pull
252-alias gup='git pull --rebase'
253-compdef _git gup=git-fetch
254-alias gp='git push'
255-compdef _git gp=git-push
256-alias gd='git diff'
257-gdv() { git diff -w "$@" | view - }
258-compdef _git gdv=git-diff
259-alias gdt='git difftool'
260+
261+alias ga='git add'
262+
263+alias gb='git branch'
264+alias gba='git branch -a'
265+alias gbda='git branch --merged | command grep -vE "^(\*|\s*master\s*$)" | command xargs -n 1 git branch -d'
266+alias gbl='git blame -b -w'
267+alias gbnm='git branch --no-merged'
268+alias gbr='git branch --remote'
269+alias gbs='git bisect'
270+alias gbsb='git bisect bad'
271+alias gbsg='git bisect good'
272+alias gbsr='git bisect reset'
273+alias gbss='git bisect start'
274+
275 alias gc='git commit -v'
276-compdef _git gc=git-commit
277 alias gc!='git commit -v --amend'
278-compdef _git gc!=git-commit
279 alias gca='git commit -v -a'
280-compdef _git gc=git-commit
281 alias gca!='git commit -v -a --amend'
282-compdef _git gca!=git-commit
283+alias gcan!='git commit -v -a -s --no-edit --amend'
284+alias gcb='git checkout -b'
285+alias gcf='git config --list'
286+alias gcl='git clone --recursive'
287+alias gclean='git reset --hard && git clean -dfx'
288+alias gcm='git checkout master'
289 alias gcmsg='git commit -m'
290-compdef _git gcmsg=git-commit