-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitService.go
113 lines (78 loc) · 2.15 KB
/
gitService.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
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"bytes"
"fmt"
"os/exec"
"github.com/fatih/color"
)
var execCommand = exec.Command
func printOutput(buffer ...*bytes.Buffer) {
for _, output := range buffer {
if output != nil {
fmt.Print(string(output.Bytes()))
}
}
}
// FetchLatest fetches all remote branches
func FetchLatest(directory string) bool {
color.Green("FETCH: %s", directory)
commandName := "git"
args := []string{"fetch", "--all"}
command := execCommand(commandName, args...)
command.Dir = directory
commandOutput := &bytes.Buffer{}
commandErrorOutput := &bytes.Buffer{}
command.Stdout = commandOutput
command.Stderr = commandErrorOutput
err := command.Run()
printOutput(commandOutput, commandErrorOutput)
if err != nil {
fmt.Println(err.Error())
color.Red("FETCH ERROR: %s", directory)
return false
}
color.Green("FETCH SUCCESS: %s", directory)
return true
}
// PullLatest retrieves the most recent code from the codebase
func PullLatest(directory string) bool {
color.Green("PULL: %s", directory)
commandName := "git"
args := []string{"pull", "--all"}
command := execCommand(commandName, args...)
command.Dir = directory
commandOutput := &bytes.Buffer{}
commandErrorOutput := &bytes.Buffer{}
command.Stdout = commandOutput
command.Stderr = commandErrorOutput
err := command.Run()
printOutput(commandOutput, commandErrorOutput)
if err != nil {
fmt.Println(err.Error())
color.Red("PULL ERROR: %s", directory)
return false
}
color.Green("PULL SUCCESS: %s", directory)
return true
}
// PushLatest pushes all of the branches to bitbucket
func PushLatest(directory string) bool {
color.Green("PUSH: %s", directory)
commandName := "git"
args := []string{"push", "bitbucket", "--all"}
command := execCommand(commandName, args...)
command.Dir = directory
commandOutput := &bytes.Buffer{}
commandErrorOutput := &bytes.Buffer{}
command.Stdout = commandOutput
command.Stderr = commandErrorOutput
err := command.Run()
printOutput(commandOutput, commandErrorOutput)
if err != nil {
fmt.Println(err.Error())
color.Red("PUSH ERROR: %s", directory)
return false
}
color.Green("PUSH SUCCESS: %s", directory)
return true
}