Answer security round 1: 0 🔴, 0 🟡 (0 misread); keep a file name with a space whole in self-update, sort its imports and name its path as <clone>
This commit is contained in:
+14
-8
@@ -18,14 +18,15 @@ def moved_to_newest(clone: str) -> str | Failure:
|
||||
# Re-reads each file through the clean filter, so a model pick alone leaves settings.json unchanged.
|
||||
if isinstance(refreshed := git("update-index", "-q", "--refresh", cwd=clone), Failure):
|
||||
return refreshed
|
||||
changed = git("diff", "--name-only", "HEAD", cwd=clone)
|
||||
if isinstance(changed, Failure):
|
||||
return changed
|
||||
unreleased = git("diff", "--name-only", tag, "--", *changed.split(), cwd=clone) if changed.split() else ""
|
||||
listed = git("diff", "--name-only", "-z", "HEAD", cwd=clone)
|
||||
if isinstance(listed, Failure):
|
||||
return listed
|
||||
changed = names(listed)
|
||||
unreleased = git("diff", "--name-only", "-z", tag, "--", *changed, cwd=clone) if changed else ""
|
||||
if isinstance(unreleased, Failure):
|
||||
return unreleased
|
||||
if unreleased.split():
|
||||
return Failure(f"{clone} has uncommitted changes that {tag} doesn't hold, to {', '.join(unreleased.split())}: merge them through the development clone and cut a release first")
|
||||
if names(unreleased):
|
||||
return Failure(f"{clone} has uncommitted changes that {tag} doesn't hold, to {', '.join(names(unreleased))}: merge them through the development clone and cut a release first")
|
||||
old = git("describe", "--tags", "--abbrev=0", "--match", "v*", "HEAD", cwd=clone)
|
||||
old_tag = None if isinstance(old, Failure) else old.strip()
|
||||
at_tag = git("describe", "--tags", "--exact-match", "--match", "v*", "HEAD", cwd=clone)
|
||||
@@ -36,10 +37,10 @@ def moved_to_newest(clone: str) -> str | Failure:
|
||||
settings_changed = isinstance(git("diff", "--quiet", "HEAD", tag, "--", "settings.json", cwd=clone), Failure)
|
||||
# The tag holds each uncommitted change, so undoing them doesn't lose anything, and lets the move below take the tag's copy.
|
||||
# A settings.json the clean filter shows unchanged may still differ on disk, by a model pick or Claude Code's key order, which checkout refuses to overwrite; the pick is asked for again below.
|
||||
tracked = git("ls-files", "--", "settings.json", cwd=clone)
|
||||
tracked = git("ls-files", "-z", "--", "settings.json", cwd=clone)
|
||||
if isinstance(tracked, Failure):
|
||||
return tracked
|
||||
set_aside = sorted({*changed.split(), *tracked.split()} if settings_changed else set(changed.split()))
|
||||
set_aside = sorted({*changed, *names(tracked)} if settings_changed else set(changed))
|
||||
if set_aside:
|
||||
restored = git("checkout", "--quiet", "HEAD", "--", *set_aside, cwd=clone)
|
||||
if isinstance(restored, Failure):
|
||||
@@ -56,6 +57,11 @@ def moved_to_newest(clone: str) -> str | Failure:
|
||||
return "\n\n".join(lines)
|
||||
|
||||
|
||||
def names(listed: str) -> list[str]:
|
||||
"""The file names git listed with -z, which ends each with a NUL, so a name holding a space stays whole."""
|
||||
return [name for name in listed.split("\0") if name]
|
||||
|
||||
|
||||
def newer_sections(changelog: str, old_tag: str | None) -> list[str]:
|
||||
"""Each `## <version>` section of changelog newer than old_tag, newest first, as it reads."""
|
||||
since = tagged(old_tag)
|
||||
|
||||
Reference in New Issue
Block a user