Skip to content

Commit 4f5653a

Browse files
authored
Merge pull request libgit2#6060 from ccstolley/ccs_merge_bugfix
merge: Check file mode when resolving renames
2 parents 3f36e79 + 516f751 commit 4f5653a

File tree

10 files changed

+65
-2
lines changed

10 files changed

+65
-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 &&
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = true
5+
logallrefupdates = true
209 Bytes
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
P pack-4363774fb90141e8aa7a326ace0566366114e869.pack
2+
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# pack-refs with: peeled fully-peeled sorted
2+
ecef6a85173b6f446873a13f7b5a7b54a85cd912 refs/heads/master
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ecef6a85173b6f446873a13f7b5a7b54a85cd912

tests/revert/rename.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "clar.h"
2+
#include "clar_libgit2.h"
3+
4+
#include "git2/revert.h"
5+
#include "../merge/merge_helpers.h"
6+
7+
#define TEST_REPO_PATH "revert-rename.git"
8+
9+
static git_repository *repo;
10+
11+
/* Fixture setup and teardown */
12+
void test_revert_rename__initialize(void)
13+
{
14+
repo = cl_git_sandbox_init(TEST_REPO_PATH);
15+
}
16+
17+
void test_revert_rename__cleanup(void)
18+
{
19+
cl_git_sandbox_cleanup();
20+
}
21+
22+
/* Attempt a revert when there is a file rename AND change of file mode,
23+
* but the file contents remain the same. Check that the file mode doesn't
24+
* change following the revert.
25+
*/
26+
void test_revert_rename__automerge(void)
27+
{
28+
git_commit *head_commit, *revert_commit;
29+
git_oid revert_oid;
30+
git_index *index;
31+
git_reference *head_ref;
32+
33+
struct merge_index_entry merge_index_entries[] = {
34+
{ 0100644, "f0f64c618e1646d2948a456ed7c4bcfad5536d68", 0, "goodmode" }};
35+
36+
cl_git_pass(git_repository_head(&head_ref, repo));
37+
cl_git_pass(git_reference_peel((git_object **)&head_commit, head_ref, GIT_OBJECT_COMMIT));
38+
39+
cl_git_pass(git_oid_fromstr(&revert_oid, "7b4d7c3789b3581973c04087cb774c3c3576de2f"));
40+
cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_oid));
41+
42+
cl_git_pass(git_revert_commit(&index, repo, revert_commit, head_commit, 0, NULL));
43+
cl_assert(merge_test_index(index, merge_index_entries, 1));
44+
45+
git_commit_free(revert_commit);
46+
git_commit_free(head_commit);
47+
git_index_free(index);
48+
git_reference_free(head_ref);
49+
}

0 commit comments

Comments
 (0)