@@ -53,6 +53,24 @@ def check_staged_changes() -> bool:
53
53
return len (subprocess .run (["git" , "diff" , "--name-only" , "--cached" ], capture_output = True ).stdout ) > 0
54
54
55
55
56
+ def push ():
57
+ print ("[Info]\t Pulling to check... " , end = "" )
58
+
59
+ pull_process = subprocess .run (
60
+ ["git" , "pull" ], capture_output = True )
61
+
62
+ if "up to date." in str (pull_process .stdout ):
63
+ print ("ok." )
64
+ else :
65
+ print ("warning." )
66
+ print (
67
+ "Remote contains changes not present in local. Make sure remote is update before bumping" )
68
+ exit (1 )
69
+
70
+ print ("[Info]\t Pushing to origin..." )
71
+ subprocess .check_output (["git" , "push" , "origin" , "main" , "--tags" ])
72
+
73
+
56
74
# Main:
57
75
try :
58
76
subprocess .check_output (['cargo' , 'bump' , '--version' ])
@@ -66,6 +84,7 @@ def check_staged_changes() -> bool:
66
84
67
85
bump_parser = sub_parsers .add_parser (name = "bump" )
68
86
undo_parser = sub_parsers .add_parser (name = "undo" )
87
+ push_parser = sub_parsers .add_parser (name = "push" )
69
88
70
89
bump_parser .add_argument ("-t" , "--type" , choices = bump_types , default = "" ,
71
90
help = "Whether to bump patch, minor, or major versions." )
@@ -154,21 +173,7 @@ def check_staged_changes() -> bool:
154
173
args .push = True
155
174
156
175
if args .push :
157
- print ("[Info]\t Pulling to check... " , end = "" )
158
-
159
- pull_process = subprocess .run (
160
- ["git" , "pull" ], capture_output = True )
161
-
162
- if "Already up to date." in str (pull_process .stdout ):
163
- print ("ok." )
164
- else :
165
- print ("warning." )
166
- print (
167
- "Remote contains changes not present in local. Make sure remote is update before bumping" )
168
- exit (1 )
169
-
170
- print ("[Info]\t Pushing to origin..." )
171
- subprocess .check_output (["git" , "push" , "origin" , "main" , "--tags" ])
176
+ push ()
172
177
else :
173
178
print ("[Info]\t Applied changes locally. Run 'git push origin main --tags' to push tags to remote and trigger a workflow." )
174
179
@@ -211,7 +216,8 @@ def check_staged_changes() -> bool:
211
216
print ("[Error]\t Unable to undo. Previous commit isn't tagged." )
212
217
213
218
exit (1 )
214
-
219
+ elif args .command == "push" :
220
+ push ()
215
221
elif args .command is None :
216
222
parser .print_help ()
217
223
exit (0 )
0 commit comments