Skip to content

Commit

Permalink
Merge branch 'main' into test-gm-end-to-end
Browse files Browse the repository at this point in the history
this brings the new `gm clone --depth` option to the PR and will
supersede 928275c.
  • Loading branch information
amtoine committed Oct 31, 2023
2 parents 02b7f1d + 8aec003 commit 81da897
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions nu-git-manager/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export def "gm" []: nothing -> nothing {
#
# setup a public repo in the local store and use HTTP to fetch without PAT and push with SSH
# > gm clone https://github.com/amtoine/nu-git-manager --fetch https --push ssh
#
# clone a big repo as a single commit, avoiding all intermediate Git deltas
# > gm clone https://github.com/neovim/neovim --depth 1
export def "gm clone" [
url: string # the URL to the repository to clone, supports HTTPS and SSH links, as well as references ending in `.git` or starting with `git@`
--remote: string = "origin" # the name of the remote to setup
Expand All @@ -85,28 +88,34 @@ export def "gm clone" [

let urls = get-fetch-push-urls $repository $fetch $push $ssh

mut args = [$urls.fetch $local_path --origin $remote]
if $depth != null {
if ($depth < 1) {(
throw-error "invalid_clone_depth"
$"clone depth should be strictly positive, found ($depth)"
(metadata $depth).span
)}
if ($depth < 1) {
let span = metadata $depth | get span
error make {
msg: $"(ansi red_bold)invalid_clone_depth(ansi reset)"
label: {
text: $"clone depth should be strictly positive, found ($depth)"
start: $span.start
end: $span.end
}
}
}

$args = ($args ++ --depth ++ $depth)

log debug "cloning the repo"
if $bare {
^git clone $urls.fetch $local_path --origin $remote --depth $depth --bare
} else {
^git clone $urls.fetch $local_path --origin $remote --depth $depth
$args = ($args ++ --bare)
}
} else {
log debug "cloning the repo"
if $bare {
^git clone $urls.fetch $local_path --origin $remote --bare
} else {
^git clone $urls.fetch $local_path --origin $remote
$args = ($args ++ --bare)
}
}

log debug "cloning the repo"
^git clone $args

log debug "setting up the remote"
^git -C $local_path remote set-url $remote $urls.fetch
^git -C $local_path remote set-url $remote --push $urls.push
Expand Down

0 comments on commit 81da897

Please sign in to comment.