Repository navigation
Carry over untracked files during branch creation that results in a conflict - #8085
Conversation
Fixes #8084 Co-authored-by: evelyn masso <[email protected]>
|
@niik before investing more energy into this it’d be great to get a 30% review to validate that my UX reasoning and technical approach are sound… I got a 👍 from @billygriffin on the UX, and wanted to check in with you as well on any historical technical context that might be relevant 💭 @nerdneha pointed me to #7720 (comment) which seems to validate my proposed solution |
|
@kuychaco This was a thoroughly enjoyable writeup to read, really well done!
The reason I pushed for us using That said, if I remember the conversation correctly from a few months back the only reason that staging before stashing was proposed was that it was tricky to produce a list of which files were in a stash when the stash commit had three parents. I still think that trying to stick with the purpose-built support for untracked files and spending the extra time figuring out the correct way to produce a file list for a stash was the right call. The situation now, however, is different in that I don't see any good workaround that would let us stay on the beaten path. It's always a shame when we can't use the tooling that's so close to what we need but c'est la vie. 👍 To continue down this path and see if there are any caveats. |
This reverts commit d762711.
... which is only present if untracked files are in the stash
we still need this code for old desktop stashes This reverts commit 06ecb7c.
|
@niik this is ready for another round of review! i tested and i think we're good to go! |
mislav
left a comment
There was a problem hiding this comment.
Looks great! Much simpler diff than before. Thanks for all the hard work on this ✨
niik
left a comment
There was a problem hiding this comment.
restored in 3651a9f !
@outofambit I think that was supposed to be 6b9604e and I don't think that revert covers it all, we probably need to revert at least 6c432ea as well right?
Co-Authored-By: Markus Olsson <[email protected]>
This reverts commit 6c432ea.
|
i also tested this with old stashes to make sure they behaved properly and found no issues. |
|
will merge this for beta when the build goes green |
Overview
Carry over untracked files during branch creation that results in a conflict
Closes #8084
Closes #8200
Description
The Problem
When switching branches and carrying over changes that produce a conflict there is an edge case when newly created untracked files are involved in the conflict. This issue crops up when a new file has been added AND has not yet been staged, so it is "untracked" by Git.
Previously, Desktop stashed the untracked file (using the
--include-untrackedflag, which takes care to preserve the untracked nature of the file), created the new branch, and tried to apply the stashed changes on the new branch. But if the new branch already contained an untracked file with the same name, Git throws an erroruntracked working tree files would be overwritten by checkoutand doesn't allow the changes to be applied.Presumably, this is because Git wants to be conservative and avoid mucking with files that it hasn't been explicitly told to track via staging or committing. So when you tell it to restore an untracked file from a stash, it tries to restore the file exactly as it exists, and doesn't try to combine it with conflicting changes on the new branch.
Proposed Solution
But we know that the user's intention is to carry over the change they've made (whether staged/tracked, or unstaged/untracked), and expects to deal with any conflicts using the usual merge conflict resolution flow. And since the Desktop UI doesn't actually distinguish between newly created untracked and tracked (staged) files, we probably don't need to be too concerned with preserving the untracked status of the user's working directory files.
To better meet the user's expectations, we want to complete the checkout and present the user with a merge conflict to resolve for the newly created file. This PR does so by staging any untracked files prior to stashing them. Which means that Git has no problem popping the stash and generating merge conflicts since it's dealing with changes we told it to track. And we can drop the
--include-untrackedflag when stashing since we've just staged everything.Alternatives considered
@outofambit and I also noted a couple of other approaches, but both seemed needlessly complex compared to the solution outlined above. In any case, here's what we considered:
Alternative 1: manually generate the conflict using git merge plumbing commands to merge the stash entry with the working directory changes
Alternative 2: create a branch from the stash and merge that with the newly created branch
TODO:
--include-untrackedflag when stashing because that's the only way to get untracked files into the stash, not because we want to keep the untracked status.[ ] Add tests?Testing:
Release notes
Notes: [Fixed] Carry over untracked files during branch creation that results in a conflict