Browse Source

git-branchd: support branchless

raylu 6 months ago
parent
commit
ab984ddd80
2 changed files with 22 additions and 5 deletions
  1. 21 4
      git-branchd
  2. 1 1
      git-branchp

+ 21 - 4
git-branchd

@@ -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()

+ 1 - 1
git-branchp

@@ -20,7 +20,7 @@ def main():
 
 	if delete and len(to_delete) > 0:
 		if has_branchless():
-			run([b'git', b'hide']  + [b'draft()::' + branch for branch in to_delete])
+			run([b'git', b'hide'] + [b'draft()::' + branch for branch in to_delete])
 		else:
 			run([b'git' b'branch', b'-D'] + to_delete)