Skip to content

Commit f4e3bf9

Browse files
authored
Merge pull request #4 from arzkar/add_bump_command
Add bump command
2 parents e298646 + 8b16fc7 commit f4e3bf9

File tree

11 files changed

+490
-61
lines changed

11 files changed

+490
-61
lines changed

.bumpversion.cfg

Lines changed: 0 additions & 31 deletions
This file was deleted.

.git-utils-bump.cfg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[bumpversion]
2+
current_version = 0.5.0
3+
commit = True
4+
tag = False
5+
tag_format = v{tag}
6+
7+
[bumpversion:file:cmd/root.go]
8+
search = git-utils v{current_version}
9+
replace = git-utils v{new_version}
10+
11+
[bumpversion:file:README.md]
12+
search = git-utils v{current_version}
13+
replace = git-utils v{new_version}
14+
15+
[bumpversion:file:utils/update_checker.go]
16+
search = v{current_version}
17+
replace = v{new_version}

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ A CLI for performing various operations on git repositories
1010
- `grep`: Search for a pattern in file contents across multiple repositories.
1111
- `checkout`: Checkout a branch for all the repositories at once.
1212
- `tag`: Use custom tag messages for git repositories
13+
- `bump`: Version bump the version
1314

1415
# Installation
1516

@@ -30,7 +31,7 @@ go install github.com/arzkar/git-utils@latest
3031

3132
```
3233
> git-utils
33-
git-utils v0.4.0
34+
git-utils v0.5.0
3435
Copyright (c) Arbaaz Laskar <arzkar.dev@gmail.com>
3536
3637
A CLI for performing various operations on git repositories
@@ -39,13 +40,14 @@ Usage:
3940
git-utils [command]
4041
4142
Available Commands:
43+
bump Version bump the version
4244
checkout Checkout a branch in all repositories
4345
completion Generate the autocompletion script for the specified shell
4446
fetch Fetch all or specified branches
4547
grep Search for a pattern in files
4648
help Help about any command
4749
pull Pull all or specified branches
48-
tag Create a new tag with custom message for the repository
50+
tag Create a new tag with a custom message for the repository
4951
5052
Flags:
5153
--config Show app config
@@ -127,3 +129,35 @@ Sample `config.json`:
127129
```
128130

