Skip to content

Commit

Permalink
add gm repo zip and gm repo unzip
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Jul 8, 2024
1 parent 6cdfe07 commit fa6971b
Showing 1 changed file with 32 additions and 0 deletions.
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
}


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
}
}

0 comments on commit fa6971b

Please sign in to comment.