diff --git a/template/justfile b/template/justfile index a81ca3e..353ffb0 100644 --- a/template/justfile +++ b/template/justfile @@ -58,6 +58,13 @@ wt-rm target: git worktree remove "$TARGET" + # Remove empty parent directories left after worktree removal + DIR="$(dirname "$TARGET")" + while [ "$DIR" != "." ] && [ -d "$DIR" ] && [ -z "$(ls -A "$DIR")" ]; do + rmdir "$DIR" + DIR="$(dirname "$DIR")" + done + if ! git branch -d "$TARGET" 2>/dev/null; then echo "Worktree removed but branch '$TARGET' has unmerged changes." echo " To delete it anyway: git branch -D $TARGET" @@ -79,6 +86,13 @@ wt-destroy target: git worktree remove "$TARGET" --force + # Remove empty parent directories left after worktree removal + DIR="$(dirname "$TARGET")" + while [ "$DIR" != "." ] && [ -d "$DIR" ] && [ -z "$(ls -A "$DIR")" ]; do + rmdir "$DIR" + DIR="$(dirname "$DIR")" + done + git branch -D "$TARGET" if git remote | grep -q . && git ls-remote --exit-code --heads origin "$TARGET" >/dev/null 2>&1; then