summaryrefslogtreecommitdiff
path: root/checkout.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-19 08:48:43 -0600
committerJeff Carr <[email protected]>2025-01-19 08:48:43 -0600
commit966e3d785898a0ba17e87b7045e36b811519e212 (patch)
tree943a30c452e0b0bd8a84bbc03a3062bcc11ab740 /checkout.go
parentd4cc68c07f2309ddefc904215d79e21fd8eb034a (diff)
recreate user branchesv0.0.61
Diffstat (limited to 'checkout.go')
-rw-r--r--checkout.go68
1 files changed, 62 insertions, 6 deletions
diff --git a/checkout.go b/checkout.go
index 8e489a8..2b0e3f2 100644
--- a/checkout.go
+++ b/checkout.go
@@ -1,6 +1,11 @@
package gitpb
-import "go.wit.com/log"
+import (
+ "fmt"
+ "path/filepath"
+
+ "go.wit.com/log"
+)
func (repo *Repo) CheckoutMaster() bool {
bName := repo.GetMasterBranchName()
@@ -20,13 +25,14 @@ func (repo *Repo) CheckoutDevel() bool {
return false
}
-func (repo *Repo) CheckoutUser() bool {
+func (repo *Repo) CheckoutUser() error {
bName := repo.GetUserBranchName()
- if repo.checkoutBranch(bName) {
- repo.UserBranchName = bName
- return true
+ // log.Info("attempting checkout user", repo.GetGoPath(), bName)
+ err := repo.checkoutBranchNew(bName)
+ if err != nil {
+ log.Info("attempting checkout user error", repo.GetGoPath(), bName, err)
}
- return false
+ return err
}
func (repo *Repo) BranchExists(bName string) bool {
@@ -61,3 +67,53 @@ func (repo *Repo) checkoutBranch(bName string) bool {
}
return true
}
+
+func (repo *Repo) checkoutBranchNew(branch string) error {
+ if branch == "" || branch == "uerr" {
+ log.Info("forge.gitpb logic err. branch name was:", branch)
+ return nil
+ }
+ if repo.IsDirty() {
+ // never change repos on dirty branches
+ return nil
+ }
+ // log.Info("forge.gitpb look for branch name was:", branch, repo.GetGoPath())
+
+ if repo.Exists(filepath.Join(".git/refs/heads", branch)) {
+ var err error
+ // there is already a local user branch
+ cmd := []string{"git", "checkout", branch}
+ if _, err = repo.RunVerboseOnError(cmd); err == nil {
+ return nil
+ }
+ log.Log(INFO, "git checkout error:", err)
+ }
+
+ if repo.Exists(filepath.Join(".git/refs/remote/origin", branch)) {
+ var err error
+ // there is a remote user branch
+ // todo: check other remotes
+ cmd := []string{"git", "checkout", branch}
+ if _, err = repo.RunVerboseOnError(cmd); err == nil {
+ return nil
+ }
+ log.Log(INFO, "git checkout error:", err)
+ }
+
+ if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
+ return fmt.Errorf("repo must be on devel branch %s", repo.GetGoPath())
+ }
+
+ // log.Info("forge.gitpb try to create", branch, repo.GetGoPath())
+
+ // create the branch from devel
+ cmd := []string{"git", "branch", branch}
+ if _, err := repo.RunVerboseOnError(cmd); err != nil {
+ return err
+ }
+ cmd = []string{"git", "checkout", branch}
+ if _, err := repo.RunVerboseOnError(cmd); err != nil {
+ return err
+ }
+ return nil
+}