Skip to content

Conversation

@Byron
Copy link
Collaborator

@Byron Byron commented Mar 25, 2025

Add V3 facilities for discarding changes in the worktree or index, this time it's about hunks specifically.

Follow-up of #7752.

Tasks

  • reset changed hunks in a file
    • assure test for executable bits
    • test for a dropped hunk
    • should the index be updated after all? - No
    • figure out what's wrong with the hunk application - it already does the wrong thing 'in the middle', maybe it never worked 100% correctly, or maybe there are assumptions an additive approach?
  • use latest version of gix - nothing essential

Notes for the reviewer

  • I find it difficult to imagine how meaningful discarding parts of hunks in whole-file deletions and additions can be so I chose to disallow it. The UI can still offer discarding the single whole hunk that a deletion or addition of a file would come with, but internally it, as always, would discard the file instead. Discarding of lines or selections would have to be disallowed on the UI level though, as this is currently only available for modified (or renamed + modified) files.

For the next PRs

  • reset individual lines (but as free selections of sub-hunks)
    • How does this work with context lines? In theory, they will mess everything up so it's probably something to avoid. After all, they will combine multiple hunks into one and the UI really would have to provide hunks without them.
  • See what happens if one tries to commit these special cases (i.e. the 'pretend there is no index' changes)
    • implement remaining ignored cases
  • gitoxide informs about diff-filter changes and this information is passed to the frontend
    • differentiate binary-to-text , otherwise it applies worktree conversions (which is fine). We ignore external diff programs anyway.

Shortcomings

  • Index-handling is low-level and I think there needs to be something like a tree-editor, but for indices. Maybe it's a mix of using the pretty-neat tree-editor, and a way to transfer index information from one index to another, similar to 'apply', to avoid loosing information.

Out of Scope

  • snapshot integration - should be left to @krlvi to warm up with the new code.

Research

  • V2 implementation
    • spread across unapply_lines, unapply_ownership and reset_files

@vercel vercel bot temporarily deployed to Preview – gitbutler-components March 25, 2025 02:06 Inactive
@vercel
Copy link

vercel bot commented Mar 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gitbutler-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2025 7:22am

@vercel
Copy link

vercel bot commented Mar 25, 2025

@Byron is attempting to deploy a commit to the GitButler Team on Vercel.

A member of the Team first needs to authorize it.

@Byron Byron marked this pull request as ready for review March 25, 2025 07:27
@Byron Byron merged commit da7e19e into gitbutlerapp:master Mar 25, 2025
18 of 19 checks passed
@Byron Byron deleted the discard branch March 25, 2025 07:29
@Byron Byron mentioned this pull request Mar 25, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant