diff options
| author | Jeff Carr <[email protected]> | 2024-02-16 11:41:29 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-02-16 11:41:29 -0600 |
| commit | bd62a89a670eab24ff5fd7b1ed155b89dde08157 (patch) | |
| tree | 1c51c281bcdb04f7f383c0549db0a6bb17e9a8cc /git.go | |
| parent | 88ca40bcfa11f464828cace14a07a9b59a00d571 (diff) | |
continue cleaning up original version
Diffstat (limited to 'git.go')
| -rw-r--r-- | git.go | 65 |
1 files changed, 61 insertions, 4 deletions
@@ -33,8 +33,29 @@ func (rs *RepoStatus) getCurrentBranchName() string { return out } +func (rs *RepoStatus) gitDescribeTags(name string) (string, error) { + name = strings.TrimSpace(name) + + if name == "" { + // git will return the current tag + err, out := rs.RunCmd([]string{"git", "describe", "--tags"}) + if err != nil { + log.Warn("not in a git repo?", err, rs.Path()) + return "", err + } + return out, err + } + err, out := rs.RunCmd([]string{"git", "describe", "--tags", name}) + if err != nil { + log.Warn("not in a git repo or bad tag?", err, rs.Path()) + return "", err + } + return out, err +} + +// todo: don't run git every time? func (rs *RepoStatus) getCurrentBranchVersion() string { - out := run(rs.realPath.String(), "git", "describe --tags") + out, _ := rs.gitDescribeTags("") log.Log(INFO, "getCurrentBranchVersion()", out) rs.currentVersion.SetValue(out) return out @@ -159,6 +180,13 @@ func (rs *RepoStatus) CheckoutMaster() bool { func (rs *RepoStatus) CheckoutDevel() bool { devel := rs.develWorkingName.String() // user := rs.userWorkingName.String() + if devel == "" { + return false + } + if rs.CheckDirty() { + log.Log(INFO, rs.realPath.String(), "is dirty") + return false + } log.Log(INFO, "checkoutBranch", devel) rs.checkoutBranch("devel", devel) @@ -167,6 +195,33 @@ func (rs *RepoStatus) CheckoutDevel() bool { return true } +func (rs *RepoStatus) CheckoutUser() bool { + bName := rs.GetUserBranchName() + if bName == "" { + return false + } + if rs.CheckDirty() { + log.Log(INFO, rs.realPath.String(), "is dirty") + return false + } + cmd := []string{"git", "checkout", bName} + err, b, output := RunCmd(rs.realPath.String(), cmd) + if err != nil { + log.Log(INFO, err, b, output) + } + + realname := rs.getCurrentBranchName() + realversion := rs.getCurrentBranchVersion() + log.Log(INFO, rs.realPath.String(), "realname =", realname, "realversion =", realversion) + + if realname != bName { + log.Log(INFO, "git checkout failed", rs.realPath.String(), bName, "!=", realname) + return false + } + rs.userBranchVersion.SetValue(realversion) + return true +} + func (rs *RepoStatus) checkoutBranch(level string, branch string) { if rs.CheckDirty() { log.Log(INFO, "checkoutBranch() checkDirty() == true for repo", rs.realPath.String(), "looking for branch:", branch) @@ -190,7 +245,9 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) { } } -func (rs *RepoStatus) SetMainWorkingName(s string) { +// attempt's to guess at what master is. +// TODO: fix this properly +func (rs *RepoStatus) setMainWorkingName(s string) { if rs == nil { log.Info("rs == nil", s) return @@ -243,12 +300,12 @@ func (rs *RepoStatus) SetMainWorkingName(s string) { rs.mainWorkingName.SetValue(s) } -func (rs *RepoStatus) SetDevelWorkingName(s string) { +func (rs *RepoStatus) setDevelWorkingName(s string) { rs.develWorkingName.SetValue(s) rs.develBranchVersion.SetLabel(s) } -func (rs *RepoStatus) SetUserWorkingName(s string) { +func (rs *RepoStatus) setUserWorkingName(s string) { rs.userWorkingName.SetValue(s) rs.userBranchVersion.SetLabel(s) // rs.userDrop.SetText(s) |
