@@ -87,28 +87,24 @@ def __enter__(self) -> None:
87
87
if diff_exitcode ():
88
88
print ("Stashing changes." )
89
89
self .stashed = True
90
- subprocess .run ( # nosec
90
+ subprocess .check_call ( # nosec
91
91
[
92
92
"git" ,
93
93
"stash" ,
94
94
"--quiet" ,
95
95
"--include-untracked" ,
96
- ],
97
- check = True ,
98
- )
96
+ ])
99
97
100
98
def __exit__ (self , exc_type : Any , exc_value : Any , traceback : Any ) -> None :
101
99
if self .stashed :
102
100
print ("Restoring stashed changes." )
103
- subprocess .run ( # nosec
101
+ subprocess .check_call ( # nosec
104
102
[
105
103
"git" ,
106
104
"stash" ,
107
105
"pop" ,
108
106
"--quiet" ,
109
- ],
110
- check = True ,
111
- )
107
+ ])
112
108
113
109
114
110
class Checkout :
@@ -120,28 +116,24 @@ def __init__(self, branch: str) -> None:
120
116
def __enter__ (self ) -> None :
121
117
if self .branch != current_branch ():
122
118
print (f"Checking out { self .branch } (from { self .old_branch } )." )
123
- subprocess .run ( # nosec
119
+ subprocess .check_call ( # nosec
124
120
[
125
121
"git" ,
126
122
"checkout" ,
127
123
"--quiet" ,
128
124
self .branch ,
129
- ],
130
- check = True ,
131
- )
125
+ ])
132
126
133
127
def __exit__ (self , exc_type : Any , exc_value : Any , traceback : Any ) -> None :
134
128
if self .old_branch != current_branch ():
135
129
print (f"Moving back to { self .old_branch } ." )
136
- subprocess .run ( # nosec
130
+ subprocess .check_call ( # nosec
137
131
[
138
132
"git" ,
139
133
"checkout" ,
140
134
"--quiet" ,
141
135
self .old_branch ,
142
- ],
143
- check = True ,
144
- )
136
+ ])
145
137
146
138
147
139
class ResetOnExit :
@@ -153,15 +145,13 @@ def __enter__(self) -> None:
153
145
pass
154
146
155
147
def __exit__ (self , exc_type : Any , exc_value : Any , traceback : Any ) -> None :
156
- subprocess .run ( # nosec
148
+ subprocess .check_call ( # nosec
157
149
[
158
150
"git" ,
159
151
"reset" ,
160
152
"--quiet" ,
161
153
"--hard" ,
162
- ],
163
- check = True ,
164
- )
154
+ ])
165
155
166
156
167
157
@memoize
@@ -187,7 +177,7 @@ def fetch(*remotes: str) -> None:
187
177
branches, tags, and prunes stale references. Overwrites local tags if they
188
178
have been updated on the remote.
189
179
"""
190
- subprocess .run ( # nosec
180
+ subprocess .check_call ( # nosec
191
181
[
192
182
"git" ,
193
183
"fetch" ,
@@ -197,24 +187,20 @@ def fetch(*remotes: str) -> None:
197
187
"--force" ,
198
188
"--multiple" ,
199
189
* remotes ,
200
- ],
201
- check = True ,
202
- )
190
+ ])
203
191
204
192
205
193
def pull (remote : str ) -> None :
206
194
"""Pull changes from the current branch and remote."""
207
- subprocess .run ( # nosec
195
+ subprocess .check_call ( # nosec
208
196
[
209
197
"git" ,
210
198
"pull" ,
211
199
"--rebase" ,
212
200
"--quiet" ,
213
201
remote ,
214
202
current_branch (),
215
- ],
216
- check = True ,
217
- )
203
+ ])
218
204
219
205
220
206
def remote_slug (remote : str ) -> types .RepoSlug :
@@ -307,7 +293,7 @@ def release_tag_exists(tag: str) -> bool:
307
293
308
294
def tag (tag : str , message : str , sign : bool ) -> None :
309
295
"""Create a signed tag with a message."""
310
- subprocess .run ( # nosec
296
+ subprocess .check_call ( # nosec
311
297
[
312
298
"git" ,
313
299
"tag" ,
@@ -316,9 +302,7 @@ def tag(tag: str, message: str, sign: bool) -> None:
316
302
"--message" ,
317
303
message ,
318
304
tag ,
319
- ],
320
- check = True ,
321
- )
305
+ ])
322
306
323
307
324
308
def release_branches () -> list [str ]:
@@ -374,59 +358,101 @@ def current_tag() -> str:
374
358
]).decode ("utf-8" ).strip ())
375
359
376
360
361
+ def tag_has_signature (tag : str ) -> bool :
362
+ """Check if a tag has a signature."""
363
+ return b"-----BEGIN PGP SIGNATURE-----" in subprocess .check_output ( # nosec
364
+ [
365
+ "git" ,
366
+ "cat-file" ,
367
+ "tag" ,
368
+ tag ,
369
+ ])
370
+
371
+
372
+ def verify_tag (tag : str ) -> bool :
373
+ """Verify the signature of a tag."""
374
+ return (subprocess .run ( # nosec
375
+ [
376
+ "git" ,
377
+ "verify-tag" ,
378
+ "--verbose" ,
379
+ tag ,
380
+ ],
381
+ check = False ,
382
+ ).returncode == 0 )
383
+
384
+
385
+ def sign_tag (tag : str ) -> None :
386
+ """Sign a tag with its original message."""
387
+ subprocess .check_call ( # nosec
388
+ [
389
+ "git" ,
390
+ "tag" ,
391
+ "--sign" ,
392
+ "--force" ,
393
+ tag ,
394
+ f"{ tag } ^{{}}" ,
395
+ ])
396
+
397
+
398
+ def push_tag (tag : str , remote : str ) -> None :
399
+ """Push a tag to a remote."""
400
+ subprocess .check_call ( # nosec
401
+ [
402
+ "git" ,
403
+ "push" ,
404
+ "--quiet" ,
405
+ "--force" ,
406
+ remote ,
407
+ tag ,
408
+ ])
409
+
410
+
377
411
def checkout (branch : str ) -> None :
378
412
"""Checkout a branch."""
379
- subprocess .run ( # nosec
413
+ subprocess .check_call ( # nosec
380
414
[
381
415
"git" ,
382
416
"checkout" ,
383
417
"--quiet" ,
384
418
branch ,
385
- ],
386
- check = True ,
387
- )
419
+ ])
388
420
389
421
390
422
def revert (* files : str ) -> None :
391
423
"""Checkout files."""
392
424
branch = current_branch ()
393
- subprocess .run ( # nosec
425
+ subprocess .check_call ( # nosec
394
426
[
395
427
"git" ,
396
428
"checkout" ,
397
429
"--quiet" ,
398
430
branch ,
399
431
"--" ,
400
432
* files ,
401
- ],
402
- check = True ,
403
- )
433
+ ])
404
434
405
435
406
436
def add (* files : str ) -> None :
407
437
"""Add files to the index."""
408
- subprocess .run ( # nosec
438
+ subprocess .check_call ( # nosec
409
439
[
410
440
"git" ,
411
441
"add" ,
412
442
* files ,
413
- ],
414
- check = True ,
415
- )
443
+ ])
416
444
417
445
418
446
def reset (branch : str ) -> None :
419
447
"""Reset a branch to a specific commit."""
420
- subprocess .run ( # nosec
448
+ subprocess .check_call ( # nosec
421
449
[
422
450
"git" ,
423
451
"reset" ,
424
452
"--quiet" ,
425
453
"--hard" ,
426
454
branch ,
427
- ],
428
- check = True ,
429
- )
455
+ ])
430
456
431
457
432
458
def rebase (onto : str , commits : int = 0 ) -> bool :
@@ -438,28 +464,24 @@ def rebase(onto: str, commits: int = 0) -> bool:
438
464
"""
439
465
old_sha = branch_sha ("HEAD" )
440
466
if not commits :
441
- subprocess .run ( # nosec
467
+ subprocess .check_call ( # nosec
442
468
[
443
469
"git" ,
444
470
"rebase" ,
445
471
"--quiet" ,
446
472
onto ,
447
- ],
448
- check = True ,
449
- )
473
+ ])
450
474
else :
451
475
branch = current_branch ()
452
- subprocess .run ( # nosec
476
+ subprocess .check_call ( # nosec
453
477
[
454
478
"git" ,
455
479
"rebase" ,
456
480
"--quiet" ,
457
481
"--onto" ,
458
482
onto ,
459
483
f"HEAD~{ commits } " ,
460
- ],
461
- check = True ,
462
- )
484
+ ])
463
485
new_sha = branch_sha ("HEAD" )
464
486
checkout (branch )
465
487
reset (new_sha )
@@ -468,23 +490,21 @@ def rebase(onto: str, commits: int = 0) -> bool:
468
490
469
491
def create_branch (branch : str , base : str ) -> None :
470
492
"""Create a branch from a base branch."""
471
- subprocess .run ( # nosec
493
+ subprocess .check_call ( # nosec
472
494
[
473
495
"git" ,
474
496
"checkout" ,
475
497
"--quiet" ,
476
498
"-b" ,
477
499
branch ,
478
500
base ,
479
- ],
480
- check = True ,
481
- )
501
+ ])
482
502
483
503
484
504
def push (remote : str , branch : str , force : bool = False ) -> None :
485
505
"""Push the current branch to a remote."""
486
506
force_flag = ["--force" ] if force else []
487
- subprocess .run ( # nosec
507
+ subprocess .check_call ( # nosec
488
508
[
489
509
"git" ,
490
510
"push" ,
@@ -493,9 +513,7 @@ def push(remote: str, branch: str, force: bool = False) -> None:
493
513
"--set-upstream" ,
494
514
remote ,
495
515
branch ,
496
- ],
497
- check = True ,
498
- )
516
+ ])
499
517
500
518
501
519
def list_changed_files () -> list [str ]:
@@ -553,7 +571,7 @@ def commit(title: str, body: str) -> None:
553
571
"""
554
572
amend = ["--amend" ] if last_commit_message (
555
573
current_branch ()) == title else []
556
- subprocess .run ( # nosec
574
+ subprocess .check_call ( # nosec
557
575
[
558
576
"git" ,
559
577
"commit" ,
@@ -563,9 +581,7 @@ def commit(title: str, body: str) -> None:
563
581
title ,
564
582
"--message" ,
565
583
body ,
566
- ],
567
- check = True ,
568
- )
584
+ ])
569
585
570
586
571
587
def files_changed (commit : str ) -> list [str ]:
0 commit comments