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
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"errors"
"go.wit.com/log"
)
func doDefaultBehavior() (string, error) {
log.Info("forge is in mode", me.forge.GetMode())
if me.forge.IsModeUnknown() {
panic("forge is UNKNOWN. this should have never happened")
}
// DEFAULT BEHAVIOR CHANGES BETWEEN MODES
if me.forge.IsModeNormal() || me.forge.IsModeUser() {
// PROBABLY YOU ARE WRITING CODE
// got to the end with nothing to do (?)
found := findWorkRepos()
if found.Len() == 0 {
return "you have no repos with patches (list them all with --show)", nil
}
found.SortNamespace()
// footer := fmt.Sprintf("findWorkRepos() found %d", found.Len())
// return "doDefaultBehavior() :" + footer, nil
footer := me.forge.PrintDefaultTB(found)
return "repos with unsaved changes: (list them all with --show) " + footer, nil
}
if me.forge.IsModeMaster() {
// PROBABLY YOU ARE PUBLISHING / MERGING CODE
err := defaultBehaviorMaster()
if err != nil {
return "has problems", err
}
return "default master behavior is ok", nil
}
// PROBABLY A NEW USER
found := findAll()
footer := me.forge.PrintDefaultTB(found)
return "new user: " + footer, nil
}
func defaultBehaviorMaster() error {
var reallybad bool
// always run dirty first
me.forge.CheckDirtyQuiet()
// if no option is given to patch, list out the
// repos that have patches ready in them
found := cloneReposWithPatches()
if found.Len() == 0 {
log.Info("you currently have no repos with patches")
return nil
}
footer := found.PrintDefaultTB()
log.Info("default master table", footer)
// warn about dirty repos not in master branches
for repo := range found.IterAll() {
if repo.CheckDirty() {
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
repo.State = "NOT USER"
reallybad = true
}
// return log.Errorf("%s repo is dirty", repo.FullPath)
}
}
if reallybad {
return errors.New("\nYOU ARE MAKING EDITS ON NON USER BRANCHES\n")
}
return nil
}
/*
func defaultBehavior() error {
// always run dirty first
me.forge.CheckDirtyQuiet()
// if no option is given to patch, list out the
// repos that have patches ready in them
found := findReposWithPatches()
if found.Len() == 0 {
log.Info("you currently have no repos with patches")
return log.Errorf("no repos to publish")
}
// check if any are dirty
for repo := range found.IterAll() {
if repo.CheckDirty() {
return log.Errorf("%s repo is dirty", repo.FullPath)
}
}
// check the hashes
for repo := range found.IterAll() {
if err := hashesMatch(repo); err != nil {
return err
}
}
// move them all the the master branch
var bad bool
for repo := range found.IterAll() {
if repo.GetCurrentBranchName() != repo.GetMasterBranchName() {
repo.CheckoutMaster()
bad = true
}
}
if bad {
return log.Errorf("some repos had to be switched to the master branch")
}
if !argv.Force {
return log.Errorf("notsure. it might be safe to publish(?)")
}
return nil
}
*/
|