diff --git a/docs/index.md b/docs/index.md index 685d2c2..6c3aeac 100644 --- a/docs/index.md +++ b/docs/index.md @@ -32,6 +32,8 @@ - [`gm repo remote add`](nu-git-manager-sugar/git/gm-repo-remote-add.md) - [`gm repo remote list`](nu-git-manager-sugar/git/gm-repo-remote-list.md) - [`gm repo switch`](nu-git-manager-sugar/git/gm-repo-switch.md) +- [`gm repo unzip`](nu-git-manager-sugar/git/gm-repo-unzip.md) +- [`gm repo zip`](nu-git-manager-sugar/git/gm-repo-zip.md) - [`setup`](nu-git-manager-sugar/git/prompt/setup.md) - [`gm gh`](nu-git-manager-sugar/github/gm-gh.md) - [`gm gh pr checkout`](nu-git-manager-sugar/github/gm-gh-pr-checkout.md) diff --git a/docs/nu-git-manager-sugar/git/gm-repo-unzip.md b/docs/nu-git-manager-sugar/git/gm-repo-unzip.md new file mode 100644 index 0000000..c265b6e --- /dev/null +++ b/docs/nu-git-manager-sugar/git/gm-repo-unzip.md @@ -0,0 +1,13 @@ +# `gm repo unzip` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L553)) + + + + +## Parameters +- `zip` <`path`>: + + +## Signatures +| input | output | +| ----- | ------ | +| `any` | `any` | diff --git a/docs/nu-git-manager-sugar/git/gm-repo-zip.md b/docs/nu-git-manager-sugar/git/gm-repo-zip.md new file mode 100644 index 0000000..d841696 --- /dev/null +++ b/docs/nu-git-manager-sugar/git/gm-repo-zip.md @@ -0,0 +1,15 @@ +# `gm repo zip` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L535)) + + + + +## Parameters +- `rev` <`string`>: +- `--head` (`-h`) <`string`> = `HEAD`: +- `--out` (`-o`) <`path`> = `a.zip`: + + +## Signatures +| input | output | +| ----- | ------ | +| `any` | `any` | diff --git a/docs/nu-git-manager-sugar/git/index.md b/docs/nu-git-manager-sugar/git/index.md index d834d33..a2358d1 100644 --- a/docs/nu-git-manager-sugar/git/index.md +++ b/docs/nu-git-manager-sugar/git/index.md @@ -23,6 +23,8 @@ ships a bunch of helper commands that augments the capabilities of Git. - [`gm repo remote add`](gm-repo-remote-add.md) - [`gm repo remote list`](gm-repo-remote-list.md) - [`gm repo switch`](gm-repo-switch.md) +- [`gm repo unzip`](gm-repo-unzip.md) +- [`gm repo zip`](gm-repo-zip.md) ## Submodules - [`prompt`](prompt/index.md) \ No newline at end of file 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..21d56de 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 } + + +export 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 +} + +export 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 + } +} diff --git a/pkgs/nu-git-manager-sugar/tests/mod.nu b/pkgs/nu-git-manager-sugar/tests/mod.nu index 126ea0f..349f4ed 100644 --- a/pkgs/nu-git-manager-sugar/tests/mod.nu +++ b/pkgs/nu-git-manager-sugar/tests/mod.nu @@ -32,6 +32,8 @@ export module imports { "gm repo remote add", "gm repo remote list", "gm repo switch", + "gm repo unzip", + "gm repo zip", "prompt setup", ] }