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

import (
	"errors"

	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

// this will make go.mod and go.sum files no matter what
// thsi will clean out everything and start over
func doForce(repo *gitpb.Repo) error {
	// var perfect bool = true
	if !repo.IsValid() {
		log.Info(repo.GoPath, "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.GoPath + " is invalid. fix your repository list with 'forge' first")
	}
	log.Info(repo.GoPath, "is valid according to forge")

	// purge the git meta-data if --force
	repo.Run([]string{"git", "notes", "remove"})

	// erase the go.mod and go.sum files
	eraseGoMod(repo)

	// actually will re-create go.sum and go.mod now
	if err := redoGoMod(repo); err != nil {
		return err
	}

	// the first time, it'll attempt to fix some stuff
	cleanGoDepsCheckOk(repo)

	// try to trim junk
	if err := trimGoSum(repo); err != nil {
		return err
	}
	repo.ParseGoSum()

	configSave = true
	return nil
}