This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
git.go
100 lines (84 loc) · 1.97 KB
/
git.go
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
package main
import (
"strings"
)
// Pulls source for indiepkg.
func pullSrcRepo(silent bool) bool {
output, err := runCommand(indiePkgSrcPath, "git", "pull", "--no-tags")
errorLog(err, "An error occurred while pulling source code for IndiePKG. Git output:\n%s", output)
if strings.Contains(output, "Already up to date.") {
if !silent {
if force {
log(3, "IndiePKG already up to date, but force is on, so continuing.")
return false
}
log(0, "IndiePKG already up to date")
}
return true
}
rawLog(output + "\n")
return false
}
// Clones indiepkg source.
func cloneSrcRepo() {
log(1, "Cloning IndiePKG source with branch %s...", config.Updating.Branch)
runCommandRealTime(
mainPath,
"git",
"clone",
"--branch",
config.Updating.Branch,
"--progress",
"--no-tags",
"--depth",
"1",
"https://github.com/talwat/indiepkg.git",
indiePkgSrcPath,
)
}
// Clones source code for a package.
func clonePkgRepo(pkg Package, cloneDir string) {
log(1, "Cloning source code for %s...", bolden(pkg.Name))
if pkg.Branch == "" {
runCommandRealTime(
cloneDir,
"git",
"clone",
"--no-tags",
"--progress",
"--depth",
"1",
pkg.URL,
pkg.Name,
)
} else {
log(1, "Getting branch %s...", pkg.Branch)
debugLog("Cloning to %s on branch %s.", cloneDir+pkg.Name, pkg.Branch)
runCommandRealTime(
cloneDir,
"git",
"clone",
"--branch",
pkg.Branch,
"--no-tags",
"--progress",
"--depth",
"1",
pkg.URL,
pkg.Name,
)
}
}
// Pulls source code for a package.
func pullPkgRepo(pkgName string) (bool, bool) {
output, err := runCommand(srcPath+pkgName, "git", "pull", "--no-tags")
debugLog("Git output from pull:\n%s", output)
// Check git output
if strings.Contains(output, "Already up to date.") {
return true, false
} else if strings.Contains(output, "not a git repository") {
return false, true
}
errorLog(err, "An error occurred while pulling source code for %s", bolden(pkgName))
return false, false
}