From fa6971b451a45e650badcfae9e7757baad679abe Mon Sep 17 00:00:00 2001 From: amtoine Date: Mon, 8 Jul 2024 18:12:17 +0200 Subject: [PATCH] add `gm repo zip` and `gm repo unzip` --- .../nu-git-manager-sugar/git/mod.nu | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu index 04c8944..d9d93d9 100644 --- a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu +++ b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu @@ -530,3 +530,35 @@ export def "gm repo bisect" [ $first_bad } + + +def "gm repo zip" [rev: string, --head (-h): string = "HEAD", --out (-o): path = "a.zip"] { + let tmp = mktemp --tmpdir XXXXXXX --directory + log info $"dumping patches to (ansi purple)($tmp)(ansi reset)" + + let patches = git rev-list $"($rev)..($head)" + | lines + | reverse + | enumerate + | each { |it| + let patch = { parent: $tmp, stem: $it.index, extension: "patch" } | path join + git show $it.item | save $patch + + $patch + } + + ^zip $out ...$patches +} + +def "gm repo unzip" [zip: path] { + let tmp = mktemp --tmpdir XXXXXXX --directory + log info $"unzipping (ansi purple)($zip)(ansi reset) to (ansi purple)($tmp)(ansi reset)" + + ^unzip $zip -d $tmp + + for p in ($tmp | path join "**/*.patch" | into glob | ls $in | sort-by name --natural) { + git apply $p.name + git add . + git commit --verbose + } +}