diff --git a/git/repo.go b/git/repo.go index 8c0b87c43..479a4581a 100644 --- a/git/repo.go +++ b/git/repo.go @@ -230,10 +230,13 @@ func (r *Repository) SetConfig(key, value string, opts ...ConfigOptions) error { // SymbolicRef returns or updates the symbolic reference for the given name. // Both name and ref can be empty. -func (r *Repository) SymbolicRef(name string, ref string) (string, error) { - opt := git.SymbolicRefOptions{ - Name: name, - Ref: ref, +func (r *Repository) SymbolicRef(name string, ref string, opts ...git.SymbolicRefOptions) (string, error) { + var opt git.SymbolicRefOptions + if len(opts) > 0 { + opt = opts[0] } + + opt.Name = name + opt.Ref = ref return r.Repository.SymbolicRef(opt) } diff --git a/server/git/git.go b/server/git/git.go index 0dba095ee..e0f1e664b 100644 --- a/server/git/git.go +++ b/server/git/git.go @@ -11,6 +11,7 @@ import ( "github.com/charmbracelet/log" "github.com/charmbracelet/soft-serve/git" "github.com/go-git/go-git/v5/plumbing/format/pktline" + gitm "github.com/gogs/git-module" ) var ( @@ -102,11 +103,10 @@ func EnsureDefaultBranch(ctx context.Context, scmd ServiceCommand) error { } } - cmd := git.NewCommand("branch", "-M", branch).WithContext(ctx) - if err := cmd.RunInDirWithOptions(scmd.Dir, git.RunInDirOptions{ - Stdin: scmd.Stdin, - Stdout: scmd.Stdout, - Stderr: scmd.Stderr, + if _, err := r.SymbolicRef(git.HEAD, git.RefsHeads+branch, gitm.SymbolicRefOptions{ + CommandOptions: gitm.CommandOptions{ + Context: ctx, + }, }); err != nil { return err } diff --git a/server/ssh/cmd/branch.go b/server/ssh/cmd/branch.go index 8566a7d4d..7ed4603db 100644 --- a/server/ssh/cmd/branch.go +++ b/server/ssh/cmd/branch.go @@ -116,7 +116,11 @@ func branchDefaultCommand() *cobra.Command { return git.ErrReferenceNotExist } - if _, err := r.SymbolicRef("HEAD", gitm.RefsHeads+branch); err != nil { + if _, err := r.SymbolicRef(git.HEAD, gitm.RefsHeads+branch, gitm.SymbolicRefOptions{ + CommandOptions: gitm.CommandOptions{ + Context: ctx, + }, + }); err != nil { return err } }