diff --git a/nu-git-manager/mod.nu b/nu-git-manager/mod.nu index af1b2796..b49e298a 100644 --- a/nu-git-manager/mod.nu +++ b/nu-git-manager/mod.nu @@ -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 @@ -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