129131
Tag Templates variables available: `repo_owner, repo_name, prevTag, newTag`
132+
133+
### Bump
134+
135+
The `bump` command bumps the version set in the `.git-utils-bump.cfg` and search & replaces the version for the files set in the config file using the subcommands: `major`, `minor` & `patch`
136+
137+
Command:
138+
`git-utils bump <command>`
139+
140+
Example:
141+
`git-utils bump minor`
142+
143+
Sample `.git-utils.bump.cfg:
144+
145+
```yml
146+
[bumpversion]
147+
current_version = 0.4.0
148+
commit = True
149+
tag = True
150+
tag_format = v{tag}
151+
152+
[bumpversion:file:cmd/root.go]
153+
search = git-utils v{current_version}
154+
replace = git-utils v{new_version}
155+
156+
[bumpversion:file:README.md]
157+
search = git-utils v{current_version}
158+
replace = git-utils v{new_version}
159+
160+
[bumpversion:file:utils/update_checker.go]
161+
search = v{current_version}
162+
replace = v{new_version}
163+
```

cmd/bump.go

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/arzkar/git-utils/utils"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var bumpCmd = &cobra.Command{
11+
Use: "bump",
12+
Short: "Version bump the version",
13+
Run: bumpVersion,
14+
}
15+
16+
var majorCmd = &cobra.Command{
17+
Use: "major",
18+
Short: "Version bump the major version",
19+
Run: bumpMajor,
20+
}
21+
22+
var minorCmd = &cobra.Command{
23+
Use: "minor",
24+
Short: "Version bump the minor version",
25+
Run: bumpMinor,
26+
}
27+
28+
var patchCmd = &cobra.Command{
29+
Use: "patch",
30+
Short: "Version bump the patch version",
31+
Run: bumpPatch,
32+
}
33+
34+
func init() {
35+
rootCmd.AddCommand(bumpCmd)
36+
bumpCmd.AddCommand(majorCmd)
37+
bumpCmd.AddCommand(minorCmd)
38+
bumpCmd.AddCommand(patchCmd)
39+
}
40+
41+
func bumpVersion(cmd *cobra.Command, args []string) {
42+
currentVersion, err := utils.GetCurrentVersion()
43+
if err != nil {
44+
fmt.Println("Failed to read current version:", err)
45+
return
46+
}
47+
48+
newVersion := utils.IncrementVersion(currentVersion)
49+
50+
err = utils.UpdateFiles(currentVersion, newVersion)
51+
if err != nil {
52+
fmt.Println("Failed to update files:", err)
53+
return
54+
}
55+
56+
commitEnabled, err := utils.GetCommitOption()
57+
if err != nil {
58+
fmt.Println("Failed to read commit option:", err)
59+
return
60+
}
61+
commitMessage := fmt.Sprintf("Bump version: %s → %s", currentVersion, newVersion)
62+
if commitEnabled {
63+
err = utils.CommitChanges(currentVersion, newVersion, commitMessage)
64+
if err != nil {
65+
fmt.Println("Failed to commit changes:", err)
66+
return
67+
}
68+
}
69+
70+
tagEnabled, err := utils.GetTagOption()
71+
if err != nil {
72+
fmt.Println("Failed to read tag option:", err)
73+
return
74+
}
75+
76+
if tagEnabled {
77+
err = utils.CreateTag(newVersion, commitMessage)
78+
if err != nil {
79+
fmt.Println("Failed to create tag:", err)
80+
return
81+
}
82+
}
83+
84+
fmt.Printf("Bump version: %s → %s\n", currentVersion, newVersion)
85+
}
86+
87+
func bumpMajor(cmd *cobra.Command, args []string) {
88+
currentVersion, err := utils.GetCurrentVersion()
89+
if err != nil {
90+
fmt.Println("Failed to read current version:", err)
91+
return
92+
}
93+
94+
newVersion := utils.BumpMajorVersion(currentVersion)
95+
96+
err = utils.UpdateFiles(currentVersion, newVersion)
97+
if err != nil {
98+
fmt.Println("Failed to update files:", err)
99+
return
100+
}
101+
102+
commitEnabled, err := utils.GetCommitOption()
103+
if err != nil {
104+
fmt.Println("Failed to read commit option:", err)
105+
return
106+
}
107+
108+
commitMessage := fmt.Sprintf("Bump version: %s → %s", currentVersion, newVersion)
109+
if commitEnabled {
110+
err = utils.CommitChanges(currentVersion, newVersion, commitMessage)
111+
if err != nil {
112+
fmt.Println("Failed to commit changes:", err)
113+
return
114+
}
115+
}
116+
117+
tagEnabled, err := utils.GetTagOption()
118+
if err != nil {
119+
fmt.Println("Failed to read tag option:", err)
120+
return
121+
}
122+
123+
if tagEnabled {
124+
err = utils.CreateTag(newVersion, commitMessage)
125+
if err != nil {
126+
fmt.Println("Failed to create tag:", err)
127+
return
128+
}
129+
}
130+
131+
fmt.Printf("Bump version: %s → %s\n", currentVersion, newVersion)
132+
}
133+
134+
func bumpMinor(cmd *cobra.Command, args []string) {
135+
currentVersion, err := utils.GetCurrentVersion()
136+
if err != nil {
137+
fmt.Println("Failed to read current version:", err)
138+
return
139+
}
140+
141+
newVersion := utils.BumpMinorVersion(currentVersion)
142+
143+
err = utils.UpdateFiles(currentVersion, newVersion)
144+
if err != nil {
145+
fmt.Println("Failed to update files:", err)
146+
return
147+
}
148+
149+
commitEnabled, err := utils.GetCommitOption()
150+
if err != nil {
151+
fmt.Println("Failed to read commit option:", err)
152+
return
153+
}
154+
155+
commitMessage := fmt.Sprintf("Bump version: %s → %s", currentVersion, newVersion)
156+
if commitEnabled {
157+
err = utils.CommitChanges(currentVersion, newVersion, commitMessage)
158+
if err != nil {
159+
fmt.Println("Failed to commit changes:", err)
160+
return
161+
}
162+
}
163+
164+
tagEnabled, err := utils.GetTagOption()
165+
if err != nil {
166+
fmt.Println("Failed to read tag option:", err)
167+
return
168+
}
169+
170+
if tagEnabled {
171+
err = utils.CreateTag(newVersion, commitMessage)
172+
if err != nil {
173+
fmt.Println("Failed to create tag:", err)
174+
return
175+
}
176+
}
177+
178+
fmt.Printf("Bump version: %s → %s\n", currentVersion, newVersion)
179+
}
180+
181+
func bumpPatch(cmd *cobra.Command, args []string) {
182+
currentVersion, err := utils.GetCurrentVersion()
183+
if err != nil {
184+
fmt.Println("Failed to read current version:", err)
185+
return
186+
}
187+
188+
newVersion := utils.BumpPatchVersion(currentVersion)
189+
190+
err = utils.UpdateFiles(currentVersion, newVersion)
191+
if err != nil {
192+
fmt.Println("Failed to update files:", err)
193+
return
194+
}
195+
196+
commitEnabled, err := utils.GetCommitOption()
197+
if err != nil {
198+
fmt.Println("Failed to read commit option:", err)
199+
return
200+
}
201+
202+
commitMessage := fmt.Sprintf("Bump version: %s → %s", currentVersion, newVersion)
203+
if commitEnabled {
204+
err = utils.CommitChanges(currentVersion, newVersion, commitMessage)
205+
if err != nil {
206+
fmt.Println("Failed to commit changes:", err)
207+
return
208+
}
209+
}
210+
211+
tagEnabled, err := utils.GetTagOption()
212+
if err != nil {
213+
fmt.Println("Failed to read tag option:", err)
214+
return
215+
}
216+
217+
if tagEnabled {
218+
err = utils.CreateTag(newVersion, commitMessage)
219+
if err != nil {
220+
fmt.Println("Failed to create tag:", err)
221+
return
222+
}
223+
}
224+
225+
fmt.Printf("Bump version: %s → %s\n", currentVersion, newVersion)
226+
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
var rootCmd = &cobra.Command{
2727
Use: "git-utils",
2828
Short: "A CLI for performing various operations on git repositories",
29-
Long: `git-utils v0.4.0
29+
Long: `git-utils v0.5.0
3030
Copyright (c) Arbaaz Laskar <arzkar.dev@gmail.com>
3131
3232
A CLI for performing various operations on git repositories

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
)
99

1010
require (
11+
github.com/go-ini/ini v1.67.0 // indirect
1112
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1213
github.com/mattn/go-colorable v0.1.13 // indirect
1314
github.com/mattn/go-isatty v0.0.17 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
22
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
33
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
4+
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
5+
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
46
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
57
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
68
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=

0 commit comments

Comments
 (0)