emdash icon indicating copy to clipboard operation
emdash copied to clipboard

feat(tasks): add delete behavior setting

Open janburzinski opened this issue 5 months ago • 2 comments

Description

  • adds a setting for "deleting branch / delete worktree" or if you want to be asked every time

Screenshot/Recording (if applicable)

https://streamable.com/rzfsq6

Checklist
  • [X] I kept this PR small and focused
  • [X] I ran a self-review before opening this PR
  • [X] I ran the relevant local checks or explained why not
  • [X] I updated docs when behavior or setup changed
  • [X] I added or updated tests when behavior changed, or explained why not
  • [X] I only added comments where the logic is not obvious
  • [X] I used Conventional Commits for commit messages and, when possible, the PR title

janburzinski avatar Jun 16 '26 12:06 janburzinski

Greptile Summary

This PR introduces a "Task delete behavior" setting that lets users choose between always deleting the worktree and branch automatically or being prompted each time, and also fixes a git (unknown) HEAD branch detection bug in both the legacy and new GitRepository implementations.

  • New setting: deleteBehavior (ask | delete-worktree-and-branch) is added to the task settings schema with a default of 'ask', wired through the settings registry, UI row, and useTaskSettings hook.
  • Modal updates: DeleteTaskModal hides checkboxes in always-delete mode and shows a descriptive notice; the deleteBranch local state default was changed from false to true, which affects the pre-checked state of the branch checkbox in ask mode.
  • Git bugfix: Both GitService and GitRepository now skip the (unknown) sentinel that git remote show emits when the HEAD branch cannot be determined.

Confidence Score: 4/5

Safe to merge with one UX regression worth addressing: the branch checkbox in ask mode is now pre-checked, silently changing the opt-in/opt-out direction for branch deletion.

The setting infrastructure, schema, and always-delete path are implemented correctly. The main concern is in delete-task-modal.tsx: deleteBranch state was changed from false to true, so users opening the modal in ask mode now see the branch checkbox pre-checked and must actively uncheck it to preserve their branch — the opposite of the previous behavior.

apps/emdash-desktop/src/renderer/features/tasks/delete-task-modal.tsx — the branch checkbox default and the scope notice rendering before preflight loads.

Important Files Changed

Filename Overview
apps/emdash-desktop/src/renderer/features/tasks/delete-task-modal.tsx Adds ask/always-delete branching logic; deleteBranch now defaults to true, making the branch checkbox pre-checked in ask mode — a behavior regression from the pre-PR default of unchecked.
apps/emdash-desktop/src/main/core/tasks/operations/deleteTask.ts Default for deleteBranch changed from false to true; all current call sites pass explicit options so the default is currently unused, but the change narrows the safety margin.
apps/emdash-desktop/src/main/core/settings/schema.ts Adds taskDeleteBehaviorSchema enum and deleteBehavior field to the task settings schema; clean addition.
apps/emdash-desktop/src/main/core/settings/settings-registry.ts Defaults deleteBehavior to 'ask', preserving safe behavior for users who haven't set a preference.
apps/emdash-desktop/src/renderer/features/settings/components/TaskSettingsRows.tsx Adds TaskDeleteBehaviorRow with a Select control and reset button; straightforward and consistent with other rows.
apps/emdash-desktop/src/renderer/features/tasks/hooks/useTaskSettings.ts Adds deleteBehavior to the settings model with update/reset helpers; correctly falls back to 'ask' when the field is absent.
apps/emdash-desktop/src/shared/core/app-settings.ts Exports TaskDeleteBehavior type derived from the new schema; clean addition.
apps/emdash-desktop/src/renderer/features/settings/components/SettingsPage.tsx Adds TaskDeleteBehaviorRow to the General Settings page between existing rows; no issues.
packages/core/src/git/git-repository.ts Bugfix: skips (unknown) when git cannot determine the HEAD branch name, preventing a stale sentinel value from being used as a real branch name.
apps/emdash-desktop/src/main/core/git/legacy/git-service.ts Same (unknown) guard applied to the legacy GitService implementation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User clicks Delete task] --> B[DeleteTaskModal opens]
    B --> C{taskSettings.loading?}
    C -- yes --> D[Show Loading... button disabled]
    C -- no --> E{deleteBehavior?}
    E -- ask --> F[Show worktree checkbox checked by default / Show branch checkbox checked by default]
    E -- delete-worktree-and-branch --> G[Hide checkboxes / Show scope notice / Show dirty warning if any]
    F --> H{User confirms}
    G --> I{User confirms}
    H --> J[onSuccess deleteWorktree=checkbox deleteBranch=checkbox]
    I --> K[onSuccess deleteWorktree=true deleteBranch=true]
    J --> L[deleteTask backend]
    K --> L
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[User clicks Delete task] --> B[DeleteTaskModal opens]
    B --> C{taskSettings.loading?}
    C -- yes --> D[Show Loading... button disabled]
    C -- no --> E{deleteBehavior?}
    E -- ask --> F[Show worktree checkbox checked by default / Show branch checkbox checked by default]
    E -- delete-worktree-and-branch --> G[Hide checkboxes / Show scope notice / Show dirty warning if any]
    F --> H{User confirms}
    G --> I{User confirms}
    H --> J[onSuccess deleteWorktree=checkbox deleteBranch=checkbox]
    I --> K[onSuccess deleteWorktree=true deleteBranch=true]
    J --> L[deleteTask backend]
    K --> L

Reviews (3): Last reviewed commit: "fix(settings): render delete behavior la..." | Re-trigger Greptile

greptile-apps avatar Jun 16 '26 12:06 greptile-apps

@greptileai

janburzinski avatar Jun 16 '26 12:06 janburzinski

image

janburzinski avatar Jun 23 '26 14:06 janburzinski

@greptileai

janburzinski avatar Jun 23 '26 15:06 janburzinski