From 65a7810de83b05afcc08544c3e01809f7f1582d4 Mon Sep 17 00:00:00 2001 From: Josua Schmid Date: Fri, 16 Oct 2026 17:31:35 +0200 Subject: [PATCH 1/2] Keep a plugin checkout's local work when removing it Co-Authored-By: Claude Opus 5.5 --- bin/omarchy-plugin-remove | 28 ++++++- manual/32-shell-plugins.md | 2 +- test/shell.d/plugin-remove-test.sh | 113 +++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 3 deletions(-) create mode 100755 test/shell.d/plugin-remove-test.sh diff --git a/bin/omarchy-plugin-remove b/bin/omarchy-plugin-remove index e7cc314aa8b3..faa653339d68 100755 --- a/bin/omarchy-plugin-remove +++ b/bin/omarchy-plugin-remove @@ -33,6 +33,25 @@ valid_plugin_id() { [[ $1 =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ && $1 != *..* ]] } +# True only for a git checkout that holds nothing upstream lacks: no uncommitted +# or untracked files, and no commit or stash of its own. `omarchy plugin update` +# merges FETCH_HEAD without moving the remote-tracking refs, so FETCH_HEAD +# counts as upstream too. Anything git cannot answer counts as local. +upstream_only_checkout() { + local dir="$1" + local upstream=(--remotes) + local changes + + [[ -d $dir/.git ]] || return 1 + changes=$(git -C "$dir" status --porcelain --untracked-files=normal) || return 1 + [[ -z $changes ]] || return 1 + if git -C "$dir" rev-parse -q --verify FETCH_HEAD >/dev/null; then + upstream+=(FETCH_HEAD) + fi + changes=$(git -C "$dir" rev-list -n 1 --all --not "${upstream[@]}") || return 1 + [[ -z $changes ]] +} + id="" while (( $# > 0 )); do @@ -84,9 +103,14 @@ if [[ -f $target/manifest.json ]]; then cloned_from=$(jq -r '.omarchy.clonedFrom // empty' "$target/manifest.json") fi +disposable=0 +if [[ ! -L $target ]] && upstream_only_checkout "$target"; then + disposable=1 +fi + if [[ -L $target ]]; then confirm "$(omarchy-i18n plugin.confirmUnlink "$id" "$(readlink "$target")")" || fail "aborted" -elif [[ -d $target/.git ]]; then +elif (( disposable )); then confirm "$(omarchy-i18n plugin.confirmDelete "$id")" || fail "aborted" else confirm "$(omarchy-i18n plugin.confirmRemove "$id")" || fail "aborted" @@ -99,7 +123,7 @@ fi if [[ -L $target ]]; then rm -f "$target" echo "Unlinked $id." -elif [[ -d $target/.git ]]; then +elif (( disposable )); then rm -rf "$target" echo "Removed $id." else diff --git a/manual/32-shell-plugins.md b/manual/32-shell-plugins.md index 108c764bb391..1840d2439a10 100644 --- a/manual/32-shell-plugins.md +++ b/manual/32-shell-plugins.md @@ -56,7 +56,7 @@ With no id it updates every git-managed plugin you have. It shows you the diff b omarchy plugin remove acme.weather ``` -Removal disables the plugin first, then deletes it if it's a git checkout (the repo is still upstream) or unlinks it if it's a symlink. A hand-made plugin folder with no git repo gets moved to a timestamped backup inside the plugins directory instead of being deleted outright. +Removal disables the plugin first, then deletes it if it's a git checkout holding nothing that isn't also upstream, or unlinks it if it's a symlink. A checkout with uncommitted or untracked files, unpushed commits, or stashes, and a hand-made plugin folder with no git repo, get moved to a timestamped backup inside the plugins directory instead of being deleted outright. ## Cloning a built-in to modify it diff --git a/test/shell.d/plugin-remove-test.sh b/test/shell.d/plugin-remove-test.sh new file mode 100755 index 000000000000..8b10b1b4fb49 --- /dev/null +++ b/test/shell.d/plugin-remove-test.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT + +stub_dir="$TMPDIR/stubs" +mkdir -p "$stub_dir" +cat >"$stub_dir/omarchy-shell" <<'STUB' +#!/bin/bash +exit 0 +STUB +chmod +x "$stub_dir/omarchy-shell" + +test_home="$TMPDIR/home" +plugins_dir="$test_home/.config/omarchy/plugins" + +run() { + HOME="$test_home" OMARCHY_PATH="$ROOT" PATH="$stub_dir:$ROOT/bin:$PATH" "$@" 2>&1 +} + +git_test() { + git -c user.name=Test -c user.email=test@example.com "$@" +} + +# Each plugin is added from an upstream repo of its own, as `omarchy plugin add` +# would clone it from a forge or a local checkout. +add_plugin() { + local id="$1" + local upstream="$TMPDIR/upstream/$id" + + mkdir -p "$upstream" + cat >"$upstream/manifest.json" <"$upstream/Widget.qml" + git -C "$upstream" init -q + git -C "$upstream" add . + git_test -C "$upstream" commit -qm "Initial" + + output=$(run omarchy-plugin-add "$upstream" --yes) || fail "plugin add installs $id" "$output" +} + +backup_of() { + find "$plugins_dir" -mindepth 1 -maxdepth 1 -name ".$1.bak.*" -print -quit +} + +remove_plugin() { + output=$(run omarchy-plugin-remove "$1" --yes) || fail "plugin remove removes $1" "$output" + [[ ! -e $plugins_dir/$1 ]] || fail "plugin remove leaves $1 installed" "$output" +} + +add_plugin acme.clean +remove_plugin acme.clean +[[ -z $(backup_of acme.clean) ]] || fail "plugin remove backs up a checkout with nothing local" +pass "plugin remove deletes a checkout whose commits are all upstream" + +# `omarchy plugin update` merges FETCH_HEAD without moving the remote-tracking +# refs, so the commits it brought in are upstream too. +add_plugin acme.updated +printf '// upstream\n' >>"$TMPDIR/upstream/acme.updated/Widget.qml" +git_test -C "$TMPDIR/upstream/acme.updated" commit -qam "Upstream change" +output=$(run omarchy-plugin-update acme.updated --yes) || fail "plugin update fast-forwards acme.updated" "$output" +remove_plugin acme.updated +[[ -z $(backup_of acme.updated) ]] || fail "plugin remove backs up a checkout that only holds updates from upstream" +pass "plugin remove deletes a checkout updated from upstream" + +add_plugin acme.edited +printf '// local edit\n' >>"$plugins_dir/acme.edited/Widget.qml" +remove_plugin acme.edited +backup=$(backup_of acme.edited) +[[ -n $backup ]] && grep -qF '// local edit' "$backup/Widget.qml" || + fail "plugin remove drops uncommitted changes" "$output" +pass "plugin remove backs up a checkout with uncommitted changes" + +add_plugin acme.untracked +printf 'import QtQuick\nItem {}\n' >"$plugins_dir/acme.untracked/Extra.qml" +remove_plugin acme.untracked +backup=$(backup_of acme.untracked) +[[ -n $backup && -f $backup/Extra.qml ]] || fail "plugin remove drops untracked files" "$output" +pass "plugin remove backs up a checkout with untracked files" + +add_plugin acme.committed +printf '// local commit\n' >>"$plugins_dir/acme.committed/Widget.qml" +git_test -C "$plugins_dir/acme.committed" commit -qam "Local change" +remove_plugin acme.committed +backup=$(backup_of acme.committed) +[[ -n $backup && $(git -C "$backup" log -1 --format=%s) == "Local change" ]] || + fail "plugin remove drops commits that were never pushed" "$output" +pass "plugin remove backs up a checkout with unpushed commits" + +add_plugin acme.stashed +printf '// stashed\n' >>"$plugins_dir/acme.stashed/Widget.qml" +git_test -C "$plugins_dir/acme.stashed" stash push -q +remove_plugin acme.stashed +backup=$(backup_of acme.stashed) +[[ -n $backup && -n $(git -C "$backup" stash list) ]] || fail "plugin remove drops stashed changes" "$output" +pass "plugin remove backs up a checkout with stashed changes" From 60945c7b10fc14627ff6537583dc3dc945064c70 Mon Sep 17 00:00:00 2001 From: Josua Schmid Date: Mon, 19 Oct 2026 07:39:56 +0200 Subject: [PATCH 2/2] Back up checkouts holding ignored files, since they are local work too Co-Authored-By: Claude Opus 5.5 --- bin/omarchy-plugin-remove | 11 ++++++----- manual/32-shell-plugins.md | 2 +- test/shell.d/plugin-remove-test.sh | 11 +++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bin/omarchy-plugin-remove b/bin/omarchy-plugin-remove index faa653339d68..ea125c87e8cd 100755 --- a/bin/omarchy-plugin-remove +++ b/bin/omarchy-plugin-remove @@ -33,17 +33,18 @@ valid_plugin_id() { [[ $1 =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ && $1 != *..* ]] } -# True only for a git checkout that holds nothing upstream lacks: no uncommitted -# or untracked files, and no commit or stash of its own. `omarchy plugin update` -# merges FETCH_HEAD without moving the remote-tracking refs, so FETCH_HEAD -# counts as upstream too. Anything git cannot answer counts as local. +# True only for a git checkout that holds nothing upstream lacks: no +# uncommitted, untracked or ignored files, and no commit or stash of its own. +# `omarchy plugin update` merges FETCH_HEAD without moving the remote-tracking +# refs, so FETCH_HEAD counts as upstream too. Anything git cannot answer counts +# as local. upstream_only_checkout() { local dir="$1" local upstream=(--remotes) local changes [[ -d $dir/.git ]] || return 1 - changes=$(git -C "$dir" status --porcelain --untracked-files=normal) || return 1 + changes=$(git -C "$dir" status --porcelain --untracked-files=normal --ignored) || return 1 [[ -z $changes ]] || return 1 if git -C "$dir" rev-parse -q --verify FETCH_HEAD >/dev/null; then upstream+=(FETCH_HEAD) diff --git a/manual/32-shell-plugins.md b/manual/32-shell-plugins.md index 1840d2439a10..be23276c9943 100644 --- a/manual/32-shell-plugins.md +++ b/manual/32-shell-plugins.md @@ -56,7 +56,7 @@ With no id it updates every git-managed plugin you have. It shows you the diff b omarchy plugin remove acme.weather ``` -Removal disables the plugin first, then deletes it if it's a git checkout holding nothing that isn't also upstream, or unlinks it if it's a symlink. A checkout with uncommitted or untracked files, unpushed commits, or stashes, and a hand-made plugin folder with no git repo, get moved to a timestamped backup inside the plugins directory instead of being deleted outright. +Removal disables the plugin first, then deletes it if it's a git checkout holding nothing that isn't also upstream, or unlinks it if it's a symlink. A checkout with uncommitted, untracked or ignored files, unpushed commits, or stashes, and a hand-made plugin folder with no git repo, get moved to a timestamped backup inside the plugins directory instead of being deleted outright. ## Cloning a built-in to modify it diff --git a/test/shell.d/plugin-remove-test.sh b/test/shell.d/plugin-remove-test.sh index 8b10b1b4fb49..e165c81538ee 100755 --- a/test/shell.d/plugin-remove-test.sh +++ b/test/shell.d/plugin-remove-test.sh @@ -95,6 +95,17 @@ backup=$(backup_of acme.untracked) [[ -n $backup && -f $backup/Extra.qml ]] || fail "plugin remove drops untracked files" "$output" pass "plugin remove backs up a checkout with untracked files" +add_plugin acme.ignored +printf 'secret.json\n' >"$TMPDIR/upstream/acme.ignored/.gitignore" +git -C "$TMPDIR/upstream/acme.ignored" add .gitignore +git_test -C "$TMPDIR/upstream/acme.ignored" commit -qm "Ignore local secrets" +output=$(run omarchy-plugin-update acme.ignored --yes) || fail "plugin update fast-forwards acme.ignored" "$output" +printf '{}\n' >"$plugins_dir/acme.ignored/secret.json" +remove_plugin acme.ignored +backup=$(backup_of acme.ignored) +[[ -n $backup && -f $backup/secret.json ]] || fail "plugin remove drops ignored files" "$output" +pass "plugin remove backs up a checkout with ignored files" + add_plugin acme.committed printf '// local commit\n' >>"$plugins_dir/acme.committed/Widget.qml" git_test -C "$plugins_dir/acme.committed" commit -qam "Local change"