From 470ad04bc54a8f91301df75cc708fe89f92cdfd4 Mon Sep 17 00:00:00 2001 From: fj0r <82698591+fj0r@users.noreply.github.com> Date: Fri, 22 Sep 2023 20:45:59 +0800 Subject: [PATCH] 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 --- modules/git/git-v2.nu | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/modules/git/git-v2.nu b/modules/git/git-v2.nu index ce43a03e..97c0c03b 100644 --- a/modules/git/git-v2.nu +++ b/modules/git/git-v2.nu @@ -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