summaryrefslogtreecommitdiff
path: root/repomap.go
blob: 8b23368f5511b3d25b63e0f87541b037c0635c89 (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
package main

import (
	"os"
	"strings"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

func repomap() {
	var changed bool = false
	if argv.Repomap == "" {
		return
	}
	data, _ := os.ReadFile(argv.Repomap)

	for _, line := range strings.Split(string(data), "\n") {
		if line == "" {
			continue
		}
		if strings.HasPrefix(line, "#") {
			continue
		}
		parts := strings.Fields(line)
		gopath := parts[0]
		url := "https://" + parts[1]
		var comment string
		if len(parts) > 1 {
			comment = strings.Join(parts[2:], " ")
		}
		repo := me.forge.Repos.FindByGoPath(gopath)
		if argv.Force && argv.Clone {
			cmd := []string{"go-clone", "--recursive", gopath}
			shell.RunRealtime(cmd)
			continue
		}
		if repo == nil {
			if argv.Clone {
				// me.forge.Clone(gopath)
			} else {
				log.Info(gopath, "need to clone")
			}
		} else {
			if repo.URL != url {
				log.Info(gopath, "url wrong", repo.URL, "vs", url)
				log.Info("\tcomment", comment)
				repo.URL = url
				changed = true
			}
			if repo.Desc != comment && !(comment == "") {
				log.Info(gopath, "comment wrong", repo.Desc, "vs", comment)
				repo.Desc = comment
				changed = true
			}
		}
	}

	if changed {
		me.forge.Repos.ConfigSave()
		log.Info("config saved")
		os.Exit(0)
	}
}