Skip to content

feat(code-review): add revert all local changes button#3352

Merged
MattPua merged 1 commit into
mainfrom
posthog-code/revert-all-local-changes
Jul 10, 2026
Merged

feat(code-review): add revert all local changes button#3352
MattPua merged 1 commit into
mainfrom
posthog-code/revert-all-local-changes

Conversation

@MattPua

@MattPua MattPua commented Jul 10, 2026

Copy link
Copy Markdown
Member

Problem

Reviewing local changes only lets you refresh the diff or discard files one at a time. No quick way to blow away all uncommitted changes at once.

Changes

CleanShot.2026-07-10.at.12.29.53.mp4
  • Added git.discardAllChanges tRPC mutation on workspace-server, reusing the existing CleanWorkingTreeSaga (stashes a backup before reset/clean)
  • Added useDiscardAllChanges hook with a confirm dialog before reverting
  • Added a "Revert all local changes" button next to Refresh in the review toolbar, shown only when there are local changes

How did you test this?

  • pnpm typecheck on @posthog/ui, @posthog/git, @posthog/workspace-server (ran via pre-commit hook)
  • qa-swarm review (paul-reviewer, xp-reviewer, security-audit) — no correctness or security findings; addressed the one convergent nit (confirm dialog now mentions untracked-file deletion and the backup stash)

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

Adds a button next to Refresh in the review toolbar to discard every
uncommitted change at once, reusing the existing CleanWorkingTreeSaga
(stashes a backup first) via a new git.discardAllChanges mutation.

Generated-By: PostHog Code
Task-Id: 9a3a79b8-890b-43e0-b567-938fc2cc46c4
@trunk-io

trunk-io Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit e522a98.

@MattPua MattPua marked this pull request as ready for review July 10, 2026 16:30
@MattPua MattPua added the Stamphog This will request an autostamp by stamphog on small changes label Jul 10, 2026

@github-actions github-actions Bot 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.

Additive feature wired correctly through all layers. The saga creates a git stash backup before discarding, the user sees a confirmation dialog, and the service method follows the same pattern as the existing discardFileChanges. No showstoppers.

@MattPua MattPua enabled auto-merge (squash) July 10, 2026 16:32
@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Security Review

The new discard-all mutation operates on a client-supplied directory path without ownership or workspace validation. This can let an API caller reset and clean a local Git repository path that should not be mutable through this workflow.

Reviews (1): Last reviewed commit: "feat(code-review): add revert all local ..." | Re-trigger Greptile

Comment on lines +489 to +490
.mutation(({ input }) =>
gitService().discardAllChanges(input.directoryPath),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security Client Path Drives Cleanup

The new mutation takes input.directoryPath from the client and sends it straight into the clean-working-tree saga. A caller that can reach this API can point it at any local Git repository the workspace-server process can access, which runs reset/restore/clean there without first checking that the path is a registered workspace owned by the caller.

Rule Used: When implementing new features, ensure that owners... (source)

Learned From
PostHog/posthog#31236

Comment on lines +29 to +31
const result = await discardAllChanges.mutateAsync({
directoryPath: repoPath,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Failed Revert Has No Feedback

If discardAllChanges.mutateAsync rejects after the user confirms, this async click handler lets the error escape without showing any failure message. The local diff can stay unchanged while the user gets no clear indication that the revert did not happen.

Rule Used: Always wrap asynchronous calls that may fail, such... (source)

Learned From
PostHog/posthog#32098

@MattPua MattPua merged commit 140d30e into main Jul 10, 2026
32 checks passed
@MattPua MattPua deleted the posthog-code/revert-all-local-changes branch July 10, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant