Skip to content

Conversation

ethomson
Copy link
Member

@ethomson ethomson commented Oct 6, 2017

When performing a forced checkout, treat files as modified when the workdir or the index is identical except for the mode. This ensures that force checkout will update the mode to the target.

Without this change, we examine the contents of the file on-disk and determine that it's identical to the tree we're checking out, and continue without making any changes. By including the filemode in the difference check, checkout will now make a file executable (or remove the executable bit) as appropriate to match the checkout target.

We apply this check for regular files only: in the case where one of the items was a file and the other item was not, then this would be a typechange (not a file mode change) and would be handled by other codepaths.

Edward Thomson and others added 3 commits October 6, 2017 23:53
When performing a forced checkout, treat files as modified when the
workdir or the index is identical except for the mode.  This ensures
that force checkout will update the mode to the target.  (Apply this
check for regular files only, if one of the items was a file and the
other was another type of item then this would be a typechange and
handled independently.)
On Windows, we do not support file mode changes, so do not test
for type changes between the disk and tree being checked out.

We could have false positives since the on-disk file can only have
an (effective) mode of 0100644 since NTFS does not support executable
files.  If the tree being checked out did have an executable file,
we would erroneously decide that the file on disk had been changed.
Test that we can successfully force checkout a target when the file
contents are identical, but the mode has changed.
@ethomson ethomson force-pushed the ethomson/checkout_typechange branch from 4a59973 to 19e8fab Compare October 7, 2017 11:35
@ethomson
Copy link
Member Author

ethomson commented Oct 7, 2017

I cherry-picked these from #3839. I think that there's more work to do there, but this is nice and isolated and we should include it.

/cc @cjhoward92

@pks-t pks-t merged commit 38e769c into master Oct 9, 2017
@pks-t
Copy link
Member

pks-t commented Oct 9, 2017

Looks good to me, thanks @ethomson. I've verified locally that the test actually catches the chmodded file with git_status_list_new.

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