#!/usr/bin/env python3 """Review selected paths before invoking. Never stages unrelated paths.""" import pathlib,os,hashlib,json,subprocess,shutil,sys 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)