mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
git-v2: imporve message of gp
(#738)
Co-authored-by: nash <nash@iffy.me>
This commit is contained in:
parent
490cee7997
commit
551b1816db
1 changed files with 15 additions and 10 deletions
|
@ -12,6 +12,10 @@ def agree [
|
||||||
( if $default_not { [no yes] } else { [yes no] } | input list $prompt) in [yes]
|
( if $default_not { [no yes] } else { [yes no] } | input list $prompt) in [yes]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def tips [ msg ] {
|
||||||
|
print -e $"(ansi light_gray)($msg)(ansi reset)"
|
||||||
|
}
|
||||||
|
|
||||||
def --wrapped with-flag [...flag] {
|
def --wrapped with-flag [...flag] {
|
||||||
if ($in | is-empty) { [] } else { [...$flag $in] }
|
if ($in | is-empty) { [] } else { [...$flag $in] }
|
||||||
}
|
}
|
||||||
|
@ -153,43 +157,44 @@ export def gp [
|
||||||
let m = if $merge { [] } else { [--rebase] }
|
let m = if $merge { [] } else { [--rebase] }
|
||||||
let a = if $autostash {[--autostash]} else {[]}
|
let a = if $autostash {[--autostash]} else {[]}
|
||||||
let branch = if ($branch | is-empty) { (_git_status).branch } else { $branch }
|
let branch = if ($branch | is-empty) { (_git_status).branch } else { $branch }
|
||||||
|
let branch_repr = $'(ansi yellow)($branch)(ansi light_gray)'
|
||||||
let remote = if ($remote|is-empty) { 'origin' } else { $remote }
|
let remote = if ($remote|is-empty) { 'origin' } else { $remote }
|
||||||
let lbs = git branch | lines | each {|x| $x | str substring 2..}
|
let lbs = git branch | lines | each {|x| $x | str substring 2..}
|
||||||
let rbs = remote_braches | each {|x| $x.1}
|
let rbs = remote_braches | each {|x| $x.1}
|
||||||
let prev = (_git_status).branch
|
let prev = (_git_status).branch
|
||||||
if $branch in $rbs {
|
if $branch in $rbs {
|
||||||
if $branch in $lbs {
|
if $branch in $lbs {
|
||||||
let bmsg = '* both local and remote have the branch'
|
let bmsg = $'both local and remote have ($branch_repr) branch'
|
||||||
if $force {
|
if $force {
|
||||||
print $'($bmsg), with --force, push'
|
tips $'($bmsg), with `--force`, push'
|
||||||
git branch -u $'($remote)/($branch)' $branch
|
git branch -u $'($remote)/($branch)' $branch
|
||||||
git push --force
|
git push --force
|
||||||
} else {
|
} else {
|
||||||
print $'($bmsg), pull'
|
tips $'($bmsg), pull'
|
||||||
if $prev != $branch {
|
if $prev != $branch {
|
||||||
print $'* switch to ($branch)'
|
tips $'switch to ($branch_repr)'
|
||||||
git checkout $branch
|
git checkout $branch
|
||||||
}
|
}
|
||||||
git pull ...$m ...$a
|
git pull ...$m ...$a
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print "* local doesn't have that branch, fetch"
|
tips $"local doesn't have ($branch_repr) branch, fetch"
|
||||||
git checkout -b $branch
|
git checkout -b $branch
|
||||||
git fetch $remote $branch
|
git fetch $remote $branch
|
||||||
git branch -u $'($remote)/($branch)' $branch
|
git branch -u $'($remote)/($branch)' $branch
|
||||||
git pull ...$m ...$a -v
|
git pull ...$m ...$a -v
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let bmsg = "* remote doesn't have that branch"
|
let bmsg = $"remote doesn't have ($branch_repr) branch"
|
||||||
let force = if $force {[--force]} else {[]}
|
let force = if $force {[--force]} else {[]}
|
||||||
if $branch in $lbs {
|
if $branch in $lbs {
|
||||||
print $'($bmsg), set upstream and push'
|
tips $'($bmsg), set upstream and push'
|
||||||
git checkout $branch
|
git checkout $branch
|
||||||
} else {
|
} else {
|
||||||
print $'($bmsg), create and push'
|
tips $'($bmsg), create and push'
|
||||||
git checkout -b $branch
|
git checkout -b $branch
|
||||||
}
|
}
|
||||||
git push $force --set-upstream $remote $branch
|
git push ...$force --set-upstream $remote $branch
|
||||||
}
|
}
|
||||||
|
|
||||||
if $back_to_prev {
|
if $back_to_prev {
|
||||||
|
@ -198,7 +203,7 @@ export def gp [
|
||||||
|
|
||||||
let s = (_git_status)
|
let s = (_git_status)
|
||||||
if $s.ahead > 0 {
|
if $s.ahead > 0 {
|
||||||
print '* remote is behind, push'
|
tips 'remote is behind, push'
|
||||||
git push
|
git push
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue