Skip to content

Commit

Permalink
fix gm clone of empty repo (#205)
Browse files Browse the repository at this point in the history
the error before
```
warning: You appear to have cloned an empty repository.
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Error: nu::shell::access_beyond_end

  × Row number too large (empty content).
    ╭─[/home/amtoine/.local/share/nupm/modules/nu-git-manager/git/repo.nu:24:44]
 23 │     let repo = $repo | default (pwd)
 24 │     (^git -C $repo rev-list HEAD | lines | last)
    ·                                            ──┬─
    ·                                              ╰── index too large (empty content)
 25 │ }
    ╰────
```

the cloning now
```
warning: You appear to have cloned an empty repository.
it appears you have cloned an empty repository
creating an 'init' commit
[main (root-commit) 8803d51] init
updating cache... done
```
  • Loading branch information
amtoine authored Dec 6, 2024
1 parent 313f0a6 commit e0adb9e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/nu-git-manager/gm-clean.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm clean` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L567))
# `gm clean` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L573))
clean the store

this command will mainly remove empty directory recursively.
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager/gm-list.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm list` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L224))
# `gm list` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L230))
list all the local repositories in your local store

**/!\\** this command will return sanitized paths. **/!\\**
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager/gm-remove.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm remove` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L362))
# `gm remove` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L368))
remove one of the repositories from your local store

## Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager/gm-squash-forks.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm squash-forks` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L490))
# `gm squash-forks` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L496))
squash multi-directory forks into a single repo

Here, two forks are defined as *two non-grafted repositories that share the same initial commit,
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager/gm-status.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm status` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L292))
# `gm status` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L298))
get current status about the repositories managed by NGM

**/!\\** `$.root.path` and `$.cache.path` will be sanitized **/!\\**
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager/gm-update-cache.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm update-cache` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L325))
# `gm update-cache` from `nu-git-manager` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager/nu-git-manager/mod.nu#L331))
update the local cache of repositories

## Examples
Expand Down
6 changes: 6 additions & 0 deletions pkgs/nu-git-manager/nu-git-manager/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ export def "gm clone" [

^git clone ...$args

if (^git -C $local_path log | complete | get exit_code) != 0 {
print $"it appears you have cloned an (ansi yellow_bold)empty repository(ansi reset)"
print $"creating an (ansi cyan)'init' commit(ansi reset)"
^git -C $local_path commit --allow-empty --message "init"
}

^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 e0adb9e

Please sign in to comment.