Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gm repo zip and gm repo unzip #197

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions docs/nu-git-manager-sugar/git/gm-repo-unzip.md
Original file line number Diff line number Diff line change
@@ -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` |
15 changes: 15 additions & 0 deletions docs/nu-git-manager-sugar/git/gm-repo-zip.md
Original file line number Diff line number Diff line change
@@ -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` |
2 changes: 2 additions & 0 deletions docs/nu-git-manager-sugar/git/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
32 changes: 32 additions & 0 deletions pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 2 additions & 0 deletions pkgs/nu-git-manager-sugar/tests/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}
Expand Down
Loading