64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package gitpb
|
|
|
|
import "go.wit.com/log"
|
|
|
|
func (repo *Repo) CheckoutMaster() bool {
|
|
bName := repo.GetMasterBranchName()
|
|
if repo.checkoutBranch(bName) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (repo *Repo) CheckoutDevel() bool {
|
|
bName := repo.GetDevelBranchName()
|
|
if repo.checkoutBranch(bName) {
|
|
repo.UserBranchName = bName
|
|
return true
|
|
// switch ok
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (repo *Repo) CheckoutUser() bool {
|
|
bName := repo.GetUserBranchName()
|
|
if repo.checkoutBranch(bName) {
|
|
repo.UserBranchName = bName
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (repo *Repo) BranchExists(bName string) bool {
|
|
// fixme after move to protobuf
|
|
return true
|
|
}
|
|
|
|
func (repo *Repo) checkoutBranch(bName string) bool {
|
|
if !repo.BranchExists(bName) {
|
|
return false
|
|
}
|
|
if bName == "" {
|
|
return false
|
|
}
|
|
if repo.CheckDirty() {
|
|
log.Log(GITPB, repo.GetFullPath(), "is dirty")
|
|
return false
|
|
}
|
|
cmd := []string{"git", "checkout", bName}
|
|
r := repo.Run(cmd)
|
|
if r.Error != nil {
|
|
log.Log(GITPB, "git checkout error:", r.Error)
|
|
}
|
|
|
|
realname := repo.GetCurrentBranchName()
|
|
realversion := repo.GetCurrentBranchVersion()
|
|
log.Log(GITPB, repo.GetFullPath(), "realname =", realname, "realversion =", realversion)
|
|
|
|
if realname != bName {
|
|
log.Log(GITPB, "git checkout failed", repo.GetFullPath(), bName, "!=", realname)
|
|
return false
|
|
}
|
|
return true
|
|
}
|