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
|
package gitpb
import (
"fmt"
"github.com/go-cmd/cmd"
"go.wit.com/log"
)
func (r *Repo) MergeToDevel() (*cmd.Status, error) {
r.Reload()
if r.GetCurrentBranchName() != r.GetDevelBranchName() {
return nil, fmt.Errorf("repo not on devel branch")
}
if r.CheckDirty() {
return nil, fmt.Errorf("repo is dirty")
}
devel := r.GetDevelBranchName()
user := r.GetUserBranchName()
log.Info(r.FullPath, "MergeToDevel() merging from", user, "into", devel)
cmd := []string{"git", "merge", user}
result := r.RunRealtimeVerbose(cmd)
if result.Error != nil {
log.Log(WARN, "MergeToDevel() failed", r.GetFullPath())
return nil, result.Error
}
if !r.IsBranchRemote(devel) {
r.Reload() // rescan the repo
// devel branch is not remote. do not try 'git push'
return nil, nil
}
if r.GetReadOnly() {
r.Reload() // rescan the repo
// devel branch is read only. you can not git push
return nil, nil
}
// it seems like we have write access. lets find out!
cmd = []string{"git", "push"}
result = r.RunRealtimeVerbose(cmd)
if result.Error != nil {
log.Log(WARN, "GitPushToDevel() failed", r.GetFullPath())
return nil, result.Error
}
r.Reload() // rescan the repo
return nil, nil
}
func (r *Repo) MergeToMaster() (*cmd.Status, error) {
r.Reload()
if r.GetCurrentBranchName() != r.GetMasterBranchName() {
return nil, fmt.Errorf("repo not on master branch")
}
if r.GetReadOnly() {
r.Reload() // rescan the repo
// master branch is read only. you can not git push
return nil, fmt.Errorf("can't merge to master on read only() repos")
}
if r.CheckDirty() {
return nil, fmt.Errorf("repo is dirty")
}
master := r.GetMasterBranchName()
devel := r.GetDevelBranchName()
log.Info("MergeToMaster() merging from", devel, "into", master)
cmd := []string{"git", "merge", devel}
result := r.RunRealtimeVerbose(cmd)
if result.Error != nil {
log.Log(WARN, "MergeToMaster() failed", r.GetFullPath())
return nil, result.Error
}
if r.GetReadOnly() {
r.Reload() // rescan the repo
// master branch is read only. you can not git push
return nil, nil
}
// it seems like we have write access. lets find out!
cmd = []string{"git", "push"}
result = r.RunRealtimeVerbose(cmd)
if result.Error != nil {
log.Log(WARN, "GitPushToMaster() failed", r.GetFullPath())
return nil, result.Error
}
r.Reload() // rescan the repo
return nil, nil
}
|