summaryrefslogtreecommitdiff
path: root/windowModeMaster.go
blob: a48875dc66174fd4c8f370d2ccbd1684f562de96 (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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

// An app to submit patches for the 30 GO GUI repos

func makeModeMasterWin() *gadgets.GenericWindow {
	win := gadgets.NewGenericWindow("Release", "tools")
	grid := win.Group.RawGrid()

	grid.NewButton("git checkout master", func() {
		win.Disable()
		defer win.Enable()
	})
	grid.NewButton("git pull", func() {
		win.Disable()
		defer win.Enable()
	})
	grid.NextRow()

	grid.NewButton("Clean branches", func() {
		win.Disable()
		defer win.Enable()
		doClean()
	})

	grid.NextRow()

	grid.NewButton("check repo state", func() {
		win.Disable()
		defer win.Enable()
	})

	grid.NewButton("reset user branches (?)", func() {
		resetUserBranchesWindow()
	})
	return win
}

func resetUserBranchesWindow() {
	found := gitpb.NewRepos()
	all := me.forge.Repos.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		uname := repo.GetUserBranchName()
		dname := repo.GetDevelBranchName()
		if repo.GetCurrentBranchName() == uname {
			log.Info("Repo is on the user branch. Can't delete it.", repo.GetGoPath())
			continue
		}
		b1 := repo.CountDiffObjects(uname, dname)
		b2 := repo.CountDiffObjects(dname, uname)
		log.Info("user vs devel count", b1, b2)
		if b1 == 0 && b2 == 0 {
			cmd := []string{"git", "branch", "-D", uname}
			log.Info(repo.GetGoPath(), cmd)
			repo.RunVerbose(cmd)
			repo.Reload()
			continue
		}
		found.Append(repo)

	}

	win := gadgets.RawBasicWindow("reset user branches")
	win.Make()
	win.Show()
	win.Custom = func() {
		// sets the hidden flag to false so Toggle() works
		win.Hide()
	}
	box := win.Box().NewBox("bw vbox", false)

	group := box.NewGroup("test buttons")
	hbox := group.Box().Horizontal()
	hbox.NewButton("force delete user branch", func() {
		win.Disable()
		defer win.Enable()
		all := found.SortByFullPath()
		for all.Scan() {
			repo := all.Next()
			brname := repo.GetUserBranchName()
			cmd := []string{"git", "branch", "-D", brname}
			log.Info(repo.GetGoPath(), cmd)
			repo.RunVerbose(cmd)
			repo.Reload()
		}
		me.forge.SetConfigSave(true)
		me.forge.ConfigSave()
	})

	t := makeStandardReposGrid(found)
	t.SetParent(box)
	t.ShowTable()
}