summaryrefslogtreecommitdiff
path: root/git.go
diff options
context:
space:
mode:
Diffstat (limited to 'git.go')
-rw-r--r--git.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/git.go b/git.go
index f51efe9..7f36ed8 100644
--- a/git.go
+++ b/git.go
@@ -1,6 +1,10 @@
package repostatus
import (
+ "strings"
+ "unicode/utf8"
+
+ "io/ioutil"
"go.wit.com/log"
)
@@ -110,3 +114,49 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) {
default:
}
}
+
+func (rs *RepoStatus) checkBranches() bool {
+ var hashCheck string
+ var perfect bool = true
+ all := rs.getBranches()
+ path := fullpath(rs.repopath + "/.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.Warn("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)
+ _, _, output := runCmd(rs.repopath, cmd)
+ // git show -s --format=%ci <hash> will give you the time
+ // log.Warn(fullfile)
+ if hash == hashCheck {
+ log.Warn(hash, output, b)
+ } else {
+ log.Warn(hash, output, b, "NOT THE SAME")
+ perfect = false
+ parts := strings.Split(b, "/")
+ log.Warn("git push", parts)
+ }
+ }
+ return perfect
+}