浏览代码

feat(git)!: add `force-if-includes` flag (#11481)

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>

Closes #11388

BREAKING CHANGE: `gpf` and `gpsupf` now have the `--force-if-includes` flag if git version is greater than 2.30. It will make force pushes more safer. See https://stackoverflow.com/questions/65837109/when-should-i-use-git-push-force-if-includes
Unnit Metaliya 2 年之前
父节点
当前提交
d48cbb82b1
共有 2 个文件被更改,包括 10 次插入3 次删除
  1. 4 1
      plugins/git/README.md
  2. 6 2
      plugins/git/git.plugin.zsh

+ 4 - 1
plugins/git/README.md

@@ -89,7 +89,8 @@ plugins=(... git)
 | ggsup                | git branch --set-upstream-to=origin/$(git_current_branch)                                                                                                                                |
 | ggsup                | git branch --set-upstream-to=origin/$(git_current_branch)                                                                                                                                |
 | ggu                  | git pull --rebase origin $(current_branch)                                                                                                                                               |
 | ggu                  | git pull --rebase origin $(current_branch)                                                                                                                                               |
 | gpsup                | git push --set-upstream origin $(git_current_branch)                                                                                                                                     |
 | gpsup                | git push --set-upstream origin $(git_current_branch)                                                                                                                                     |
-| gpsupf                | git push --set-upstream origin $(git_current_branch) --force-with-lease                                                                                                                                     |
+| gpsupf               | git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes (git version >= 2.30)                                                                        |
+| gpsupf               | git push --set-upstream origin $(git_current_branch) --force-with-lease (git version < 2.30)                                                                                             |
 | ghh                  | git help                                                                                                                                                                                 |
 | ghh                  | git help                                                                                                                                                                                 |
 | gignore              | git update-index --assume-unchanged                                                                                                                                                      |
 | gignore              | git update-index --assume-unchanged                                                                                                                                                      |
 | gignored             | git ls-files -v \| grep "^[[:lower:]]"                                                                                                                                                   |
 | gignored             | git ls-files -v \| grep "^[[:lower:]]"                                                                                                                                                   |
@@ -120,6 +121,8 @@ plugins=(... git)
 | gp                   | git push                                                                                                                                                                                 |
 | gp                   | git push                                                                                                                                                                                 |
 | gpd                  | git push --dry-run                                                                                                                                                                       |
 | gpd                  | git push --dry-run                                                                                                                                                                       |
 | gpf                  | git push --force-with-lease                                                                                                                                                              |
 | gpf                  | git push --force-with-lease                                                                                                                                                              |
+| gpf                  | git push --force-with-lease --force-if-includes (git version >= 2.30)                                                                                                                    |
+| gpf                  | git push --force-with-lease (git version < 2.30)                                                                                                                                         |
 | gpf!                 | git push --force                                                                                                                                                                         |
 | gpf!                 | git push --force                                                                                                                                                                         |
 | gpoat                | git push origin --all && git push origin --tags                                                                                                                                          |
 | gpoat                | git push origin --all && git push origin --tags                                                                                                                                          |
 | gpr                  | git pull --rebase                                                                                                                                                                        |
 | gpr                  | git pull --rebase                                                                                                                                                                        |

+ 6 - 2
plugins/git/git.plugin.zsh

@@ -199,7 +199,9 @@ alias ggpush='git push origin "$(git_current_branch)"'
 
 
 alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
 alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
 alias gpsup='git push --set-upstream origin $(git_current_branch)'
 alias gpsup='git push --set-upstream origin $(git_current_branch)'
-alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease'
+is-at-least 2.30 "$git_version" \
+  && alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes' \
+  || alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease'
 
 
 alias ghh='git help'
 alias ghh='git help'
 
 
@@ -235,7 +237,9 @@ alias gma='git merge --abort'
 
 
 alias gp='git push'
 alias gp='git push'
 alias gpd='git push --dry-run'
 alias gpd='git push --dry-run'
-alias gpf='git push --force-with-lease'
+is-at-least 2.30 "$git_version" \
+  && alias gpf='git push --force-with-lease --force-if-includes' \
+  || alias gpf='git push --force-with-lease'
 alias gpf!='git push --force'
 alias gpf!='git push --force'
 alias gpoat='git push origin --all && git push origin --tags'
 alias gpoat='git push origin --all && git push origin --tags'
 alias gpr='git pull --rebase'
 alias gpr='git pull --rebase'