Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to initialize git repo with a particular branch #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
)

type Config struct {
KeyDir string // Directory for server ssh keys. Only used in SSH strategy.
Dir string // Directory that contains repositories
GitPath string // Path to git binary
GitUser string // User for ssh connections
AutoCreate bool // Automatically create repostories
AutoHooks bool // Automatically setup git hooks
Hooks *HookScripts // Scripts for hooks/* directory
Auth bool // Require authentication
ReadOnly bool // Simulates a user that has read-only access to the repository.
KeyDir string // Directory for server ssh keys. Only used in SSH strategy.
Dir string // Directory that contains repositories
GitPath string // Path to git binary
GitUser string // User for ssh connections
AutoCreate bool // Automatically create repostories
AutoHooks bool // Automatically setup git hooks
Hooks *HookScripts // Scripts for hooks/* directory
Auth bool // Require authentication
ReadOnly bool // Simulates a user that has read-only access to the repository.
DefaultBranch string // branch that will be used for initializing the git repository
}

// HookScripts represents all repository server-size git hooks
Expand Down
9 changes: 7 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,13 @@ func (s *Server) Setup() error {
func initRepo(name string, config *Config) error {
fullPath := path.Join(config.Dir, name)

if err := exec.Command(config.GitPath, "init", "--bare", fullPath).Run(); err != nil {
return err
args := []string{"init", "--bare", fullPath}
if config.DefaultBranch != "" {
args = append(args, "--initial-branch", config.DefaultBranch)
}
cmd := exec.Command(config.GitPath, args...)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("err running cmd: %w, output: '%s'", err, out)
}

if config.AutoHooks && config.Hooks != nil {
Expand Down
Loading