From 194eb30dc7523f6336ad62738b3f8dc5d7fcb355 Mon Sep 17 00:00:00 2001 From: fj0r <82698591+fj0r@users.noreply.github.com> Date: Sun, 14 May 2023 20:58:02 +0800 Subject: [PATCH] gp: run `git fetch` before `git push` or `git pull` (#490) * gp: run `git fetch` before `git push` or `git pull` * remove useless else --------- Co-authored-by: nash --- modules/git/README.md | 4 +++- modules/git/git-v2.nu | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/git/README.md b/modules/git/README.md index 3b8d30a..50a04e5 100644 --- a/modules/git/README.md +++ b/modules/git/README.md @@ -41,7 +41,9 @@ Pull, push and other related to remote repositories - `--override` just used to trigger a github actions event (in fact, webhooks can also be used) - if branch is specified, we assume it is `git fetch` - unless -u is specified: `git push -u` -- finally, if no branch and above parameters are specified, `git pull` or `git push` will be executed according to the current state. +- finally, if no branch and above parameters are specified + - `git fetch` to update status. + - `git pull` or `git push` will be executed according to the current state. - if both `ahead` and `behind` exist, only `pull` ### ga diff --git a/modules/git/git-v2.nu b/modules/git/git-v2.nu index 49cad55..0fb6918 100644 --- a/modules/git/git-v2.nu +++ b/modules/git/git-v2.nu @@ -122,6 +122,7 @@ export def gp [ git fetch $remote $branch } } else { + git fetch let s = (_git_status) if $s.behind > 0 { let r = if $rebase { [--rebase] } else { [] } @@ -129,8 +130,6 @@ export def gp [ git pull $r $a -v } else if $s.ahead > 0 { git push - } else { - git fetch } } }