Repository navigation
fix(update): refuse to update over dirty tree; --force auto-stashes (closes #247) - #250
Conversation
…247) QA finding via #247: 'airc canary' on a dirty install dir bailed with a hostile install.sh failure and no recovery hint. Now detects local mods BEFORE branch switch / pull and either: - Without --force: print git status short, three copy-pasteable recovery commands, then die. Refuses to mutate without consent. - With --force / -f: auto-stash via 'git stash push -u -m ...' so the user can pop later if the mods mattered. Adds --force / -f to the --help intercept usage block. Verification: tabs 19/0; manual exercise via 'echo x >> README.md && airc update'. Closes #247 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR enhances airc update safety by detecting a dirty install-dir git working tree before switching channels and running install.sh, refusing to proceed unless the user explicitly opts in via --force (auto-stash).
Changes:
- Add
--force/-fhelp text forairc update. - Add pre-update “dirty tree” detection with two behaviors: refuse with recovery hints, or auto-stash and continue when forced.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local force=0 | ||
| for _arg in "$@"; do | ||
| case "$_arg" in --force|-f) force=1 ;; esac | ||
| done |
There was a problem hiding this comment.
--force will never be detected here: the earlier while [ $# -gt 0 ]; do ... shift ... done loop consumes all args, so $@ is empty by the time this for _arg in "$@" runs. Parse --force/-f inside the main arg-parsing loop (or save the original args before shifting) so the flag actually takes effect.
| for _arg in "$@"; do | ||
| case "$_arg" in --force|-f) force=1 ;; esac | ||
| done | ||
| if ! git -C "$dir" diff --quiet 2>/dev/null || ! git -C "$dir" diff --cached --quiet 2>/dev/null; then |
There was a problem hiding this comment.
Dirty-tree detection uses git diff (tracked changes only) and misses untracked files. That means a directory with only untracked files will still update without prompting/stashing, contradicting the --force “auto-stash local mods” behavior. Consider basing the check on git status --porcelain (or also checking git ls-files --others --exclude-standard).
| for _arg in "$@"; do | |
| case "$_arg" in --force|-f) force=1 ;; esac | |
| done | |
| if ! git -C "$dir" diff --quiet 2>/dev/null || ! git -C "$dir" diff --cached --quiet 2>/dev/null; then | |
| local git_status="" | |
| for _arg in "$@"; do | |
| case "$_arg" in --force|-f) force=1 ;; esac | |
| done | |
| git_status="$(git -C "$dir" status --porcelain 2>/dev/null)" | |
| if [ -n "$git_status" ]; then |
| git -C "$dir" stash push -u -m "airc-update-autostash-$(date +%s)" >/dev/null 2>&1 || die "Auto-stash failed in $dir." | ||
| else | ||
| echo " ⚠ Local mods in install dir ($dir):" >&2 | ||
| git -C "$dir" status --short 2>&1 | head -10 >&2 |
There was a problem hiding this comment.
Under set -euo pipefail, git ... status --short | head -10 can fail because head closes the pipe early, causing git status to exit non-zero on SIGPIPE; that would abort before printing the recovery hints. Add a || true to this pipeline or avoid SIGPIPE (e.g., capture output then print first 10 lines).
| git -C "$dir" status --short 2>&1 | head -10 >&2 | |
| git -C "$dir" status --short 2>&1 | head -10 >&2 || true |
| echo " Recover with one of:" >&2 | ||
| echo " airc update --force # auto-stash, pull, leave stash for you" >&2 | ||
| echo " git -C $dir stash && airc update # manual stash + retry" >&2 | ||
| echo " git -C $dir reset --hard origin/$channel # discard mods + retry update" >&2 |
There was a problem hiding this comment.
The recovery commands print git -C $dir ... without quoting $dir. If the install path contains spaces, the copy/paste instructions will fail. Quote $dir (and origin/$channel) in the suggested commands to make them reliably usable.
| echo " Recover with one of:" >&2 | |
| echo " airc update --force # auto-stash, pull, leave stash for you" >&2 | |
| echo " git -C $dir stash && airc update # manual stash + retry" >&2 | |
| echo " git -C $dir reset --hard origin/$channel # discard mods + retry update" >&2 | |
| local escaped_dir escaped_remote_ref | |
| printf -v escaped_dir '%q' "$dir" | |
| printf -v escaped_remote_ref '%q' "origin/$channel" | |
| echo " Recover with one of:" >&2 | |
| echo " airc update --force # auto-stash, pull, leave stash for you" >&2 | |
| echo " git -C $escaped_dir stash && airc update # manual stash + retry" >&2 | |
| echo " git -C $escaped_dir reset --hard $escaped_remote_ref # discard mods + retry update" >&2 |
Detect local mods before pull. Without --force: helpful recovery hint, then die. With --force: auto-stash + continue.