1
1
#!/usr/bin/env python3
2
2
3
+ import contextlib
3
4
import subprocess
4
5
5
6
@@ -13,10 +14,30 @@ def exec_cmd(cmd, input=None):
13
14
return str (stdout , 'utf-8' )
14
15
15
16
17
+ @contextlib .contextmanager
18
+ def disable_show_signature ():
19
+ local_flag = exec_cmd (
20
+ ["git" , "config" , "--local" , "--get" , "log.showSignature" ]
21
+ ).strip ()
22
+ exec_cmd (
23
+ ["git" , "config" , "--local" , "log.showSignature" ,
24
+ "false" ]
25
+ )
26
+ yield
27
+ if local_flag :
28
+ exec_cmd (
29
+ ["git" , "config" , "--local" , "log.showSignature" , local_flag ]
30
+ )
31
+ else :
32
+ exec_cmd (
33
+ ["git" , "config" , "--local" , "--unset" , "log.showSignature" ]
34
+ )
35
+
36
+
16
37
def get_diff (tag ):
17
- return exec_cmd ([
38
+ return [ l for l in exec_cmd ([
18
39
"git" , "log" , "--pretty=%h %s" , "--no-merges" , "{}..HEAD" .format (tag )
19
- ]).splitlines ()
40
+ ]).splitlines () if not l . startswith ( "gpg" )]
20
41
21
42
22
43
def get_last_tag ():
@@ -61,36 +82,44 @@ def show(tag):
61
82
return exec_cmd (["git" , "show" , tag ])
62
83
63
84
64
- def create_tag (tag , annotation ):
65
- exec_cmd (["git" , "tag" , "-s" , "-F-" , tag ], input = annotation )
85
+ def create_tag (tag , annotation , sign ):
86
+ cmd = ["git" , "tag" ]
87
+ if sign :
88
+ cmd .append ("--sign" )
89
+ exec_cmd (cmd + ["-F-" , tag ], input = annotation )
66
90
67
91
68
92
def delete_tag (tag ):
69
93
exec_cmd (["git" , "tag" , "-d" , tag ])
70
94
71
95
72
96
def sdist (tag ):
73
- create_tag (tag , 'sdist' )
97
+ create_tag (tag , 'sdist' , False )
74
98
exec_cmd (["python" , "setup.py" , "sdist" ])
75
99
delete_tag (tag )
76
100
77
101
78
- def bump (tag , annotation ):
102
+ def bump (tag , annotation , sign ):
79
103
sdist (tag )
80
104
exec_cmd (["git" , "add" , "AUTHORS" , "ChangeLog" ])
81
- exec_cmd (["git" , "commit" , "-m" , "Bump version %s" % tag ])
105
+ cmd = ["git" , "commit" ]
106
+ if sign :
107
+ cmd .append ("--sign" )
108
+ exec_cmd (cmd + ["-m" , "Bump version %s" % tag ])
82
109
sdist (tag )
83
110
exec_cmd (["git" , "add" , "ChangeLog" ])
84
- exec_cmd ([ "git" , "commit" , "--amend" , "--no-edit" ])
85
- create_tag (tag , annotation )
111
+ exec_cmd (cmd + [ "--amend" , "--no-edit" ])
112
+ create_tag (tag , annotation , sign )
86
113
87
114
88
115
def main (args ):
89
- tag , annotation = get_info (args .version )
116
+ with disable_show_signature ():
117
+ tag , annotation = get_info (args .version )
90
118
if args .dry_run :
91
119
print (annotation )
92
120
else :
93
- bump (tag , annotation )
121
+ with disable_show_signature ():
122
+ bump (tag , annotation , args .sign )
94
123
print (show (tag ))
95
124
96
125
a = input ('Push new tag? [y/N]: ' )
@@ -108,6 +137,12 @@ if __name__ == '__main__':
108
137
help = "specify version, otherwise the current version "
109
138
"will be incremented by 1" )
110
139
parser .add_argument (
140
+ '-s' ,
141
+ '--sign' ,
142
+ action = 'store_true' ,
143
+ help = "sign a tag and commits" )
144
+ parser .add_argument (
145
+ '-r' ,
111
146
'--dry-run' ,
112
147
action = 'store_true' ,
113
148
help = "print tag's number and annotation" )
0 commit comments