2 files changed,
47 insertions(+),
0 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-03 00:54:39 +0200
Change ID:
mumskmptlpqxxsszuorwqkqoqumyslmr
Parent:
b9e7f9b
jump to
| M | internal/cli/cli.go |
| A | internal/cli/repo.go |
M
internal/cli/cli.go
@@ -51,6 +51,19 @@ Name: "serve",
Usage: "starts the server", Action: c.serveAction, }, + { + Name: "repo", + Commands: []*cli.Command{ + { + Name: "new", + Usage: "create new repo", + Action: c.repoNewAction, + Arguments: []cli.Argument{ + &cli.StringArg{Name: "name"}, + }, + }, + }, + }, }, } return cmd.Run(ctx, args)
A
internal/cli/repo.go
@@ -0,0 +1,34 @@
+package cli + +import ( + "context" + "fmt" + "os" + "strings" + + securejoin "github.com/cyphar/filepath-securejoin" + "github.com/urfave/cli/v3" + "olexsmir.xyz/mugit/internal/git" +) + +func (c *Cli) repoNewAction(ctx context.Context, cmd *cli.Command) error { + name := cmd.StringArg("name") + if name == "" { + return fmt.Errorf("no name provided") + } + + name = strings.TrimRight(name, ".git") + ".git" + + // TODO: check if there's already such repo + + path, err := securejoin.SecureJoin(c.cfg.Repo.Dir, name) + if err != nil { + return err + } + + if _, err := os.Stat(path); err == nil { + return fmt.Errorf("repository already exists: %s", name) + } + + return git.Init(path) +}