-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.go
More file actions
57 lines (49 loc) · 902 Bytes
/
Copy pathupdate.go
File metadata and controls
57 lines (49 loc) · 902 Bytes
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
package gitwrapper
import "strings"
func (rc RepoConfig) Update(merge bool) error {
o, err := runGitCmd(true, "git status")
if err != nil {
return err
}
var clean bool
if strings.Contains(o, "nothing to commit, working tree clean") {
clean = true
}
// step 1
if !clean {
_, err = runGitCmd(true, "git stash")
if err != nil {
return err
}
}
// step 2
_, err = runGitCmd(true, "git fetch -p")
if err != nil {
return err
}
// step 3
if merge {
_, err = runGitCmd(true, "git merge origin/"+rc.DefaultBranch)
if err != nil {
return err
}
} else {
_, err = runGitCmd(true, "git rebase origin/"+rc.CurrentBranch)
if err != nil {
return err
}
}
// step 4
if clean {
_, err = runGitCmd(true, "git status")
if err != nil {
return err
}
} else {
_, err = runGitCmd(true, "git stash pop")
if err != nil {
return err
}
}
return nil
}