git-branchd 703 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env python3
  2. import pathlib
  3. import subprocess
  4. import sys
  5. def main() -> None:
  6. branches = sys.argv[1:]
  7. if has_branchless():
  8. run(['git', 'hide'] + ['draft()::' + branch for branch in branches])
  9. else:
  10. run(['git', 'branch', '-d'] + branches)
  11. run(['git', 'push', 'origin'] + [':' + branch for branch in branches])
  12. def has_branchless() -> bool:
  13. repo_root = run(['git', 'rev-parse', '--show-toplevel'], capture_output=True, text=True).stdout.rstrip('\n')
  14. return pathlib.Path(repo_root, '.git/branchless/config').is_file()
  15. def run(cmd, capture_output=False, text=None):
  16. return subprocess.run(cmd, capture_output=capture_output, check=True, text=text)
  17. if __name__ == '__main__':
  18. main()