文件
dayu-color/tools/checkpoint.py
T

12 行
1.1 KiB
Python

#!/usr/bin/env python3
"""Review selected paths before invoking. Never stages unrelated paths."""
import pathlib,os,hashlib,json,subprocess,shutil,sys
if len(sys.argv) < 3 or sys.argv[1] in ('--help', '-h'):
print('Usage: checkpoint.py MESSAGE PATH [PATH ...]');sys.exit(0 if len(sys.argv)>1 and sys.argv[1] in ('--help','-h') else 2)
root=pathlib.Path(__file__).resolve().parent.parent;remote='https://dayu.media/git/dayu/dayu-color.git';lock=pathlib.Path('/Users/mac/.codex/git-backup-locks')/(hashlib.sha256(remote.encode()).hexdigest()+'.lock')
lock.parent.mkdir(parents=True,exist_ok=True);lock.mkdir();(lock/'owner.json').write_text(json.dumps(dict(PID=os.getpid(),cwd=str(root),remote=remote)))
def run(*a):return subprocess.check_output(a,cwd=root,text=True).strip()
try:
run('git','add','-A','--',*sys.argv[2:]);print(run('git','diff','--cached','--stat'));print(run('git','commit','-m',sys.argv[1]));print(run('git','push','origin','HEAD'));sha=run('git','rev-parse','HEAD');assert run('git','ls-remote','origin','refs/heads/main').split()[0]==sha;print('REMOTE_VERIFIED '+sha)
finally:shutil.rmtree(lock)