summaryrefslogtreecommitdiff
path: root/plugins/git/git.plugin.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/git/git.plugin.zsh')
-rw-r--r--plugins/git/git.plugin.zsh113
1 files changed, 64 insertions, 49 deletions
diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
index 2a824444b..9ef60d69a 100644
--- a/plugins/git/git.plugin.zsh
+++ b/plugins/git/git.plugin.zsh
@@ -8,14 +8,6 @@ git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
# (order should follow README)
#
-# The name of the current branch
-# Back-compatibility wrapper for when this function was defined here in
-# the plugin, before being pulled in to core lib/git.zsh as git_current_branch()
-# to fix the core -> git plugin dependency.
-function current_branch() {
- git_current_branch
-}
-
# Check for develop and similarly named branches
function git_develop_branch() {
command git rev-parse --git-dir &>/dev/null || return
@@ -31,16 +23,26 @@ function git_develop_branch() {
return 1
}
-# Check if main exists and use instead of master
+# Get the default branch name from common branch names or fallback to remote HEAD
function git_main_branch() {
command git rev-parse --git-dir &>/dev/null || return
- local ref
- for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master}; do
+
+ local remote ref
+
+ for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,stable,master}; do
if command git show-ref -q --verify $ref; then
echo ${ref:t}
return 0
fi
done
+
+ # Fallback: try to get the default branch from remote HEAD symbolic refs
+ for remote in origin upstream; do
+ ref=$(command git rev-parse --abbrev-ref $remote/HEAD 2>/dev/null)
+ if [[ $ref == $remote/* ]]; then
+ echo ${ref#"$remote/"}; return 0
+ fi
+ done
# If no main branch was found, fall back to master but return error
echo master
@@ -86,13 +88,13 @@ function work_in_progress() {
# Aliases
# (sorted alphabetically by command)
# (order should follow README)
-# (in some cases force the alisas order to match README, like for example gke and gk)
+# (in some cases force the alias order to match README, like for example gke and gk)
#
alias grt='cd "$(git rev-parse --show-toplevel || echo .)"'
function ggpnp() {
- if [[ "$#" == 0 ]]; then
+ if [[ $# == 0 ]]; then
ggl && ggp
else
ggl "${*}" && ggp "${*}"
@@ -147,8 +149,8 @@ function gbds() {
done
}
-alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d'
-alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D'
+alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | cut -c 3- | awk '"'"'{print $1}'"'"' | xargs git branch -d'
+alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | cut -c 3- | awk '"'"'{print $1}'"'"' | xargs git branch -D'
alias gbm='git branch --move'
alias gbnm='git branch --no-merged'
alias gbr='git branch --remote'
@@ -157,6 +159,7 @@ alias gbg='LANG=C git branch -vv | grep ": gone\]"'
alias gco='git checkout'
alias gcor='git checkout --recurse-submodules'
alias gcb='git checkout -b'
+alias gcB='git checkout -B'
alias gcd='git checkout $(git_develop_branch)'
alias gcm='git checkout $(git_main_branch)'
alias gcp='git cherry-pick'
@@ -164,6 +167,7 @@ alias gcpa='git cherry-pick --abort'
alias gcpc='git cherry-pick --continue'
alias gclean='git clean --interactive -d'
alias gcl='git clone --recurse-submodules'
+alias gclf='git clone --recursive --shallow-submodules --filter=blob:none --also-filter-submodules'
function gccd() {
setopt localoptions extendedglob
@@ -193,9 +197,12 @@ alias gca='git commit --verbose --all'
alias gca!='git commit --verbose --all --amend'
alias gcan!='git commit --verbose --all --no-edit --amend'
alias gcans!='git commit --verbose --all --signoff --no-edit --amend'
+alias gcann!='git commit --verbose --all --date=now --no-edit --amend'
alias gc!='git commit --verbose --amend'
+alias gcn='git commit --verbose --no-edit'
alias gcn!='git commit --verbose --no-edit --amend'
alias gcf='git config --list'
+alias gcfu='git commit --fixup'
alias gdct='git describe --tags $(git rev-list --tags --max-count=1)'
alias gd='git diff'
alias gdca='git diff --cached'
@@ -217,8 +224,8 @@ alias gdt='git diff-tree --no-commit-id --name-only -r'
alias gf='git fetch'
# --jobs=<n> was added in git 2.8
is-at-least 2.8 "$git_version" \
- && alias gfa='git fetch --all --prune --jobs=10' \
- || alias gfa='git fetch --all --prune'
+ && alias gfa='git fetch --all --tags --prune --jobs=10' \
+ || alias gfa='git fetch --all --tags --prune'
alias gfo='git fetch origin'
alias gg='git gui citool'
alias gga='git gui citool --amend'
@@ -250,7 +257,9 @@ alias gignored='git ls-files -v | grep "^[[:lower:]]"'
alias gfg='git ls-files | grep'
alias gm='git merge'
alias gma='git merge --abort'
+alias gmc='git merge --continue'
alias gms="git merge --squash"
+alias gmff="git merge --ff-only"
alias gmom='git merge origin/$(git_main_branch)'
alias gmum='git merge upstream/$(git_main_branch)'
alias gmtl='git mergetool --no-prompt'
@@ -263,24 +272,28 @@ alias gpra='git pull --rebase --autostash'
alias gprav='git pull --rebase --autostash -v'
function ggu() {
- [[ "$#" != 1 ]] && local b="$(git_current_branch)"
- git pull --rebase origin "${b:=$1}"
+ local b
+ [[ $# != 1 ]] && b="$(git_current_branch)"
+ git pull --rebase origin "${b:-$1}"
}
-compdef _git ggu=git-checkout
+compdef _git ggu=git-pull
alias gprom='git pull --rebase origin $(git_main_branch)'
alias gpromi='git pull --rebase=interactive origin $(git_main_branch)'
+alias gprum='git pull --rebase upstream $(git_main_branch)'
+alias gprumi='git pull --rebase=interactive upstream $(git_main_branch)'
alias ggpull='git pull origin "$(git_current_branch)"'
function ggl() {
- if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
+ if [[ $# != 0 ]] && [[ $# != 1 ]]; then
git pull origin "${*}"
else
- [[ "$#" == 0 ]] && local b="$(git_current_branch)"
- git pull origin "${b:=$1}"
+ local b
+ [[ $# == 0 ]] && b="$(git_current_branch)"
+ git pull origin "${b:-$1}"
fi
}
-compdef _git ggl=git-checkout
+compdef _git ggl=git-pull
alias gluc='git pull upstream $(git_current_branch)'
alias glum='git pull upstream $(git_main_branch)'
@@ -288,10 +301,11 @@ alias gp='git push'
alias gpd='git push --dry-run'
function ggf() {
- [[ "$#" != 1 ]] && local b="$(git_current_branch)"
- git push --force origin "${b:=$1}"
+ local b
+ [[ $# != 1 ]] && b="$(git_current_branch)"
+ git push --force origin "${b:-$1}"
}
-compdef _git ggf=git-checkout
+compdef _git ggf=git-push
alias gpf!='git push --force'
is-at-least 2.30 "$git_version" \
@@ -299,10 +313,11 @@ is-at-least 2.30 "$git_version" \
|| alias gpf='git push --force-with-lease'
function ggfl() {
- [[ "$#" != 1 ]] && local b="$(git_current_branch)"
- git push --force-with-lease origin "${b:=$1}"
+ local b
+ [[ $# != 1 ]] && b="$(git_current_branch)"
+ git push --force-with-lease origin "${b:-$1}"
}
-compdef _git ggfl=git-checkout
+compdef _git ggfl=git-push
alias gpsup='git push --set-upstream origin $(git_current_branch)'
is-at-least 2.30 "$git_version" \
@@ -314,14 +329,15 @@ alias gpod='git push origin --delete'
alias ggpush='git push origin "$(git_current_branch)"'
function ggp() {
- if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
+ if [[ $# != 0 ]] && [[ $# != 1 ]]; then
git push origin "${*}"
else
- [[ "$#" == 0 ]] && local b="$(git_current_branch)"
- git push origin "${b:=$1}"
+ local b
+ [[ $# == 0 ]] && b="$(git_current_branch)"
+ git push origin "${b:-$1}"
fi
}
-compdef _git ggp=git-checkout
+compdef _git ggp=git-push
alias gpu='git push upstream'
alias grb='git rebase'
@@ -333,6 +349,8 @@ alias grbs='git rebase --skip'
alias grbd='git rebase $(git_develop_branch)'
alias grbm='git rebase $(git_main_branch)'
alias grbom='git rebase origin/$(git_main_branch)'
+alias grbum='git rebase upstream/$(git_main_branch)'
+alias grf='git reflog'
alias gr='git remote'
alias grv='git remote --verbose'
alias gra='git remote add'
@@ -346,12 +364,15 @@ alias grhh='git reset --hard'
alias grhk='git reset --keep'
alias grhs='git reset --soft'
alias gpristine='git reset --hard && git clean --force -dfx'
+alias gwipe='git reset --hard && git clean --force -df'
alias groh='git reset origin/$(git_current_branch) --hard'
alias grs='git restore'
alias grss='git restore --source'
alias grst='git restore --staged'
alias gunwip='git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1'
alias grev='git revert'
+alias greva='git revert --abort'
+alias grevc='git revert --continue'
alias grm='git rm'
alias grmc='git rm --cached'
alias gcount='git shortlog --summary --numbered'
@@ -385,7 +406,7 @@ alias gts='git tag --sign'
alias gtv='git tag | sort -V'
alias gignore='git update-index --assume-unchanged'
alias gunignore='git update-index --no-assume-unchanged'
-alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
+alias gwch='git log --patch --abbrev-commit --pretty=medium --raw'
alias gwt='git worktree'
alias gwta='git worktree add'
alias gwtls='git worktree list'
@@ -398,19 +419,13 @@ alias gke='\gitk --all $(git log --walk-reflogs --pretty=%h) &!'
unset git_version
-# Logic for adding warnings on deprecated aliases
-local old_alias new_alias
-for old_alias new_alias (
- # TODO(2023-10-19): remove deprecated `git pull --rebase` aliases
- gup gpr
- gupv gprv
- gupa gpra
- gupav gprav
- gupom gprom
- gupomi gpromi
+# Logic for adding warnings on deprecated aliases or functions
+local old_name new_name
+for old_name new_name (
+ current_branch git_current_branch
); do
- aliases[$old_alias]="
- print -Pu2 \"%F{yellow}[oh-my-zsh] '%F{red}${old_alias}%F{yellow}' is a deprecated alias, using '%F{green}${new_alias}%F{yellow}' instead.%f\"
- $new_alias"
+ aliases[$old_name]="
+ print -Pu2 \"%F{yellow}[oh-my-zsh] '%F{red}${old_name}%F{yellow}' is deprecated, using '%F{green}${new_name}%F{yellow}' instead.%f\"
+ $new_name"
done
-unset old_alias new_alias
+unset old_name new_name