all repos

mugit @ 7a14044

馃惍 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
Authored at: 2026-01-31 21:23:46 +0200
Change ID: mumskmptlpqxxsszuorwqkqoqumyslmr
Parent: b9e7f9b
M internal/cli/cli.go
路路路
        51
        51
         				Usage:  "starts the server",

      
        52
        52
         				Action: c.serveAction,

      
        53
        53
         			},

      
        
        54
        +			{

      
        
        55
        +				Name: "repo",

      
        
        56
        +				Commands: []*cli.Command{

      
        
        57
        +					{

      
        
        58
        +						Name:   "new",

      
        
        59
        +						Usage:  "create new repo",

      
        
        60
        +						Action: c.repoNewAction,

      
        
        61
        +						Arguments: []cli.Argument{

      
        
        62
        +							&cli.StringArg{Name: "name"},

      
        
        63
        +						},

      
        
        64
        +					},

      
        
        65
        +				},

      
        
        66
        +			},

      
        54
        67
         		},

      
        55
        68
         	}

      
        56
        69
         	return cmd.Run(ctx, args)

      
A internal/cli/repo.go
路路路
        
        1
        +package cli

      
        
        2
        +

      
        
        3
        +import (

      
        
        4
        +	"context"

      
        
        5
        +	"fmt"

      
        
        6
        +	"os"

      
        
        7
        +	"strings"

      
        
        8
        +

      
        
        9
        +	securejoin "github.com/cyphar/filepath-securejoin"

      
        
        10
        +	"github.com/urfave/cli/v3"

      
        
        11
        +	"olexsmir.xyz/mugit/internal/git"

      
        
        12
        +)

      
        
        13
        +

      
        
        14
        +func (c *Cli) repoNewAction(ctx context.Context, cmd *cli.Command) error {

      
        
        15
        +	name := cmd.StringArg("name")

      
        
        16
        +	if name == "" {

      
        
        17
        +		return fmt.Errorf("no name provided")

      
        
        18
        +	}

      
        
        19
        +

      
        
        20
        +	name = strings.TrimRight(name, ".git") + ".git"

      
        
        21
        +

      
        
        22
        +	// TODO: check if there's already such repo

      
        
        23
        +

      
        
        24
        +	path, err := securejoin.SecureJoin(c.cfg.Repo.Dir, name)

      
        
        25
        +	if err != nil {

      
        
        26
        +		return err

      
        
        27
        +	}

      
        
        28
        +

      
        
        29
        +	if _, err := os.Stat(path); err == nil {

      
        
        30
        +		return fmt.Errorf("repository already exists: %s", name)

      
        
        31
        +	}

      
        
        32
        +

      
        
        33
        +	return git.Init(path)

      
        
        34
        +}