25 lines
1.8 KiB
Python
25 lines
1.8 KiB
Python
from pathlib import Path
|
|
import hashlib,json,subprocess
|
|
packet=Path(__file__).resolve().parent;owner=Path('/home/worsch/net-kingdom');backup=packet/'publication-backup'
|
|
git=lambda *args:subprocess.check_output(['git','-C',str(owner),*args])
|
|
# Verify original staged/worktree brief bytes before changing its index entry.
|
|
if git('show',':.custodian-brief.md') != (backup/'brief.index').read_bytes():raise SystemExit('staged brief race')
|
|
if (owner/'.custodian-brief.md').read_bytes() != (backup/'brief.worktree').read_bytes():raise SystemExit('working brief race')
|
|
subprocess.run(['git','-C',str(owner),'restore','--staged','.custodian-brief.md'],check=True)
|
|
try:
|
|
result=subprocess.run(['statehub','fix-consistency','--repo','net-kingdom','--repo-path',str(owner),'--json'],capture_output=True,text=True,cwd=owner)
|
|
(packet/'normal-writeback.stdout.json').write_text(result.stdout)
|
|
(packet/'normal-writeback.stderr.txt').write_text(result.stderr)
|
|
(packet/'normal-writeback.exit.json').write_text(json.dumps({'exit_code':result.returncode})+'\n')
|
|
print('statehub exit:',result.returncode)
|
|
print(result.stdout[-6000:])
|
|
print(result.stderr[-1000:])
|
|
finally:
|
|
# Restore exact pre-existing stage blob, independently of any auto-brief commit.
|
|
record=(backup/'index-record.txt').read_text().split()
|
|
original_blob=record[1];mode=record[0]
|
|
subprocess.run(['git','-C',str(owner),'update-index','--cacheinfo',f'{mode},{original_blob},.custodian-brief.md'],check=True)
|
|
(owner/'.custodian-brief.md').write_bytes((backup/'brief.worktree').read_bytes())
|
|
if git('show',':.custodian-brief.md') != (backup/'brief.index').read_bytes():raise SystemExit('staged brief restoration failed')
|
|
if (owner/'.custodian-brief.md').read_bytes() != (backup/'brief.worktree').read_bytes():raise SystemExit('brief restoration failed')
|
|
print('Exact original staged and working brief bytes restored.')
|