-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go.old
More file actions
122 lines (112 loc) · 3.18 KB
/
Copy pathmain.go.old
File metadata and controls
122 lines (112 loc) · 3.18 KB
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
114
115
116
117
118
119
120
121
122
package main
import (
"flag"
"fmt"
"github.com/everfore/exc"
)
var (
quit = false
force = false
commit = ""
only_commit = ""
remote = ""
branch = ""
remote_branch = ""
tag = ""
status = false
ignore_dlt_tag = false // delete the tag after 25 sec
)
func init() {
flag.BoolVar(&quit, "q", false, "-q: quit add all, just push the committed code \n\tgit push")
flag.BoolVar(&force, "f", false, "-f: push --force")
flag.StringVar(&only_commit, "om", "", "-om $commit,only commit no push \n\tgit commit $commit")
flag.BoolVar(&status, "s", false, "git status")
flag.StringVar(&commit, "m", "", "-m $commit, commit and push \n\tgit add -A;git commit $commit;git push")
flag.StringVar(&remote, "r", "origin", "-r $remote \n\tgit push $origin")
flag.StringVar(&branch, "b", "", "-b $branch \n\tgit push $origin $branch:$remote_branch")
flag.StringVar(&remote_branch, "rb", "", "-rb $remote_branch \n\tgit push $origin $branch:$remote_branch")
flag.StringVar(&tag, "t", "", "-t $tag \n\tgit tag -a $tag -m $tag;git push $origin --tags $tag:$tag")
flag.BoolVar(&ignore_dlt_tag, "d", false, "-d: delete the tag after 50 seconds \n\tgit tag -d $tag;git push $origin --tags :$tag")
}
func main() {
flag.Parse()
first := "git add ."
var git *exc.CMD
git = exc.NewCMD(first).Wd().Debug()
var err error
if status {
git.Reset("git status").Execute()
return
}
cb := currentBranch()
remote_branch = cb
if branch == "nil" {
branch = ""
} else {
branch = cb
}
gitCmd := ""
if quit {
if force {
gitCmd = fmt.Sprintf("git push -f %s %s:%s", remote, branch, remote_branch)
} else {
gitCmd = fmt.Sprintf("git push %s %s:%s", remote, branch, remote_branch)
}
git.Reset(gitCmd).Execute()
goto TAG
}
if len(only_commit) > 0 {
fmt.Println("only_commit", only_commit)
only_commit = fmt.Sprintf(`git commit -m %s`, only_commit)
_ = git.Reset(only_commit).Execute()
return
}
_ = git.Execute()
if len(commit) > 0 {
commit = fmt.Sprintf(`git commit -m %s`, commit)
} else {
if len(tag) > 0 {
commit = fmt.Sprintf("git commit -m %s", tag)
} else {
commit = `git commit -m same+as+the+last+commit`
}
}
_ = git.Reset(commit).Execute()
if force {
gitCmd = fmt.Sprintf("git push -f %s %s:%s", remote, branch, remote_branch)
} else {
gitCmd = fmt.Sprintf("git push %s %s:%s", remote, branch, remote_branch)
}
git.Reset(gitCmd).Execute()
TAG:
if len(tag) > 0 {
_, err = git.Reset(fmt.Sprintf("git tag -a %s -m %s", tag, tag)).DoNoTime()
if checkerr(err) {
return
}
git.Reset(fmt.Sprintf("git push %s --tag %s:%s", remote, tag, tag)).Execute()
fmt.Println("ignore_dlt_tag:", ignore_dlt_tag)
if ignore_dlt_tag {
return
}
fmt.Printf("%d seconds later...\n", 25)
git.Reset(fmt.Sprintf("git tag -d %s", tag)).ExecuteAfter(25)
git.Reset(fmt.Sprintf("git push %s --tag :%s", remote, tag)).Execute()
}
}
func currentBranch() string {
bs, err := exc.NewCMD("git rev-parse --abbrev-ref HEAD").DoNoTime()
if err != nil {
panic(err)
}
cb := string(bs[:len(bs)-1])
fmt.Printf("* %s\n", cb)
return cb
}
func checkerr(err error) bool {
if err != nil {
fmt.Println(err)
return true
}
return false
}