Skip to content

Commit 479a38b

Browse files
author
Colin Stolley
committed
merge: Check file mode when resolving renames.
When determining if ours or theirs changed, we check the oids but not their respective file modes. This can lead to merges introducing incorrect file mode changes (eg., in a revert). A simple linear example might be: commit A - introduces file `foo` with chmod 0755 commit B - updates some unrelated file commit C - renames `foo` to `bar` and chmod 0644 If B is reverted, `bar` will unexpectedly acquire mode 0755.
1 parent 7d195b9 commit 479a38b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/merge.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,11 @@ static int merge_conflict_resolve_one_renamed(
816816
conflict->type == GIT_MERGE_DIFF_RENAMED_ADDED)
817817
return 0;
818818

819-
ours_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->our_entry.id) != 0);
820-
theirs_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->their_entry.id) != 0);
819+
ours_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->our_entry.id) != 0) ||
820+
(conflict->ancestor_entry.mode != conflict->our_entry.mode);
821+
822+
theirs_changed = (git_oid__cmp(&conflict->ancestor_entry.id, &conflict->their_entry.id) != 0) ||
823+
(conflict->ancestor_entry.mode != conflict->their_entry.mode);
821824

822825
/* if both are modified (and not to a common target) require a merge */
823826
if (ours_changed && theirs_changed &&

0 commit comments

Comments
 (0)