summaryrefslogtreecommitdiff
path: root/doClone.go
blob: 528edd08dbe07346f9acf1e8ed03d0895e36345d (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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"strings"

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

//
// go-clone everything from wit
//

func doClone() error {
	initForge()

	data, err := resources.ReadFile("resources/repomap")
	if err != nil {
		log.Info("open repomap failed", err)
		return err
	}
	if len(data) == 0 {
		log.Info("resources/repomap is empty")
		return config.ErrEmpty
	}

	for _, line := range strings.Split(string(data), "\n") {
		if line == "" {
			continue
		}
		if strings.HasPrefix(line, "#") {
			continue
		}
		parts := strings.Fields(line)
		gopath := parts[0]
		repo := me.forge.Repos.FindByNamespace(gopath)
		if repo != nil {
			if argv.Verbose {
				log.Info("already have", repo.FullPath)
			}
			continue
		}
		var cmd []string
		cmd = []string{"go-clone", "--non-recursive", gopath}
		if argv.DryRun {
			log.Info("run:", cmd)
		} else {
			log.Info("should run:", cmd)
			if _, err := shell.RunRealtimeError(cmd); err != nil {
				if !argv.Force {
					badExit(err)
				}
			}
		}
	}
	return nil
}