summaryrefslogtreecommitdiff
path: root/addRepo.go
blob: 0d99c1491f061fe739b8e6c7fe60b283a67ed2cf (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package repolist

import (
	"errors"

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

func (r *Repo) Hide() {
	r.pLabel.Hide()
	r.lastTag.Hide()
	r.vLabel.Hide()

	r.masterVersion.Hide()
	r.develVersion.Hide()
	r.userVersion.Hide()

	r.dirtyLabel.Hide()
	r.endBox.Hide()
	// r.statusButton.Hide()
	// r.diffButton.Hide()
	r.hidden = true
}

func (r *Repo) Hidden() bool {
	return r.hidden
}

func (r *Repo) Show() {
	r.pLabel.Show()
	r.lastTag.Show()
	r.vLabel.Show()

	r.masterVersion.Show()
	r.develVersion.Show()
	r.userVersion.Show()

	r.dirtyLabel.Show()
	r.endBox.Show()
	// r.statusButton.Show()
	// r.diffButton.Show()
	r.hidden = false
}

func (r *RepoList) AddRepo(path string, master string, devel string, user string) (error, *Repo) {
	return r.addRepo(r.reposgrid, path, master, devel, user)
}

func (r *RepoList) addRepo(grid *gui.Node, path string, master string, devel string, user string) (error, *Repo) {
	existingr, ok := r.allrepos[path]
	if ok {
		log.Info("addRepo() already had path", path)
		return nil, existingr
	}
	// log.Info("addRepo() attempting to add path", path)
	err, rstatus := repostatus.NewRepoStatusWindow(path)

	if rstatus == nil {
		log.Info("add failed. I can figure this out yet", path, err)
		// probably this isn't downloaded
		return err, nil
	}

	newRepo := new(Repo)
	newRepo.Status = rstatus

	// path = strings.TrimSuffix(path, "/") // trim any extranous '/' chars put in the config file by the user
	if path == "" {
		// just an empty line in the config file
		return errors.New("you sent a blank path. stop being silly"), nil
	}

	newRepo.pLabel = grid.NewLabel(path).SetProgName("path")
	newRepo.lastTag = grid.NewLabel("").SetProgName("lastTag")
	newRepo.masterVersion = grid.NewLabel("").SetProgName("masterVersion")
	newRepo.develVersion = grid.NewLabel("").SetProgName("develVersion")
	newRepo.userVersion = grid.NewLabel("").SetProgName("userVersion")
	newRepo.dirtyLabel = grid.NewLabel("")
	newRepo.vLabel = grid.NewLabel("").SetProgName("current")
	newRepo.endBox = grid.NewHorizontalBox("HBOX")
	newRepo.endBox.NewButton("Configure", func() {
		if newRepo.Status == nil {
			// this should never happen, but it does happen because I'm not that smart and forget I can nil Status
			// for some reason that makes sense in my head. again, I'm not that smart
			log.Warn("status window wasn't created")
			return
		}
		newRepo.Status.Toggle()
	})

	newRepo.endBox.NewButton("show diff", func() {
		r.reposbox.Disable()
		// newRepo.Status.XtermNohup([]string{"git diff"})
		newRepo.Status.Xterm("git diff; bash")
		r.reposbox.Enable()
	})

	newRepo.endBox.NewButton("commit all", func() {
		r.reposbox.Disable()
		// restore anything staged so everything can be reviewed
		newRepo.Status.RunCmd([]string{"git", "restore", "--staged", "."})
		newRepo.Status.XtermWait("git diff")
		newRepo.Status.XtermWait("git add --all")
		newRepo.Status.XtermWait("git commit -a")
		newRepo.Status.XtermWait("git push")
		if newRepo.Status.CheckDirty() {
			// commit was not done, restore diff
			newRepo.Status.RunCmd([]string{"git", "restore", "--staged", "."})
		} else {
			newRepo.NewScan()
		}
		r.reposbox.Enable()
	})

	newRepo.hidden = false
	// newRepo.Status.SetMainWorkingName(master)
	// newRepo.Status.SetDevelWorkingName(devel)
	// newRepo.Status.SetUserWorkingName(user)

	var showBuildB bool = false
	switch newRepo.Status.RepoType() {
	case "binary":
		// log.Info("compile here. Show()")
		showBuildB = true
	case "library":
		// log.Info("library here. Hide()")
	default:
		// log.Info("unknown RepoType", newRepo.Status.RepoType())
	}
	if showBuildB {
		newRepo.endBox.NewButton("build", func() {
			newRepo.Status.Build()
		})
	}
	grid.NextRow()

	r.allrepos[path] = newRepo
	return nil, newRepo
}