Skip to content

Conversation

derethil
Copy link

@derethil derethil commented Sep 2, 2025

Graceful Dirty Buffer Handling for Diff Operations

This PR adds the ability to gracefully handle unsaved changes when creating diffs. This has two behaviors to choose from:

  1. error (default): Throws an error when attempting to create a diff with unsaved changes. This is unchanged from the existing behavior.
  2. discard: Automatically discards unsaved buffer changes by reloading the buffer from disk before creating the diff.

The implementation includes:

  • A new diff_opts.on_unsaved_changes configuration option with validation
  • A new discard_buffer_changes() function that safely reloads buffers from disk
  • Integration with the existing diff setup workflow
  • Comprehensive test coverage for both error and discard behaviors

This makes it easier to work with diffs when files have unsaved changes, allowing you to choose between safety or convenience based on your workflow preferences.

@derethil derethil force-pushed the derethil/feat_add_discard_unsaved_changes_option branch from 6d17378 to bfb9a4d Compare September 2, 2025 05:36
Copy link
Member

@ThomasK33 ThomasK33 left a comment

Choose a reason for hiding this comment

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

Hey @derethil, thanks for this PR.

It's mostly looking good. The only thing missing is the update to lua/claudecode/types.lua.

The others are minor issues that you can choose to address if you want :)

@derethil
Copy link
Author

derethil commented Sep 3, 2025

Changes pushed up in the latest commits - great idea on the discard warning, thanks for that suggestion.

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