|
|
@@ -1,6 +1,23 @@
|
|
|
-#!/usr/bin/env bash
|
|
|
+#!/usr/bin/env python3
|
|
|
|
|
|
-set -euo pipefail
|
|
|
+import pathlib
|
|
|
+import subprocess
|
|
|
+import sys
|
|
|
|
|
|
-git branch -d $1
|
|
|
-git push origin :$1
|
|
|
+def main() -> None:
|
|
|
+ branches = sys.argv[1:]
|
|
|
+ if has_branchless():
|
|
|
+ run(['git', 'hide'] + ['draft()::' + branch for branch in branches])
|
|
|
+ else:
|
|
|
+ run(['git', 'branch', '-d'] + branches)
|
|
|
+ run(['git', 'push', 'origin'] + [':' + branch for branch in branches])
|
|
|
+
|
|
|
+def has_branchless() -> bool:
|
|
|
+ repo_root = run(['git', 'rev-parse', '--show-toplevel'], capture_output=True, text=True).stdout.rstrip('\n')
|
|
|
+ return pathlib.Path(repo_root, '.git/branchless/config').is_file()
|
|
|
+
|
|
|
+def run(cmd, capture_output=False, text=None):
|
|
|
+ return subprocess.run(cmd, capture_output=capture_output, check=True, text=text)
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|