"""Move the clone this tool ships in to the setup's newest release. usage: self-update Run it by its path in a clone of a release, as in /bin/self-update. It fetches origin's tags and checks out the newest v* tag, detached, so the clone holds only what a release holds. Development happens in another clone, such as ~/code/claude-config. It prints the clone and the version it moved from and to, then CHANGELOG.md's section for each version since, so you can do what each asks, such as a new step under Install. It refuses, exit 1, and leaves the clone as it was where a file the clone tracks has an uncommitted change the newest tag doesn't hold. Merge the change through the development clone and cut a release first. It also refuses where the newest tag doesn't hold the clone's commit, since the move would drop work no release holds. Untracked files stay as they are. """ import sys from failure import Failure from self_update.move import moved_to_newest from loop_state.paths import RELEASE_ROOT def main(argv: list[str], clone: str = str(RELEASE_ROOT)) -> int: """Move clone, which is the clone this tool ships in unless a test names another.""" if argv[:1] in (["-h"], ["--help"]): print(__doc__.strip()) return 0 if argv: print("self-update: usage: self-update", file=sys.stderr) return 1 moved = moved_to_newest(clone) if isinstance(moved, Failure): print(f"self-update: {moved.reason}", file=sys.stderr) return 1 print(moved) return 0