-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitil.go
More file actions
184 lines (182 loc) · 4.68 KB
/
gitil.go
File metadata and controls
184 lines (182 loc) · 4.68 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package main
import (
"bufio"
"fmt"
"github.com/stevenbraham/gitil/commands/branches"
"github.com/stevenbraham/gitil/commands/other"
"github.com/stevenbraham/gitil/commands/sync"
"gopkg.in/urfave/cli.v1"
"os"
)
func main() {
//init app
app := cli.NewApp()
app.Name = "Gitil"
app.Version = "0.1.0"
app.Usage = "Gitil is a wrapper for git that has commands for common tasks"
app.Action = func(c *cli.Context) error {
app.Command("help").Run(c)
return nil
}
app.Commands = []cli.Command{
{
Name: "clone",
Aliases: []string{"c"},
Category: "Sync commands",
Usage: "clones a repository",
Action: func(c *cli.Context) error {
repoUrl := c.Args().First()
if repoUrl == "" {
fmt.Println("Usage: gitil clone [url]")
os.Exit(1)
}
sync.CloneRepository(repoUrl)
fmt.Println("Cloned", repoUrl)
return nil
},
},
{
Name: "fetch-all",
Aliases: []string{"fa"},
Category: "Sync commands",
Usage: "Does a git fetch --all",
Action: func(c *cli.Context) error {
sync.FetchAll()
return nil
},
},
{
Name: "create-tag",
Aliases: []string{"ct"},
Category: "Sync commands",
Usage: "Adds a tag to the last commit and pushes the tag to the origin",
Action: func(c *cli.Context) error {
tag := c.Args().First()
if tag == "" {
fmt.Println("Usage: gitil create-tag [tag]")
os.Exit(1)
}
sync.CreateTag(tag)
fmt.Println("Created tag", tag)
return nil
},
},
{
Name: "to-master",
Aliases: []string{"tm"},
Category: "Merge commands",
Usage: "Merges the selected branch into master",
Action: func(c *cli.Context) error {
sync.FetchAll()
var branch = branches.GetCurrentBranch()
//if not empty use the branch provided by the command line
if c.Args().First() != "" {
branch = c.Args().First()
}
branches.MergeBranch(branch, "master")
fmt.Println("Merged", branch, " into master")
return nil
},
},
{
Name: "from-master",
Aliases: []string{"fm"},
Category: "Merge commands",
Usage: "Merges master into the selected branch",
Action: func(c *cli.Context) error {
sync.FetchAll()
var branch = branches.GetCurrentBranch()
//if not empty use the branch provided by the command line
if c.Args().First() != "" {
branch = c.Args().First()
}
branches.MergeBranch("master", branch)
fmt.Println("Merged master into", branch)
branches.CheckoutBranch(branch)
return nil
},
},
{
Name: "insta-commit",
Aliases: []string{"ic"},
Category: "Sync commands",
Usage: "Adds all, commits and pushes",
Action: func(c *cli.Context) error {
message := c.Args().First()
if message == "" {
fmt.Println("Usage: gitil insta-commit [message]")
os.Exit(1)
}
branches.AddAll()
branches.Commit(message)
sync.Push()
fmt.Println("Commited", c.Args().First())
return nil
},
},
{
Name: "master-all",
Aliases: []string{"ma"},
Category: "Merge commands",
Usage: "Merges master in all branches",
Action: func(c *cli.Context) error {
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("DANGER! This merges master in all branches, do you want to continue [y,N]:")
for scanner.Scan() {
if scanner.Text() == "y" {
sync.FetchAll()
var ownBranch = branches.GetCurrentBranch()
//if not empty use the branch provided by the command line
if c.Args().First() != "" {
ownBranch = c.Args().First()
}
for _, branch := range branches.GetBranches() {
if branch != ownBranch && branch != "master" {
branches.MergeBranch("master", branch)
fmt.Println("Merged master into", branch)
}
}
return nil
}
break
}
return nil
},
},
{
Name: "reset-hard",
Aliases: []string{"rh"},
Category: "Other commands",
Usage: "Deletes all changes",
Action: func(c *cli.Context) error {
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("DANGER! This deletes all your changes, do you want to continue [y,N]:")
for scanner.Scan() {
if scanner.Text() == "y" {
branches.ResetHard()
return nil
}
break
}
return nil
},
},
{
Name: "create-gitignore",
Aliases: []string{"gi"},
Category: "Other commands",
Usage: "Downloads a GitIgnore from gitignore.io to .gitignore",
Action: func(c *cli.Context) error {
params := c.Args().First()
if params == "" {
fmt.Println("Usage: gitil create-gitignore [platform,platform]")
os.Exit(1)
}
other.CreateGitIgnore(params)
fmt.Println("Created new gitignore")
return nil
},
},
}
app.Run(os.Args)
}