package gitpb

import (
	"github.com/go-cmd/cmd"
	"go.wit.com/log"
)

func (rs *Repo) MergeUserToDevel() (*cmd.Status, error) {
	startbranch := rs.GetCurrentBranchName()
	devel := rs.GetDevelBranchName()
	user := rs.GetUserBranchName()

	log.Info("MergeUserToDevel() checking out", devel, "started on", startbranch, "merge", user)

	var all [][]string
	all = append(all, []string{"git", "checkout", devel})
	all = append(all, []string{"git", "merge", user})
	all = append(all, []string{"git", "push"})

	if result, err := rs.RunStrictAll(all); err != nil {
		log.Log(WARN, "MergeUserToDevel() failed", rs.GetFullPath())
		return result, err
	}
	return nil, nil
}

func (rs *Repo) MergeDevelToMaster() (*cmd.Status, error) {
	startbranch := rs.GetCurrentBranchName()
	devel := rs.GetDevelBranchName()
	main := rs.GetMasterBranchName()

	log.Info("MergeDevelToMaster() checking out", main, "started on", startbranch, "merge", devel)

	var all [][]string
	all = append(all, []string{"git", "checkout", main})
	all = append(all, []string{"git", "merge", devel})
	all = append(all, []string{"git", "push"})

	if result, err := rs.RunStrictAll(all); err != nil {
		log.Log(WARN, "MergeDevelToMaster() failed", rs.GetFullPath())
		return result, err
	}
	return nil, nil
}