Skip to content

fix(update): refuse to update over dirty tree; --force auto-stashes (closes #247) - #250

Merged
joelteply merged 1 commit into
canaryfrom
fix/canary-update-dirty-tree-recovery
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/canary-update-dirty-tree-recovery

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Detect local mods before pull. Without --force: helpful recovery hint, then die. With --force: auto-stash + continue.

…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]>
Copilot AI review requested due to automatic review settings April 28, 2026 22:57
@joelteply
joelteply merged commit 79583ae into canary Apr 28, 2026
1 check passed
@joelteply
joelteply deleted the fix/canary-update-dirty-tree-recovery branch April 28, 2026 22:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/-f help text for airc 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.

Comment on lines +77 to +80
local force=0
for _arg in "$@"; do
case "$_arg" in --force|-f) force=1 ;; esac
done

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--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.

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +81
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

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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

Copilot uses AI. Check for mistakes.
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

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
git -C "$dir" status --short 2>&1 | head -10 >&2
git -C "$dir" status --short 2>&1 | head -10 >&2 || true

Copilot uses AI. Check for mistakes.
Comment on lines +89 to +92
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

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants