summaryrefslogtreecommitdiff
path: root/doCheckout.go
blob: a314d2597ca099cd5f93ba220164a86aa98043ac (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
package main

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

func IsEverythingOnDevel() bool {
	me.found = new(gitpb.Repos)
	all := me.forge.Repos.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
			// log.Info(repo.GetFullPath(), repo.GetCurrentBranchName(), repo.GetDevelBranchName())
			// add this to the list of "found" repos
			me.found.AppendByGoPath(repo)
		}
	}
	if len(me.found.Repos) == 0 {
		return true
	}
	return false
}

func IsEverythingOnUser() bool {
	me.found = new(gitpb.Repos)
	all := me.forge.Repos.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
			me.found.AppendByGoPath(repo)
		}
	}
	if len(me.found.Repos) == 0 {
		return true
	}
	return false
}

func doGitReset() {
	all := me.found.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
			// log.Info("is readonly", repo.GetGoPath())
			if repo.CheckDirty() {
				log.Info("is readonly and dirty", repo.GetGoPath())
				cmd := []string{"git", "reset", "--hard"}
				repo.RunRealtime(cmd)
			}
		} else {
			// log.Info("is not readonly", repo.GetGoPath())
		}
	}
}

func checkoutBranches(repo *gitpb.Repo) error {
	dname := repo.GetDevelBranchName()
	if dname == "" {
		if err := me.forge.MakeDevelBranch(repo); err != nil {
			log.Info("verify() no devel branch name", repo.GetGoPath())
			return err
		}
		configSave = true
	}
	if repo.GetUserBranchName() == "" {
		if err := me.forge.MakeUserBranch(repo); err != nil {
			log.Info("verify() no devel branch name", repo.GetGoPath())
			return err
		}
		configSave = true
	}
	return nil
}

func doAllCheckoutDevel() bool {
	me.forge.CheckoutDevel()
	me.forge = forgepb.Init()
	if !IsEverythingOnDevel() {
		log.Info("switching to devel branch failed")
		me.forge.PrintHumanTable(me.found)
		badExit(nil)
		return false
	}
	return true
}

func doAllCheckoutUser() bool {
	me.forge.CheckoutUser()
	me.forge = forgepb.Init()
	if !IsEverythingOnUser() {
		log.Info("switching to user branch failed")
		me.forge.PrintHumanTable(me.found)
		return false
	}
	return true
}

func doCheckoutMaster() {
	me.forge.CheckoutMaster()
	me.forge = forgepb.Init()
	me.found = new(gitpb.Repos)
	argv.Checkout.Master.findRepos()
	me.forge.PrintHumanTable(me.found)
}