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
|
package main
import (
"os"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
// sent via -ldflags
var VERSION string
var BUILDTIME string
// used for shell auto completion
var ARGNAME string = "go-mod-clean"
var auto *prep.Auto // more experiments for bash handling
var forge *forgepb.Forge
// var check *gitpb.Repo
var configSave bool
func main() {
auto = prep.Bash(&argv) // add support for bash autocomplete with go-arg // this line must be before anything else
log.Info(auto.Version())
forge, _ = forgepb.Init()
// figure out what directory we are running in
pwd, _ := os.Getwd()
check := forge.Repos.FindByFullPath(pwd)
if check == nil {
log.Info("this directory isn't in a golang project (not in ~/go/src nor a go.work file)")
badExit(nil, nil)
}
// deletes all the git notes
if argv.Purge != nil {
purgeNotes(check) // purges all the 'git notes'
eraseGoMod(check) // erase the go.mod and go.sum files
okExit(check, "notes gone")
}
if argv.Restore {
// attempt to restore from ~/go/pkg/mod/
if err := restoreFromGoPkg(check); err != nil {
badExit(check, err)
}
okExit(check, "go.mod and go.sum restored from ~/go/pkg/mod/")
}
if argv.Strict != nil {
log.Info("Starting --strict mode")
if err := doStrict(check); err != nil {
badExit(check, err)
}
okExit(check, "go.mod seems clean")
}
if argv.Smart != nil {
// best effort
if err := doSmart(check); err != nil {
// badExit(check, err)
}
okExit(check, "maybe it's ok")
}
if argv.Force {
if err := doForce(check); err != nil {
badExit(check, err)
}
}
okExit(check, "go.sum seems clean")
}
func findPwdRepo() *gitpb.Repo {
// var check *gitpb.Repo
// attempt to use the working directory
// this is probably what happens most of the time
pwd, _ := os.Getwd()
return forge.Repos.FindByFullPath(pwd)
/*
if strings.HasPrefix(pwd, forge.Config.ReposDir) {
gopath := strings.TrimPrefix(pwd, forge.Config.ReposDir)
gopath = strings.Trim(gopath, "/")
check = forge.FindByGoPath(gopath)
if check != nil {
log.Info(check.Namespace, "was found ok in forge")
return check
}
}
log.Info("findRepo() forge could not find GO path:", pwd)
return nil
*/
}
func saveAsMetadata(repo *gitpb.Repo) error {
cname := repo.GetCurrentBranchName()
if repo.GetGoPrimitive() {
if err := repo.AutogenSave([]string{"go.mod"}, cname, true); err != nil {
return err
}
} else {
if err := repo.AutogenSave([]string{"go.mod", "go.sum"}, cname, true); err != nil {
return err
}
}
return nil
}
|