git-v2: new command gcf for copying files from other branch (#616)

`_git_log`: use `git --reverse` instead of nushell's reverse
        `nu-complete git log all`(gcp): show tags of all branches
        rename `gcf` to `gcl`
        new `gcf` for copying files from other branch

Co-authored-by: agent <agent@nuc>
This commit is contained in:
fj0r 2023-09-22 20:45:59 +08:00 committed by GitHub
parent d459a7de1d
commit 470ad04bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -394,7 +394,7 @@ export def gr [
# git cherry-pick
export def gcp [
commit?: string@"nu-complete git log"
commit?: string@"nu-complete git log all"
--abort (-a): bool
--continue (-c): bool
--skip (-s): bool
@ -413,6 +413,14 @@ export def gcp [
}
}
# copy file from other branch
export def gcf [
branch: string@"nu-complete git branches"
...file: string@"nu-complete git branch files"
] {
^git checkout $branch $file
}
# git reset
export def grs [
commit?: string@"nu-complete git log"
@ -491,7 +499,7 @@ export def ggc [] {
git gc --prune=now --aggressive
}
export alias gcf = git config --list
export alias gcl = git config --list
export alias gsw = git switch
export alias gswc = git switch -c
export alias gts = git tag -s
@ -593,7 +601,7 @@ export def _git_status [] {
export def _git_log_stat [n] {
do -i {
git log -n $n --pretty=»¦«%h --stat
git log --reverse -n $n --pretty=»¦«%h --stat
| lines
| reduce -f { c: '', r: [] } {|it, acc|
if ($it | str starts-with '»¦«') {
@ -631,15 +639,15 @@ export def _git_log [v num] {
_git_log_stat $num
} else { {} }
let r = (do -i {
git log -n $num --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD
git log --reverse -n $num --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD
| lines
| split column "»¦«" sha message author email date
| each {|x| ($x| upsert date ($x.date | into datetime))}
})
if $v {
$r | merge $stat | reverse
$r | merge $stat
} else {
$r | reverse
$r
}
}
@ -650,6 +658,22 @@ def "nu-complete git log" [] {
| each {|x| $x | update value $"($x.value)"}
}
def "nu-complete git log all" [] {
git log --all -n 32 --pretty=%h»¦«%d»¦«%s
| lines
| split column "»¦«" value branch description
| each {|x| $x | update description $"($x.branch) ($x.description)" }
}
def "nu-complete git branch files" [context: string, offset:int] {
let token = $context | split row ' '
let branch = $token | get 1
let files = $token | skip 2
git ls-tree -r --name-only $branch
| lines
| filter {|x| not ($x in $files)}
}
def "nu-complete git branches" [] {
git branch
| lines