all repos

mugit @ bb5018d720a612bb763b6e6250f284d31404673b

馃惍 git server that your cow will love
6 files changed, 40 insertions(+), 7 deletions(-)
write logs to file, so we could write logs in ssh shell
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-04-23 22:14:02 +0300
Authored at: 2026-04-23 21:49:15 +0300
Change ID: qwmyzwmyqukktuvpnlruktmylmsozmzu
Parent: da15464
M README.md
路路路
        63
        63
         server:

      
        64
        64
           host: 0.0.0.0 # bind address (0.0.0.0 = all interfaces)

      
        65
        65
           port: 5555    # HTTP port (defaults to 8080 when omitted)

      
        
        66
        +  log_file: /var/lib/mugit/mugit.log # where slog output is written (default: <repo.dir>/mugit.log)

      
        66
        67
         

      
        67
        68
         meta:

      
        68
        69
           title: "My Git Server"    # site title shown on index page

      
M flake.nix
路路路
        114
        114
                             default = 8080;

      
        115
        115
                             description = "Website port";

      
        116
        116
                           };

      
        
        117
        +                  log_file = mkOption {

      
        
        118
        +                    type = types.str;

      
        
        119
        +                    default = "";

      
        
        120
        +                    description = "File to write mugit logs";

      
        
        121
        +                  };

      
        117
        122
                         };

      
        118
        123
                         options.repo = {

      
        119
        124
                           dir = mkOption {

      
        120
        125
                             type = types.str;

      
        121
        126
                             default = "";

      
        122
        127
                             description = "Directory which mugit will scan for repositories (required)";

      
        123
        
        -                  };

      
        124
        
        -                  masters = mkOption {

      
        125
        
        -                    type = types.listOf types.str;

      
        126
        
        -                    default = ["master" "main"];

      
        127
        
        -                    description = "Master branch to look for";

      
        128
        128
                           };

      
        129
        129
                           readmes = mkOption {

      
        130
        130
                             type = types.listOf types.str;

      
M internal/cli/cli.go
路路路
        3
        3
         import (

      
        4
        4
         	"context"

      
        5
        5
         	"fmt"

      
        
        6
        +	"log/slog"

      
        
        7
        +	"os"

      
        
        8
        +	"path/filepath"

      
        6
        9
         

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

      
        8
        11
         	"olexsmir.xyz/mugit/internal/config"

      路路路
        137
        140
         		},

      
        138
        141
         	}

      
        139
        142
         	return cmd.Run(ctx, args)

      
        
        143
        +}

      
        
        144
        +

      
        
        145
        +func (c *Cli) setupLogger() error {

      
        
        146
        +	logDir := filepath.Dir(c.cfg.Server.LogFile)

      
        
        147
        +	if err := os.MkdirAll(logDir, 0o755); err != nil {

      
        
        148
        +		return fmt.Errorf("failed to create log directory: %w", err)

      
        
        149
        +	}

      
        
        150
        +

      
        
        151
        +	logOutput, err := os.OpenFile(c.cfg.Server.LogFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)

      
        
        152
        +	if err != nil {

      
        
        153
        +		return fmt.Errorf("failed to open log file: %w", err)

      
        
        154
        +	}

      
        
        155
        +

      
        
        156
        +	slog.SetDefault(slog.New(slog.NewTextHandler(logOutput, nil)))

      
        
        157
        +	return nil

      
        140
        158
         }

      
        141
        159
         

      
        142
        160
         func (c *Cli) openRepo(name string) (*git.Repo, error) {

      
M internal/cli/serve.go
路路路
        16
        16
         )

      
        17
        17
         

      
        18
        18
         func (c *Cli) serveAction(ctx context.Context, cmd *cli.Command) error {

      
        
        19
        +	if err := c.setupLogger(); err != nil {

      
        
        20
        +		return err

      
        
        21
        +	}

      
        
        22
        +

      
        19
        23
         	httpServer := &http.Server{

      
        20
        24
         		Addr:    net.JoinHostPort(c.cfg.Server.Host, strconv.Itoa(c.cfg.Server.Port)),

      
        21
        25
         		Handler: handlers.InitRoutes(c.cfg),

      
M internal/cli/ssh_shell.go
路路路
        4
        4
         	"context"

      
        5
        5
         	"errors"

      
        6
        6
         	"fmt"

      
        
        7
        +	"log/slog"

      
        7
        8
         	"os"

      
        8
        9
         

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

      路路路
        15
        16
         	if !c.cfg.SSH.Enable {

      
        16
        17
         		return errSSHDisabled

      
        17
        18
         	}

      
        
        19
        +	if err := c.setupLogger(); err != nil {

      
        
        20
        +		return err

      
        
        21
        +	}

      
        18
        22
         

      
        19
        23
         	sshCommand := os.Getenv("SSH_ORIGINAL_COMMAND")

      
        20
        24
         	if err := c.ssh.HandleCommand(ctx, sshCommand, os.Stdin, os.Stdout, os.Stderr); err != nil {

      
        
        25
        +		slog.Error("ssh command failed", "command", sshCommand, "err", err)

      
        21
        26
         		os.Exit(1)

      
        22
        27
         		return nil

      
        23
        28
         	}

      
M internal/config/config.go
路路路
        18
        18
         )

      
        19
        19
         

      
        20
        20
         type ServerConfig struct {

      
        21
        
        -	Host string `yaml:"host"`

      
        22
        
        -	Port int    `yaml:"port"`

      
        
        21
        +	Host    string `yaml:"host"`

      
        
        22
        +	Port    int    `yaml:"port"`

      
        
        23
        +	LogFile string `yaml:"log_file"`

      
        23
        24
         }

      
        24
        25
         

      
        25
        26
         type MetaConfig struct {

      路路路
        115
        116
         }

      
        116
        117
         

      
        117
        118
         func (c *Config) ensureDefaults() {

      
        
        119
        +	if c.Server.LogFile == "" {

      
        
        120
        +		c.Server.LogFile = filepath.Join(c.Repo.Dir, "mugit.log")

      
        
        121
        +	}

      
        
        122
        +

      
        118
        123
         	// http

      
        119
        124
         	if c.Server.Port == 0 {

      
        120
        125
         		c.Server.Port = 8080