summaryrefslogtreecommitdiff
path: root/addRepo.go
blob: f2555f723f4a36337059f86dc02866c1f1d9bce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main

import (
	"os"
	"strings"
	"time"

	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/gui/repostatus"
	"go.wit.com/log"
)

func RemoveFirstElement(slice []string) (string, []string) {
	if len(slice) == 0 {
		return "", slice // Return the original slice if it's empty
	}
	return slice[0], slice[1:] // Return the slice without the first element
}

//	homeDir, _ := os.UserHomeDir()

func (c *controlBox) addRepo(path string) {
	path = strings.Trim(path, "/") // trim any extranous '/' chars put in the config file by the user
	if path == "" {
		log.Warn("addRepo() got empty path", path)
		return
	}

	//	if repostatus.VerifyLocalGoRepo(path) {
	//		log.Verbose("path actually exists", path)
	//	} else {
	//		log.Warn("repostatus.VerifyLocalGoRepo() failed for for", path)
	//		return
	//	}

	c.pathL = gadgets.NewOneLiner(c.grid, "path")
	c.pathL.SetText(path)
	c.grid.NextRow()

	c.lastTag = gadgets.NewOneLiner(c.grid, "lastTag")
	c.grid.NextRow()

	c.dirtyL = gadgets.NewOneLiner(c.grid, "dirty")
	c.grid.NextRow()

	c.currentL = gadgets.NewOneLiner(c.grid, "current")
	c.grid.NextRow()

	c.buildDate = gadgets.NewOneLiner(c.grid, "Build Date")
	c.grid.NextRow()

	stamp := time.Now().UTC().Format("2006/01/02 15:04:05 UTC")
	c.buildDate.SetText(stamp)

	c.tagDate = gadgets.NewBasicEntry(c.grid, "git tag Date")
	c.grid.NextRow()

	err, repo := repostatus.NewRepoStatusWindow(path)
	if err != nil {
		log.Info("path did not work", path, err)
		return
	}
	if repo == nil {
		log.Info("repo == nil", path, err)
		os.Exit(-1)
		return
	}
	c.status = repo
	// c.status.SetMainWorkingName("master")
	// c.status.SetDevelWorkingName("devel")
	// c.status.SetUserWorkingName("jcarr")
	c.status.Update()

	cbname := c.status.GetCurrentBranchName()
	cbversion := c.status.GetCurrentBranchVersion()
	debversion := c.status.DebianCurrentVersion()

	if c.status.CheckDirty() {
		c.dirtyL.SetText("true")
	} else {
		c.dirtyL.SetText("false")
	}

	if c.GoPath.String() == "" {
		c.GoPath.SetText(c.status.GoPath())
	}

	lasttag := c.status.GetLastTagVersion()
	if argv.Release {
		debversion = c.status.DebianReleaseVersion()
		c.dirtyL.SetText("false")
	}

	c.Version.SetText(debversion)

	c.lastTag.SetText(lasttag)
	c.currentL.SetText(cbname + " " + cbversion)

	tagDate := c.getDateStamp(lasttag)
	c.tagDate.SetText(tagDate)

	if s, ok := c.status.Changed(); ok {
		log.Warn("should scan here", s)
	}

	return
}