33c0de7add12b050b94fd6f2f988e9b5547d172c

Author
Miguel Hargreaves Pimenta <jmiguelpimenta@icloud.com>
Committer
GitHub <noreply@github.com>
Date

Message

refactor(git): sort git aliases alphabetically (#9743)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/git/README.md b/plugins/git/README.md
  2index d18531955981e67cc07ea89a6eb1bef9a60f073f..0b757c4812f7685d4f9b5e821d1039291eef0c37 100644
  3--- a/plugins/git/README.md
  4+++ b/plugins/git/README.md
  5@@ -10,213 +10,214 @@ plugins=(... git)
  6 
  7 ## Aliases
  8 
  9-| Alias                | Command                                                                                                                                                                                  |
 10-| :------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
 11-| g                    | git                                                                                                                                                                                      |
 12-| ga                   | git add                                                                                                                                                                                  |
 13-| gaa                  | git add --all                                                                                                                                                                            |
 14-| gapa                 | git add --patch                                                                                                                                                                          |
 15-| gau                  | git add --update                                                                                                                                                                         |
 16-| gav                  | git add --verbose                                                                                                                                                                        |
 17-| gap                  | git apply                                                                                                                                                                                |
 18-| gapt                 | git apply --3way                                                                                                                                                                         |
 19-| gb                   | git branch                                                                                                                                                                               |
 20-| gba                  | git branch --all                                                                                                                                                                         |
 21-| gbd                  | git branch --delete                                                                                                                                                                      |
 22-| gbda                 | git branch --no-color --merged \| grep -vE "^([+*]\|\s*(<span>$</span>(git_main_branch)\|<span>$</span>(git_develop_branch))\s*<span>$</span>)" \| xargs git branch --delete 2>/dev/null |
 23-| gbD                  | git branch --delete --force                                                                                                                                                              |
 24-| gbg                  | git branch -vv | grep ": gone\]"                                                                                                                                                         |
 25-| gbgd                 | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d                                                                                             |
 26-| gbgD                 | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D                                                                                             |
 27-| gbl                  | git blame -b -w                                                                                                                                                                          |
 28-| gbnm                 | git branch --no-merged                                                                                                                                                                   |
 29-| gbr                  | git branch --remote                                                                                                                                                                      |
 30-| gbs                  | git bisect                                                                                                                                                                               |
 31-| gbsb                 | git bisect bad                                                                                                                                                                           |
 32-| gbsg                 | git bisect good                                                                                                                                                                          |
 33-| gbsr                 | git bisect reset                                                                                                                                                                         |
 34-| gbss                 | git bisect start                                                                                                                                                                         |
 35-| gc                   | git commit --verbose                                                                                                                                                                     |
 36-| gc!                  | git commit --verbose --amend                                                                                                                                                             |
 37-| gcn!                 | git commit --verbose --no-edit --amend                                                                                                                                                   |
 38-| gca                  | git commit --verbose --all                                                                                                                                                               |
 39-| gca!                 | git commit --verbose --all --amend                                                                                                                                                       |
 40-| gcan!                | git commit --verbose --all --no-edit --amend                                                                                                                                             |
 41-| gcans!               | git commit --verbose --all --signoff --no-edit --amend                                                                                                                                   |
 42-| gcam                 | git commit --all --message                                                                                                                                                               |
 43-| gcas                 | git commit --all --signoff                                                                                                                                                               |
 44-| gcasm                | git commit --all --signoff --message                                                                                                                                                     |
 45-| gcsm                 | git commit --signoff --message                                                                                                                                                           |
 46-| gcb                  | git checkout -b                                                                                                                                                                          |
 47-| gcf                  | git config --list                                                                                                                                                                        |
 48-| gcl                  | git clone --recurse-submodules                                                                                                                                                           |
 49-| gccd                 | git clone --recurse-submodules "<span>$</span>@" && cd "<span>$</span>(basename <span>$</span>\_ .git)"                                                                                  |
 50-| gclean               | git clean --interactive -d                                                                                                                                                               |
 51-| gpristine            | git reset --hard && git clean -dffx                                                                                                                                                      |
 52-| gcm                  | git checkout $(git_main_branch)                                                                                                                                                          |
 53-| gcd                  | git checkout $(git_develop_branch)                                                                                                                                                       |
 54-| gcmsg                | git commit --message                                                                                                                                                                     |
 55-| gco                  | git checkout                                                                                                                                                                             |
 56-| gcor                 | git checkout --recurse-submodules                                                                                                                                                        |
 57-| gcount               | git shortlog --summary -n                                                                                                                                                                |
 58-| gcp                  | git cherry-pick                                                                                                                                                                          |
 59-| gcpa                 | git cherry-pick --abort                                                                                                                                                                  |
 60-| gcpc                 | git cherry-pick --continue                                                                                                                                                               |
 61-| gcs                  | git commit -S                                                                                                                                                                            |
 62-| gcss                 | git commit -S -s                                                                                                                                                                         |
 63-| gcssm                | git commit -S -s -m                                                                                                                                                                      |
 64-| gd                   | git diff                                                                                                                                                                                 |
 65-| gdca                 | git diff --cached                                                                                                                                                                        |
 66-| gdcw                 | git diff --cached --word-diff                                                                                                                                                            |
 67-| gdct                 | git describe --tags $(git rev-list --tags --max-count=1)                                                                                                                                 |
 68-| gds                  | git diff --staged                                                                                                                                                                        |
 69-| gdt                  | git diff-tree --no-commit-id --name-only -r                                                                                                                                              |
 70-| gdnolock             | git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock"                                                                                                                            |
 71-| gdup                 | git diff @{upstream}                                                                                                                                                                     |
 72-| gdv                  | git diff -w $@ \| view -                                                                                                                                                                 |
 73-| gdw                  | git diff --word-diff                                                                                                                                                                     |
 74-| gf                   | git fetch                                                                                                                                                                                |
 75-| gfa                  | git fetch --all --prune                                                                                                                                                                  |
 76-| gfg                  | git ls-files \| grep                                                                                                                                                                     |
 77-| gfo                  | git fetch origin                                                                                                                                                                         |
 78-| gg                   | git gui citool                                                                                                                                                                           |
 79-| gga                  | git gui citool --amend                                                                                                                                                                   |
 80-| ggf                  | git push --force origin $(current_branch)                                                                                                                                                |
 81-| ggfl                 | git push --force-with-lease origin $(current_branch)                                                                                                                                     |
 82-| ggl                  | git pull origin $(current_branch)                                                                                                                                                        |
 83-| ggp                  | git push origin $(current_branch)                                                                                                                                                        |
 84-| ggpnp                | ggl && ggp                                                                                                                                                                               |
 85-| ggpull               | git pull origin "$(git_current_branch)"                                                                                                                                                  |
 86-| ggpur                | ggu                                                                                                                                                                                      |
 87-| ggpush               | git push origin "$(git_current_branch)"                                                                                                                                                  |
 88-| ggsup                | git branch --set-upstream-to=origin/$(git_current_branch)                                                                                                                                |
 89-| ggu                  | git pull --rebase origin $(current_branch)                                                                                                                                               |
 90-| gpsup                | git push --set-upstream origin $(git_current_branch)                                                                                                                                     |
 91-| gpsupf               | git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes (git version >= 2.30)                                                                        |
 92-| gpsupf               | git push --set-upstream origin $(git_current_branch) --force-with-lease (git version < 2.30)                                                                                             |
 93-| ghh                  | git help                                                                                                                                                                                 |
 94-| gignore              | git update-index --assume-unchanged                                                                                                                                                      |
 95-| gignored             | git ls-files -v \| grep "^[[:lower:]]"                                                                                                                                                   |
 96-| git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk                                                                                                                           |
 97-| gk                   | gitk --all --branches &!                                                                                                                                                                 |
 98-| gke                  | gitk --all $(git log --walk-reflogs --pretty=%h) &!                                                                                                                                      |
 99-| gl                   | git pull                                                                                                                                                                                 |
100-| glg                  | git log --stat                                                                                                                                                                           |
101-| glgp                 | git log --stat --patch                                                                                                                                                                   |
102-| glgg                 | git log --graph                                                                                                                                                                          |
103-| glgga                | git log --graph --decorate --all                                                                                                                                                         |
104-| glgm                 | git log --graph --max-count=10                                                                                                                                                           |
105diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
106index d04edea5e3844e59281d801fb832d2cb8bfc8c91..b321ce7b044c633c765cb48b05a359efb4f73316 100644
107--- a/plugins/git/git.plugin.zsh
108+++ b/plugins/git/git.plugin.zsh
109@@ -3,7 +3,9 @@ autoload -Uz is-at-least
110 git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
111 
112 #
113-# Functions
114+# Functions Current
115+# (sorted alphabetically by function name)
116+# (order should follow README)
117 #
118 
119 # The name of the current branch
120@@ -14,27 +16,17 @@ function current_branch() {
121   git_current_branch
122 }
123 
124-# Pretty log messages
125-function _git_log_prettily(){
126-  if ! [ -z $1 ]; then
127-    git log --pretty=$1
128-  fi
129-}
130-compdef _git _git_log_prettily=git-log
131-
132-# Warn if the current branch is a WIP
133-function work_in_progress() {
134-  command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
135-}
136-
137-# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one
138-function gunwipall() {
139-  local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H)
140-  
141-  # Check if a commit without "--wip--" was found and it's not the same as HEAD
142-  if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then
143-    git reset $_commit || return 1
144-  fi
145+# Check for develop and similarly named branches
146+function git_develop_branch() {
147+  command git rev-parse --git-dir &>/dev/null || return
148+  local branch
149+  for branch in dev devel development; do
150+    if command git show-ref -q --verify refs/heads/$branch; then
151+      echo $branch
152+      return
153+    fi
154+  done
155+  echo develop
156 }
157 
158 # Check if main exists and use instead of master
159@@ -50,64 +42,101 @@ function git_main_branch() {
160   echo master
161 }
162 
163-# Check for develop and similarly named branches
164-function git_develop_branch() {
165-  command git rev-parse --git-dir &>/dev/null || return
166-  local branch
167-  for branch in dev devel development; do
168-    if command git show-ref -q --verify refs/heads/$branch; then
169-      echo $branch
170-      return
171-    fi
172-  done
173-  echo develop
174+function grename() {
175+  if [[ -z "$1" || -z "$2" ]]; then
176+    echo "Usage: $0 old_branch new_branch"
177+    return 1
178+  fi
179+
180+  # Rename branch locally
181+  git branch -m "$1" "$2"
182+  # Rename branch in origin remote
183+  if git push origin :"$1"; then
184+    git push --set-upstream origin "$2"
185+  fi
186+}
187+
188+#
189+# Functions Work in Progress (WIP)
190+# (sorted alphabetically by function name)
191+# (order should follow README)
192+#
193+
194+# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one
195+function gunwipall() {
196+  local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H)
197+
198+  # Check if a commit without "--wip--" was found and it's not the same as HEAD
199+  if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then
200+    git reset $_commit || return 1
201+  fi
202+}
203+
204+# Warn if the current branch is a WIP
205+function work_in_progress() {
206+  command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
207 }
208