gitpb/repo.merge.go

89 lines
2.1 KiB
Go
Raw Normal View History

2025-01-05 12:02:54 -06:00
package gitpb
import (
2025-01-30 11:27:48 -06:00
"fmt"
2025-01-05 12:02:54 -06:00
"github.com/go-cmd/cmd"
"go.wit.com/log"
)
2025-01-30 11:27:48 -06:00
func (r *Repo) MergeToDevel() (*cmd.Status, error) {
r.Reload()
if r.GetCurrentBranchName() != r.GetDevelBranchName() {
return nil, fmt.Errorf("repo not on devel branch")
}
if r.CheckDirty() {
return nil, fmt.Errorf("repo is dirty")
}
devel := r.GetDevelBranchName()
user := r.GetUserBranchName()
2025-01-05 12:02:54 -06:00
2025-01-30 11:27:48 -06:00
log.Info("MergeToDevel() merging from", user, "into", devel)
2025-01-05 12:02:54 -06:00
2025-01-30 11:27:48 -06:00
cmd := []string{"git", "merge", user}
result, err := r.RunQuiet(cmd)
if err != nil {
log.Log(WARN, "MergeToDevel() failed", r.GetFullPath())
return result, err
}
2025-01-05 12:02:54 -06:00
2025-01-30 11:27:48 -06:00
if !r.IsBranchRemote(devel) {
2025-01-30 11:50:35 -06:00
r.Reload() // rescan the repo
2025-01-30 11:27:48 -06:00
// devel branch is not remote. do not try 'git push'
return result, nil
}
2025-01-30 11:58:27 -06:00
if r.GetReadOnly() {
r.Reload() // rescan the repo
// devel branch is read only. you can not git push
return result, nil
}
2025-01-30 11:27:48 -06:00
// it seems like we have write access. lets find out!
cmd = []string{"git", "push"}
result, err = r.RunQuiet(cmd)
if err != nil {
2025-01-30 11:50:35 -06:00
log.Log(WARN, "GitPushToDevel() failed", r.GetFullPath())
2025-01-05 12:02:54 -06:00
return result, err
}
2025-01-30 11:50:35 -06:00
r.Reload() // rescan the repo
2025-01-30 11:27:48 -06:00
return result, nil
2025-01-05 12:02:54 -06:00
}
2025-01-30 11:50:35 -06:00
func (r *Repo) MergeToMaster() (*cmd.Status, error) {
r.Reload()
2025-01-05 12:02:54 -06:00
2025-01-30 11:50:35 -06:00
if r.GetCurrentBranchName() != r.GetMasterBranchName() {
return nil, fmt.Errorf("repo not on master branch")
}
if r.CheckDirty() {
return nil, fmt.Errorf("repo is dirty")
}
master := r.GetMasterBranchName()
devel := r.GetDevelBranchName()
2025-01-05 12:02:54 -06:00
2025-01-30 11:50:35 -06:00
log.Info("MergeToMaster() merging from", devel, "into", master)
2025-01-05 12:02:54 -06:00
2025-01-30 11:50:35 -06:00
cmd := []string{"git", "merge", devel}
result, err := r.RunQuiet(cmd)
if err != nil {
log.Log(WARN, "MergeToMaster() failed", r.GetFullPath())
2025-01-05 12:02:54 -06:00
return result, err
}
2025-01-30 11:50:35 -06:00
2025-01-30 11:58:27 -06:00
if r.GetReadOnly() {
r.Reload() // rescan the repo
// master branch is read only. you can not git push
return result, nil
}
2025-01-30 11:50:35 -06:00
// it seems like we have write access. lets find out!
cmd = []string{"git", "push"}
result, err = r.RunQuiet(cmd)
if err != nil {
log.Log(WARN, "GitPushToMaster() failed", r.GetFullPath())
return result, err
}
r.Reload() // rescan the repo
return result, nil
2025-01-05 12:02:54 -06:00
}