Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Stash workdir correctly when added in the index, modified in the workdir #3250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 24, 2015

Conversation

ethomson
Copy link
Member

We do not presently stash files correctly when a file is added in the index and then modified in the working directory. We are examining only the working directory with regard to the HEAD, and without examining the index as well (with that file staged) we treat that file as untracked and thus do not include it in the workdir tree.

Correct that by using a diff that includes the index similar to git_diff_tree_to_workdir_with_index but with different special cases. (git_diff_tree_to_workdir_with_index is aimed at producing something like git diff and so collapses some cases - we differ in that we want to ensure that we still pay attention to the workdir side when the index side is deleted.)

Edward Thomson added 4 commits June 23, 2015 16:48
Drop `git_diff__merge_like_cgit_reversed`, since it's a copy and
paste mess of slightly incompatible changes.
Ensure that when a file is added in the index and subsequently
modified in the working directory, the stashed working directory
tree contains the actual working directory contents.
When stashing the workdir tree, examine the index as well.  Using
a mechanism similar to `git_diff_tree_to_workdir_with_index`
allows us to determine that a file was added in the index and
subsequently modified in the working directory.  Without examining
the index, we would erroneously believe that this file was
untracked and fail to include it in the working directory tree.

Use a slightly modified `git_diff_tree_to_workdir_with_index` in
order to avoid some of the behavior custom to `git diff`.  In
particular, be sure to include the working directory side of a
file when it was deleted in the index.
const git_diff_delta *left = reversed ? f : o;
const git_diff_delta *right = reversed ? o : f;

delta = cb(left, right, &onto_pool);
Copy link
Contributor

Choose a reason for hiding this comment

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

So when I was working on this code, I wondered myself why diff_delta__merge_like_cgit_reversed() even existed vs just swapping the parameters to diff_delta__merge_like_cgit().

If you look at the implementation of diff_delta__merge_like_cgit_reversed(), it's actually not exactly the "reverse" of diff_delta__merge_like_cgit IIRC. Are you sure this is safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. It looks like there are a handful of changes to each since they were written. I tried to make sure that the unique changes to each were reflected in the new function. Was there something in particular that you're concerned about?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing in particular as I don't remember right now the past edge cases I had to deal when using this merge API. I do remember I spent a lot of time dealing with its peculiarities though. Anyway, looks like you have this covered already!

carlosmn added a commit that referenced this pull request Jun 24, 2015
Stash workdir correctly when added in the index, modified in the workdir
@carlosmn carlosmn merged commit c2f274c into libgit2:master Jun 24, 2015
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.

3 participants