Skip to content

Carry over untracked files during branch creation that results in a conflict - #8085

Merged
outofambit merged 26 commits into
developmentfrom
ku-stage-before-stashing
Sep 26, 2019
Merged

outofambit merged 26 commits into
developmentfrom
ku-stage-before-stashing

Conversation

@kuychaco

@kuychaco kuychaco commented Aug 9, 2019 •

Copy link
Copy Markdown
Contributor

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-untracked flag, 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 error untracked working tree files would be overwritten by checkout and 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-untracked flag 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:

  • Check with @niik to see if we're missing context on why we might not want to stage before stashing. My guess is that there's no reason, and that we use the --include-untracked flag when stashing because that's the only way to get untracked files into the stash, not because we want to keep the untracked status.
  • Remove flag for stashing untracked files
  • See if checkout branch needs similar staging logic (moved logic into git/stash so we're good)
  • [ ] Add tests?

Testing:

Release notes

Notes: [Fixed] Carry over untracked files during branch creation that results in a conflict

@kuychaco kuychaco self-assigned this Aug 9, 2019
@billygriffin
billygriffin requested a review from niik August 15, 2019 15:14
@kuychaco

Copy link
Copy Markdown
Contributor Author

@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

@niik

niik commented Aug 16, 2019

Copy link
Copy Markdown
Member

@kuychaco This was a thoroughly enjoyable writeup to read, really well done!

Check with @niik to see if we're missing context on why we might not want to stage before stashing. My guess is that there's no reason, and that we use the --include-untracked flag when stashing because that's the only way to get untracked files into the stash, not because we want to keep the untracked status.

The reason I pushed for us using --include-untracked instead of staging untracked files before stashing wasn't out of any known problems with the staging approach but rather a philosophical concern where we've previously been bitten by hard problems whenever we've strayed from the beaten path of Git. I'm always a bit anxious when we rely too much on our own understanding of Git's inner workings because they're almost always more complex than they initially appear.

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.

Comment thread app/src/lib/git/stash.ts Resolved
@kuychaco kuychaco added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 22, 2019
@kuychaco kuychaco removed their assignment Aug 22, 2019
stephanie86T
stephanie86T previously approved these changes Aug 23, 2019
Comment thread app/src/lib/git/stash.ts Resolved
Comment thread app/src/lib/stores/app-store.ts Resolved
Comment thread app/src/lib/git/stash.ts Resolved
Comment thread app/src/lib/git/stash.ts Resolved
@outofambit

Copy link
Copy Markdown
Contributor

@niik this is ready for another round of review! i tested and i think we're good to go!

mislav
mislav previously approved these changes Sep 26, 2019

@mislav mislav left a comment

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.

Looks great! Much simpler diff than before. Thanks for all the hard work on this ✨

Comment thread app/src/lib/stores/app-store.ts Resolved
niik
niik previously requested changes Sep 26, 2019

@niik niik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Comment thread app/src/lib/git/stash.ts Resolved
Comment thread app/src/lib/git/stash.ts Resolved
@niik niik self-assigned this Sep 26, 2019
@outofambit outofambit added the epic:stashing Tracking label for work related to the stashing flow label Sep 26, 2019

@kuychaco kuychaco left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Checked out the code and tested things locally. Everything looks good to me!

Captured @niik's suggestion in #8345 and added it to our issue tracker to get in before production

@outofambit

Copy link
Copy Markdown
Contributor

i also tested this with old stashes to make sure they behaved properly and found no issues.

@outofambit
outofambit dismissed niik’s stale review September 26, 2019 18:20

feedback addressed

@outofambit outofambit assigned outofambit and unassigned niik Sep 26, 2019
@outofambit

Copy link
Copy Markdown
Contributor

will merge this for beta when the build goes green

@outofambit
outofambit merged commit 72f5d85 into development Sep 26, 2019
@outofambit
outofambit deleted the ku-stage-before-stashing branch September 26, 2019 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

epic:stashing Tracking label for work related to the stashing flow ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swapping branches with changes Stash error with conflicted file upon new branch creation due to untracked files

5 participants