Switched from the default branch being main to whatever is currently head

This commit is contained in:
Leon Mika 2025-01-02 12:35:14 +11:00
parent 644390f59a
commit 3f9c10c04b

View file

@ -69,7 +69,13 @@ func (s *Services) PushRepository() error {
sourceBranch := s.cfg.LocalBranch
if sourceBranch == "" {
sourceBranch = "main"
// Get the current ref
ref, err := runCmdExpectingOutput("git", "rev-parse", "--abbrev-ref", "HEAD")
if err != nil {
return err
}
sourceBranch = strings.TrimSpace(ref)
}
remoteBranch := s.cfg.RemoteBranch
if remoteBranch == "" {
@ -96,6 +102,17 @@ func runCmd(cmd ...string) error {
return e.Run()
}
func runCmdExpectingOutput(cmd ...string) (string, error) {
log.Printf(" .. [exec] %v", strings.Join(cmd, " "))
e := exec.Command(cmd[0], cmd[1:]...)
e.Stderr = os.Stderr
res, err := e.Output()
if err != nil {
return "", err
}
return string(res), nil
}
func writeFile(path string, content string, mode os.FileMode) error {
fullPath := os.ExpandEnv(path)
log.Printf(" .. [file] %v (%v bytes)", fullPath, len(content))