summaryrefslogtreecommitdiff
path: root/git.go
diff options
context:
space:
mode:
Diffstat (limited to 'git.go')
-rw-r--r--git.go472
1 files changed, 224 insertions, 248 deletions
diff --git a/git.go b/git.go
index cef5d05..42255f0 100644
--- a/git.go
+++ b/git.go
@@ -44,6 +44,7 @@ func (rs *RepoStatus) Age() time.Duration {
var ErrorMissingGitConfig error = errors.New("missing .git/config")
var ErrorGitPullOnLocal error = errors.New("git pull on local only branch")
+/*
func (rs *RepoStatus) GitPull() (string, error) {
currentName := rs.GetCurrentBranchName()
if rs.IsOnlyLocalTag(currentName) {
@@ -64,6 +65,228 @@ func (rs *RepoStatus) GitPull() (string, error) {
}
return output, r.Error
}
+*/
+
+func (rs *RepoStatus) checkoutBranch(level string, branch string) {
+ if rs.CheckDirty() {
+ log.Log(REPO, "checkoutBranch() checkDirty() == true for repo", rs.realPath.String(), "looking for branch:", branch)
+ return
+ }
+ out := run(rs.realPath.String(), "git", "checkout "+branch)
+ log.Log(REPO, rs.realPath.String(), "git checkout "+branch, "returned", out)
+
+ realname := rs.GetCurrentBranchName()
+ realversion := rs.GetCurrentBranchVersion()
+ log.Log(REPO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
+
+ switch level {
+ case "master":
+ rs.mainBranchVersion.SetValue(realversion)
+ case "devel":
+ rs.develBranchVersion.SetValue(realversion)
+ case "user":
+ rs.userBranchVersion.SetValue(realversion)
+ default:
+ }
+}
+
+func (rs *RepoStatus) guessDevelWorkingName() {
+ if rs.TagExists("guidevel") {
+ rs.develWorkingName.SetValue("guidevel")
+ rs.develBranchVersion.SetLabel("guidevel")
+ return
+ }
+ if rs.TagExists("devel") {
+ rs.develWorkingName.SetValue("devel")
+ rs.develBranchVersion.SetLabel("devel")
+ return
+ }
+
+ // figure out what to do here
+ rs.develWorkingName.SetValue("develFIXME")
+ rs.develBranchVersion.SetLabel("develFIXME")
+}
+
+func (rs *RepoStatus) setUserWorkingName() {
+ usr, _ := user.Current()
+ uname := usr.Username
+ if rs.TagExists(uname) {
+ rs.userWorkingName.SetValue(uname)
+ rs.userBranchVersion.SetLabel(uname)
+ return
+ }
+ rs.userWorkingName.SetValue("need to create " + uname)
+ rs.userBranchVersion.SetLabel("need to create " + uname)
+}
+
+// returns "master", "devel", os.Username, etc
+func (rs *RepoStatus) GetMasterBranchName() string {
+ name := rs.mainWorkingName.String()
+ return name
+}
+func (rs *RepoStatus) GetDevelBranchName() string {
+ name := rs.develWorkingName.String()
+ return name
+}
+
+func (rs *RepoStatus) GetUserBranchName() string {
+ name := rs.userWorkingName.String()
+ return name
+}
+
+// returns the git versions like "1.3-2-laksdjf" or whatever
+func (rs *RepoStatus) GetMasterVersion() string {
+ name := rs.mainBranchVersion.String()
+ return name
+}
+func (rs *RepoStatus) GetDevelVersion() string {
+ name := rs.develBranchVersion.String()
+ return name
+}
+func (rs *RepoStatus) GetUserVersion() string {
+ name := rs.userBranchVersion.String()
+ return name
+}
+
+func (rs *RepoStatus) setMasterVersion(s string) {
+ old := rs.GetMasterVersion()
+ if old == s {
+ return
+ }
+ rs.mainBranchVersion.SetValue(s)
+ if old == "" {
+ return // don't note if there was nothing before
+ }
+ rs.NoteChange("master branch has been changed from " + old + " to " + s)
+}
+
+func (rs *RepoStatus) setDevelVersion(s string) {
+ old := rs.GetDevelVersion()
+ if old == s {
+ return
+ }
+ if old == "" {
+ // don't note nothing
+ } else {
+ rs.NoteChange("devel branch has been changed from " + old + " to " + s)
+ }
+ rs.develBranchVersion.SetValue(s)
+}
+
+func (rs *RepoStatus) setUserVersion(s string) {
+ old := rs.GetUserVersion()
+ if old == s {
+ return
+ }
+ if old == "" {
+ // don't note nothing
+ } else {
+ rs.NoteChange("user branch has been changed from " + old + " to " + s)
+ }
+ rs.userBranchVersion.SetValue(s)
+}
+
+func (rs *RepoStatus) GitState() string {
+ return rs.gitState.String()
+}
+
+func (rs *RepoStatus) CheckGitState() string {
+ rs.setState()
+ return rs.gitState.String()
+}
+
+func (rs *RepoStatus) GetStatus() string {
+ return rs.gitState.String()
+}
+
+func (rs *RepoStatus) setState() {
+ rs.changed = false
+ if rs.CheckDirty() {
+ log.Log(REPO, "CheckDirty() true")
+ rs.gitState.SetText("dirty")
+ return
+ }
+ if rs.GetUserVersion() != rs.GetDevelVersion() {
+ rs.gitState.SetText("merge to devel")
+ return
+ }
+ if rs.GetDevelVersion() != rs.GetMasterVersion() {
+ rs.gitState.SetText("merge to main")
+ return
+ }
+ if rs.lasttag.String() != rs.GetMasterVersion() {
+ rs.gitState.SetText("unchanged")
+ return
+ }
+
+ if rs.CheckBranches() {
+ log.Log(REPO, "Branches are Perfect")
+ rs.gitState.SetText("PERFECT")
+ return
+ }
+ log.Log(REPO, rs.String(), "Branches are not Perfect")
+ rs.gitState.SetText("unknown branches")
+}
+
+// TODO: make this report the error somewhere
+// This is supposed to check all the branches to make sure
+// the are the same. that was originally what this was for
+// now I think it's jsut probably dumb old code that doesn't
+// need to be here
+
+// actually, this is to attempt to verify absolutely everything
+// is pushed upstream before doing a rm -rf ~/go/src
+// TODO: revisit this code in the autotypist later
+func (rs *RepoStatus) CheckBranches() bool {
+ var hashCheck string
+ var perfect bool = true
+ all := rs.getBranches()
+ path := rs.realPath.String() + "/.git/refs/"
+ for _, b := range all {
+ parts := strings.Split(b, "/")
+ rdir := "heads"
+ if len(parts) == 2 {
+ rdir = "remotes"
+ }
+ fullfile := path + "/" + rdir + "/" + b
+
+ // check if the ref name is "HEAD". if so, skip
+ runeCount := utf8.RuneCountInString(fullfile)
+ // Convert the string to a slice of runes
+ runes := []rune(fullfile)
+ // Slice the last 4 runes
+ lastFour := runes[runeCount-4:]
+ if string(lastFour) == "HEAD" {
+ log.Log(REPO, "skip HEAD fullfile", fullfile)
+ continue
+ }
+
+ content, _ := ioutil.ReadFile(fullfile)
+ hash := strings.TrimSpace(string(content))
+ if hashCheck == "" {
+ hashCheck = hash
+ }
+ var cmd []string
+ cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash)
+ r := shell.PathRunLog(rs.Path(), cmd, INFO)
+ if r.Error != nil {
+ log.Log(WARN, "CheckBranches() git show error:", r.Error)
+ }
+ // git show -s --format=%ci <hash> will give you the time
+ // log.Log(REPO, fullfile)
+ if hash == hashCheck {
+ log.Log(REPO, "notsure why this git show is here", hash)
+ } else {
+ // log.Log(WARN, rs.String(), hash, output, b)
+ // log.Log(WARN, "UNKNOWN BRANCHES IN THIS REPO", cmd)
+ rs.versionCmdOutput.SetText("UNKNOWN BRANCHES")
+ perfect = false
+ // parts := strings.Split(b, "/")
+ // log.Warn("git push", parts)
+ }
+ }
+ return perfect
+}
/*
// this isn't right
@@ -257,6 +480,7 @@ func (rs *RepoStatus) CheckDirty() bool {
return true
}
+
func (rs *RepoStatus) CheckoutBranch(bname string) bool {
if rs.CheckDirty() {
log.Log(REPO, rs.realPath.String(), "is dirty")
@@ -343,251 +567,3 @@ func (rs *RepoStatus) CheckoutUser() bool {
rs.userBranchVersion.SetValue(realversion)
return true
}
-
-func (rs *RepoStatus) checkoutBranch(level string, branch string) {
- if rs.CheckDirty() {
- log.Log(REPO, "checkoutBranch() checkDirty() == true for repo", rs.realPath.String(), "looking for branch:", branch)
- return
- }
- out := run(rs.realPath.String(), "git", "checkout "+branch)
- log.Log(REPO, rs.realPath.String(), "git checkout "+branch, "returned", out)
-
- realname := rs.GetCurrentBranchName()
- realversion := rs.GetCurrentBranchVersion()
- log.Log(REPO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
-
- switch level {
- case "master":
- rs.mainBranchVersion.SetValue(realversion)
- case "devel":
- rs.develBranchVersion.SetValue(realversion)
- case "user":
- rs.userBranchVersion.SetValue(realversion)
- default:
- }
-}
-
-// attempt's to guess at what master is.
-// TODO: fix this properly
-func (rs *RepoStatus) guessMainWorkingName() {
- if !rs.Ready() {
- return
- }
- if rs.TagExists("guimaster") {
- rs.mainWorkingName.SetText("guimaster")
- rs.mainBranchVersion.SetLabel("guimaster")
- return
- }
- if rs.TagExists("master") {
- rs.mainWorkingName.SetText("master")
- rs.mainBranchVersion.SetLabel("master")
- return
- }
- if rs.TagExists("main") {
- rs.mainWorkingName.SetText("main")
- rs.mainBranchVersion.SetLabel("main")
- return
- }
-
- // figure out what to do here
- rs.mainWorkingName.SetText("FIXME")
- rs.mainBranchVersion.SetLabel("FIXME")
-}
-
-func (rs *RepoStatus) guessDevelWorkingName() {
- if rs.TagExists("guidevel") {
- rs.develWorkingName.SetValue("guidevel")
- rs.develBranchVersion.SetLabel("guidevel")
- return
- }
- if rs.TagExists("devel") {
- rs.develWorkingName.SetValue("devel")
- rs.develBranchVersion.SetLabel("devel")
- return
- }
-
- // figure out what to do here
- rs.develWorkingName.SetValue("develFIXME")
- rs.develBranchVersion.SetLabel("develFIXME")
-}
-
-func (rs *RepoStatus) setUserWorkingName() {
- usr, _ := user.Current()
- uname := usr.Username
- if rs.TagExists(uname) {
- rs.userWorkingName.SetValue(uname)
- rs.userBranchVersion.SetLabel(uname)
- return
- }
- rs.userWorkingName.SetValue("need to create " + uname)
- rs.userBranchVersion.SetLabel("need to create " + uname)
-}
-
-// returns "master", "devel", os.Username, etc
-func (rs *RepoStatus) GetMasterBranchName() string {
- name := rs.mainWorkingName.String()
- return name
-}
-func (rs *RepoStatus) GetDevelBranchName() string {
- name := rs.develWorkingName.String()
- return name
-}
-
-func (rs *RepoStatus) GetUserBranchName() string {
- name := rs.userWorkingName.String()
- return name
-}
-
-// returns the git versions like "1.3-2-laksdjf" or whatever
-func (rs *RepoStatus) GetMasterVersion() string {
- name := rs.mainBranchVersion.String()
- return name
-}
-func (rs *RepoStatus) GetDevelVersion() string {
- name := rs.develBranchVersion.String()
- return name
-}
-func (rs *RepoStatus) GetUserVersion() string {
- name := rs.userBranchVersion.String()
- return name
-}
-
-func (rs *RepoStatus) setMasterVersion(s string) {
- old := rs.GetMasterVersion()
- if old == s {
- return
- }
- rs.mainBranchVersion.SetValue(s)
- if old == "" {
- return // don't note if there was nothing before
- }
- rs.NoteChange("master branch has been changed from " + old + " to " + s)
-}
-
-func (rs *RepoStatus) setDevelVersion(s string) {
- old := rs.GetDevelVersion()
- if old == s {
- return
- }
- if old == "" {
- // don't note nothing
- } else {
- rs.NoteChange("devel branch has been changed from " + old + " to " + s)
- }
- rs.develBranchVersion.SetValue(s)
-}
-
-func (rs *RepoStatus) setUserVersion(s string) {
- old := rs.GetUserVersion()
- if old == s {
- return
- }
- if old == "" {
- // don't note nothing
- } else {
- rs.NoteChange("user branch has been changed from " + old + " to " + s)
- }
- rs.userBranchVersion.SetValue(s)
-}
-
-func (rs *RepoStatus) GitState() string {
- return rs.gitState.String()
-}
-
-func (rs *RepoStatus) CheckGitState() string {
- rs.setState()
- return rs.gitState.String()
-}
-
-func (rs *RepoStatus) GetStatus() string {
- return rs.gitState.String()
-}
-
-func (rs *RepoStatus) setState() {
- rs.changed = false
- if rs.CheckDirty() {
- log.Log(REPO, "CheckDirty() true")
- rs.gitState.SetText("dirty")
- return
- }
- if rs.GetUserVersion() != rs.GetDevelVersion() {
- rs.gitState.SetText("merge to devel")
- return
- }
- if rs.GetDevelVersion() != rs.GetMasterVersion() {
- rs.gitState.SetText("merge to main")
- return
- }
- if rs.lasttag.String() != rs.GetMasterVersion() {
- rs.gitState.SetText("unchanged")
- return
- }
-
- if rs.CheckBranches() {
- log.Log(REPO, "Branches are Perfect")
- rs.gitState.SetText("PERFECT")
- return
- }
- log.Log(REPO, rs.String(), "Branches are not Perfect")
- rs.gitState.SetText("unknown branches")
-}
-
-// TODO: make this report the error somewhere
-// This is supposed to check all the branches to make sure
-// the are the same. that was originally what this was for
-// now I think it's jsut probably dumb old code that doesn't
-// need to be here
-
-// actually, this is to attempt to verify absolutely everything
-// is pushed upstream before doing a rm -rf ~/go/src
-// TODO: revisit this code in the autotypist later
-func (rs *RepoStatus) CheckBranches() bool {
- var hashCheck string
- var perfect bool = true
- all := rs.getBranches()
- path := rs.realPath.String() + "/.git/refs/"
- for _, b := range all {
- parts := strings.Split(b, "/")
- rdir := "heads"
- if len(parts) == 2 {
- rdir = "remotes"
- }
- fullfile := path + "/" + rdir + "/" + b
-
- // check if the ref name is "HEAD". if so, skip
- runeCount := utf8.RuneCountInString(fullfile)
- // Convert the string to a slice of runes
- runes := []rune(fullfile)
- // Slice the last 4 runes
- lastFour := runes[runeCount-4:]
- if string(lastFour) == "HEAD" {
- log.Log(REPO, "skip HEAD fullfile", fullfile)
- continue
- }
-
- content, _ := ioutil.ReadFile(fullfile)
- hash := strings.TrimSpace(string(content))
- if hashCheck == "" {
- hashCheck = hash
- }
- var cmd []string
- cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash)
- r := shell.PathRunLog(rs.Path(), cmd, INFO)
- if r.Error != nil {
- log.Log(WARN, "CheckBranches() git show error:", r.Error)
- }
- // git show -s --format=%ci <hash> will give you the time
- // log.Log(REPO, fullfile)
- if hash == hashCheck {
- log.Log(REPO, "notsure why this git show is here", hash)
- } else {
- // log.Log(WARN, rs.String(), hash, output, b)
- // log.Log(WARN, "UNKNOWN BRANCHES IN THIS REPO", cmd)
- rs.versionCmdOutput.SetText("UNKNOWN BRANCHES")
- perfect = false
- // parts := strings.Split(b, "/")
- // log.Warn("git push", parts)
- }
- }
- return perfect
-}