Skip to content

Commit 7b033c7

Browse files
committed
Add --push-last to git push tag upstream
1 parent 95f9339 commit 7b033c7

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ bumped v0.2.0 -> v1.2.0
3030
# delete the last tag
3131
$ gtbump --delete-last
3232
deleted v1.2.0
33+
34+
# push the last tag upstream(or --push-last=your_remote_name)
35+
$ gtbump --push-last
36+
pushing v0.3.0 to origin
3337
```
3438

3539
Check `gtbump --help` for more options.

gtbump/__init__.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/python
22
import argparse
33
import re
4+
from time import sleep
45
import subprocess
56
import sys
67

7-
__version__ = "0.3.0"
8+
__version__ = "1.0"
89

910
MAJOR = "major"
1011
MINOR = "minor"
@@ -83,24 +84,26 @@ def main():
8384
description="simple semver tag bump helper for git")
8485
p.add_argument("-ss", "--strip-suffix", action="store_true",
8586
dest="strip_suffix", help="strip existing suffx from tag (eg: -beta.0)")
86-
p.add_argument("-s", "--suffix", action="store", type=str,
87+
p.add_argument("-s", "--suffix", action="store", type=str, metavar="",
8788
dest="suffix", help="optional suffix to add to the tag (eg: -beta.0). Pass as =\"-beta\" if the first character is a dash")
8889
p.add_argument("-v", "--version", action="store_true", dest="version",
8990
help="show version")
9091

9192
g = p.add_argument_group("bump").add_mutually_exclusive_group()
92-
g.add_argument("-show", "--show", action="store_true",
93-
dest="show", help="show the closest (last) tag")
9493
g.add_argument("-init", "--init", action="store_true",
9594
dest="init", help="add tag v0.1.0 (when there are no tags)")
95+
g.add_argument("-show", "--show", action="store_true",
96+
dest="show", help="show last tag")
97+
g.add_argument("-push-last", "--push-last", action="store", type=str, nargs="?", const="origin", metavar="",
98+
dest="push_last", help="push the last tag upstream (default: origin). IMPORTANT: This skips pre-push hooks with --no-verify. eg: --push-last, --push-last=remote_name")
9699
g.add_argument("-delete-last", "--delete-last", action="store_true",
97-
dest="delete_last", help="deletes the closest (last) tag")
100+
dest="delete_last", help="delete the last tag")
98101
g.add_argument("-major", "--major", action="store_true",
99-
dest="major", help="bump the major version")
102+
dest="major", help="bump major version (vX.0.0)")
100103
g.add_argument("-minor", "--minor", action="store_true",
101-
dest="minor", help="bump the minor version")
104+
dest="minor", help="bump minor version (v0.X.0)")
102105
g.add_argument("-patch", "--patch", action="store_true",
103-
dest="patch", help="bump the patch version")
106+
dest="patch", help="bump patch version (v0.0.X)")
104107
args = p.parse_args()
105108

106109
if args.version:
@@ -124,11 +127,24 @@ def main():
124127
bump({MAJOR: 0, MINOR: 0, PATCH: 0,
125128
SUFFIX: ""}, MINOR, "", False)
126129
sys.exit(0)
130+
131+
elif args.push_last:
132+
tag = get_last_tag()["tag"]
133+
print("pushing {} to {}".format(tag, args.push_last))
134+
sleep(2);
135+
try:
136+
print(run("git push --no-verify {} {}".format(args.push_last, tag)))
137+
except Exception as e:
138+
print(e)
139+
sys.exit(1)
140+
sys.exit(0)
141+
127142
elif args.delete_last:
128143
tag = get_last_tag()["tag"]
129144
run("git tag -d {}".format(tag))
130145
print("deleted {}".format(tag))
131146
sys.exit(0)
147+
132148
else:
133149
# If there's a suffix, it should start with - or +.
134150
if args.suffix and args.suffix != "":

0 commit comments

Comments
 (0)