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
  | 
package main
import (
	"errors"
	"os"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)
func doStrict(repo *gitpb.Repo) error {
	var err error
	if !repo.IsValidDir() {
		log.Info(repo.GetGoPath(), "is invalid. fix your repos.pb file with 'forge' first")
		log.Info("")
		log.Info("go install go.wit.com/apps/forge@latest")
		log.Info("")
		return errors.New(repo.GetGoPath() + " is invalid. fix your repository list with 'forge' first")
	}
	log.Info(repo.GetGoPath(), "is valid according to forge")
	repo.Run([]string{"git", "notes", "remove"})
	if err := repo.RepoIgnoresGoMod(); err != nil {
		log.Info(repo.GetGoPath(), "git repo does not ignore go.mod. do nothing here", err)
		return nil
	}
	// erase the go.mod and go.sum files
	eraseGoMod(repo)
	if repo.GetMasterBranchName() != repo.GetCurrentBranchName() {
		log.Info("")
		log.Info("ERR: You are not operating on your git master branch.")
		log.Info("ERR: Publishing go.mod & go.sum files must come from from git version tag on the master branch")
		log.Info("")
		return errors.New("not on the git master branch")
	}
	// not sure if this really needs to be run a second time. probably not, but whatever. who cares
	if err := repo.RepoIgnoresGoMod(); err != nil {
		log.Info(repo.GetGoPath(), "some wierd git error happened. investigate.", err)
		return err
	}
	if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
		log.Info("you can not push to read only repositories.", repo.GetGoPath())
		log.Info("change your .config/forge/ to indicate you own this repository")
		return nil
	}
	if repo.CheckDirty() {
		log.Info("")
		log.Info("You can not continue on a dirty git repo.")
		log.Info("")
		return errors.New(repo.GetGoPath() + " git repo is dirty")
	}
	log.Info(repo.GetGoPath(), "GOING TO MAKE NEW go.* FILES")
	// actually will re-create go.sum and go.mod now
	os.Unsetenv("GO111MODULE")
	if result, err := repo.RunQuiet([]string{"go", "mod", "init", repo.GetGoPath()}); err != nil {
		log.Warn("go mod init failed", err)
		for _, line := range result.Stdout {
			log.Warn("stdout:", line)
		}
		for _, line := range result.Stderr {
			log.Warn("stderr:", line)
		}
		return err
	}
	if !repo.Exists("go.mod") {
		// well, if go mod init fails, then we will just error since 'go mod init' almost never fails
		return err
	}
	os.Unsetenv("GO111MODULE")
	if result, err := repo.RunQuiet([]string{"go", "mod", "tidy"}); err != nil {
		// I guess the thing to do, if go mod tidy fails, is to just leave the repo alone
		// it's either primitive or could be a go support project but not in go
		for _, line := range result.Stdout {
			log.Warn("stdout:", line)
		}
		for _, line := range result.Stderr {
			log.Warn("stderr:", line)
		}
		return nil
	}
	// the first time, it'll attempt to fix some stuff
	log.Info(repo.GetGoPath(), "Running: updateToNewestReleases()")
	cleanGoDepsCheckOk(repo)
	if repo.Exists("go.sum") {
		// try to trim junk
		log.Info(repo.GetGoPath(), "Running: trimGoSum()")
		if err := trimGoSum(repo); err != nil {
			log.Info(repo.GetGoPath(), "trimGoSum() failed", err)
			return err
		}
	}
	if repo.ParseGoSum() {
		log.Info(repo.GetGoPath(), "ParseGoSum() ok")
	} else {
		log.Info(repo.GetGoPath(), "ParseGoSum() failed")
	}
	if !repo.GetGoPrimitive() {
		// check go.sum file
		if err := cleanGoDepsCheckOk(repo); err != nil {
			log.Info(repo.GetGoPath(), "forge.FinalGoDepsCheck() failed. boo.")
			return err
		}
	}
	if repo.Exists("go.sum") {
		// try to trim junk
		log.Info(repo.GetGoPath(), "Running: trimGoSum()")
		if err := trimGoSum(repo); err != nil {
			log.Info(repo.GetGoPath(), "trimGoSum() failed", err)
			return err
		}
	}
	// put the files in the notes section in git
	// this way, git commits are not messed up
	// with this autogenerated code
	if err := saveAsMetadata(repo); err != nil {
		log.Info(repo.GetGoPath(), "save go.mod as git metadata failed", err)
		return err
	}
	// everything worked!
	return nil
}
  |