all repos

mugit @ 8417128c1e4d0af633edbbe59590db541356c3d8

🐮 git server that your cow will love
2 files changed, 25 insertions(+), 3 deletions(-)
cli: repo create --mirror
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-02-03 00:54:39 +0200
Change ID: utzyrwyttkyzrmvzqxztttzmlqolmsls
Parent: 1a0952a
M internal/cli/cli.go

@@ -61,6 +61,12 @@ Action: c.repoNewAction,

Arguments: []cli.Argument{ &cli.StringArg{Name: "name"}, }, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "mirror", + Usage: "remote URL(only http/https) to mirror from", + }, + }, }, }, },
M internal/cli/repo.go

@@ -19,8 +19,6 @@ }

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

@@ -30,5 +28,23 @@ if _, err := os.Stat(path); err == nil {

return fmt.Errorf("repository already exists: %s", name) } - return git.Init(path) + if err := git.Init(path); err != nil { + return err + } + + mirrorURL := cmd.String("mirror") + if mirrorURL != "" { + if !strings.HasPrefix(mirrorURL, "http") { + return fmt.Errorf("only http and https remotes are supported") + } + repo, err := git.Open(path, "") + if err != nil { + return fmt.Errorf("failed to open repo for mirror setup: %w", err) + } + if err := repo.SetMirrorRemote(mirrorURL); err != nil { + return fmt.Errorf("failed to set mirror remote: %w", err) + } + } + + return nil }