git: a creation gate that never writes history, a git tab with Paperclip's worktree scan, and a warning line in every pane

This commit is contained in:
Sam
2026-11-12 20:38:44 +11:00
parent f7b77f370f
commit c419de5b48
18 changed files with 2223 additions and 82 deletions

View File

@@ -67,3 +67,56 @@ def make_repo(folder, quiet=False):
return False, "git commit failed: %s" % detail[:200]
say(" made a repository on branch %s, one commit" % branch(folder))
return True, ""
STARTER = """# Paperclip puts each task's worktree inside this folder, at .paperclip/.
# It is a checkout of this repository, so it must never be committed.
.paperclip/
# Add your own patterns below, one per line. For example:
# evidence/
# .env
# *secret*
"""
def ensure_ignore(folder):
"""Make sure .gitignore exists and that it excludes .paperclip/.
Returns (changed, note). The .paperclip entry is not a preference: without
it the first commit takes the worktrees with it.
"""
path = os.path.join(folder, ".gitignore")
if not os.path.exists(path):
with open(path, "w") as fh:
fh.write(STARTER)
return True, "wrote .gitignore, ignoring .paperclip/"
with open(path) as fh:
text = fh.read()
for line in text.splitlines():
line = line.strip().strip("/")
if line == ".paperclip" or line.startswith(".paperclip/"):
return False, ".gitignore already ignores .paperclip/"
add = "" if text.endswith("\n") or not text else "\n"
add += "\n# Paperclip's task worktrees; a commit must never take them.\n.paperclip/\n"
with open(path, "a") as fh:
fh.write(add)
return True, "added .paperclip/ to the existing .gitignore"
def stage_all(folder):
r = git(folder, "add", "-A")
return r.returncode == 0
def commit_all(folder, message="Initial commit, before any Paperclip task"):
"""Commit what is staged. Returns (ok, message)."""
r = git(folder, "-c", "user.name=Paperclip Harness",
"-c", "user.email=harness@localhost",
"commit", "-q", "-m", message)
if r.returncode != 0:
detail = (r.stderr or r.stdout).strip()
if "nothing to commit" in detail:
return False, "nothing to commit: the folder has no files git will take"
return False, "git commit failed: %s" % detail[:200]
return True, ""