all repos

mugit @ 6ba4dfde44441460d5325c6c6a10c2329cc99da1

🐮 git server that your cow will love
3 files changed, 56 insertions(+), 11 deletions(-)
cli: create private repo; toggle private status
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-02-06 23:49:13 +0200
Change ID: tsouwxmxnuvxnnnoxqxotlruzzvpqtsz
Parent: e6fe822
M internal/cli/cli.go

@@ -63,12 +63,24 @@ &cli.StringFlag{

Name: "mirror", Usage: "remote URL(only http/https) to mirror from", }, + &cli.BoolFlag{ + Name: "private", + Usage: "make the repository private", + }, }, }, { Name: "description", Usage: "get or set repo description", Action: c.repoDescriptionAction, + Arguments: []cli.Argument{ + &cli.StringArg{Name: "name"}, + }, + }, + { + Name: "private", + Usage: "toggle private status of a repo", + Action: c.repoPrivateAction, Arguments: []cli.Argument{ &cli.StringArg{Name: "name"}, },
M internal/cli/repo.go

@@ -3,6 +3,7 @@

import ( "context" "fmt" + "log/slog" "os" "strings"

@@ -24,22 +25,27 @@ if err != nil {

return err } - if _, err := os.Stat(path); err == nil { + if _, err = os.Stat(path); err == nil { return fmt.Errorf("repository already exists: %s", name) } - if err := git.Init(path); err != nil { + if err = git.Init(path); err != nil { return err } + repo, err := git.Open(path, "") + if err != nil { + return fmt.Errorf("failed to open repo: %w", err) + } + + if err := repo.SetPrivate(true); err != nil { + return fmt.Errorf("failed to set private status: %w", 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)

@@ -64,7 +70,7 @@ }

newDesc := cmd.Args().Get(0) if newDesc != "" { - if err := repo.SetDescription(newDesc); err != nil { + if err = repo.SetDescription(newDesc); err != nil { return fmt.Errorf("failed to set description: %w", err) } }

@@ -74,11 +80,33 @@ if err != nil {

return fmt.Errorf("failed to get description: %w", err) } - if desc == "" { - fmt.Println("No description set") - } else { - fmt.Println(desc) + slog.Info("changed repo description", "repo", name, "new_description", desc) + return nil +} + +func (c *Cli) repoPrivateAction(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" + + repo, err := c.openRepo(name) + if err != nil { + return fmt.Errorf("failed to open repo: %w", err) + } + + isPrivate, err := repo.IsPrivate() + if err != nil { + return fmt.Errorf("failed to get private status: %w", err) + } + + newStatus := !isPrivate + if err := repo.SetPrivate(newStatus); err != nil { + return fmt.Errorf("failed to set private status: %w", err) + } + + slog.Info("new repo private status", "repo", name, "is_private", newStatus) return nil }
M internal/git/config.go

@@ -4,6 +4,7 @@ import (

"fmt" "os" "path/filepath" + "strconv" "strings" "time"

@@ -16,6 +17,10 @@ if err != nil {

return false, err } return v == "true", nil +} + +func (g *Repo) SetPrivate(isPrivate bool) error { + return g.setOption("private", strconv.FormatBool(isPrivate)) } const originRemote = "origin"