all repos

mugit @ 7a1404484e466147951fe3e23f4c43b2b2b029a4

🐮 git server that your cow will love
2 files changed, 47 insertions(+), 0 deletions(-)
cli: repo new
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-02-03 00:54:39 +0200
Change ID: mumskmptlpqxxsszuorwqkqoqumyslmr
Parent: b9e7f9b
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) +}