Skip to content

Commit 06f3aa5

Browse files
authored
Merge pull request libgit2#4429 from novalis/delete-modify-submodule-merge
Do not attempt to check out submodule as blob when merging a submodule modify/deltete conflict
2 parents a086724 + 2a3e063 commit 06f3aa5

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

src/checkout.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,8 +2022,11 @@ static int checkout_write_entry(
20222022
(error = checkout_safe_for_update_only(data, fullpath->ptr, side->mode)) <= 0)
20232023
return error;
20242024

2025-
return checkout_write_content(data,
2026-
&side->id, fullpath->ptr, hint_path, side->mode, &st);
2025+
if (!S_ISGITLINK(side->mode))
2026+
return checkout_write_content(data,
2027+
&side->id, fullpath->ptr, hint_path, side->mode, &st);
2028+
2029+
return 0;
20272030
}
20282031

20292032
static int checkout_write_entries(

tests/merge/workdir/submodules.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ static git_repository *repo;
1212
#define SUBMODULE_MAIN_BRANCH "submodules"
1313
#define SUBMODULE_OTHER_BRANCH "submodules-branch"
1414
#define SUBMODULE_OTHER2_BRANCH "submodules-branch2"
15+
#define SUBMODULE_DELETE_BRANCH "delete-submodule"
1516

1617
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
1718

@@ -93,3 +94,38 @@ void test_merge_workdir_submodules__take_changed(void)
9394
git_reference_free(their_ref);
9495
git_reference_free(our_ref);
9596
}
97+
98+
99+
void test_merge_workdir_submodules__update_delete_conflict(void)
100+
{
101+
git_reference *our_ref, *their_ref;
102+
git_commit *our_commit;
103+
git_annotated_commit *their_head;
104+
git_index *index;
105+
106+
struct merge_index_entry merge_index_entries[] = {
107+
{ 0100644, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", 0, ".gitmodules" },
108+
{ 0100644, "5887a5e516c53bd58efb0f02ec6aa031b6fe9ad7", 0, "file1.txt" },
109+
{ 0100644, "4218670ab81cc219a9f94befb5c5dad90ec52648", 0, "file2.txt" },
110+
{ 0160000, "d3d806a4bef96889117fd7ebac0e3cb5ec152932", 1, "submodule"},
111+
{ 0160000, "297aa6cd028b3336c7802c7a6f49143da4e1602d", 3, "submodule" },
112+
};
113+
114+
cl_git_pass(git_reference_lookup(&our_ref, repo, "refs/heads/" SUBMODULE_DELETE_BRANCH));
115+
cl_git_pass(git_commit_lookup(&our_commit, repo, git_reference_target(our_ref)));
116+
cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL));
117+
118+
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_MAIN_BRANCH));
119+
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
120+
121+
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, 1, NULL, NULL));
122+
123+
cl_git_pass(git_repository_index(&index, repo));
124+
cl_assert(merge_test_index(index, merge_index_entries, 5));
125+
126+
git_index_free(index);
127+
git_annotated_commit_free(their_head);
128+
git_commit_free(our_commit);
129+
git_reference_free(their_ref);
130+
git_reference_free(our_ref);
131+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��]
2+
�0�}�)�J�v�">x/�I6ZhIӞ�*���a�e��Z�C��`��F�6;KL�O)�.y��8�N��^���� ���}�a'��Ѱ �S����*����g�p�mHp_���s�h��/O�>.�Pi�F��������?��,k�JZGo��JT
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
50c5dc8cdfe40c688eb0a0e23be54dd57cae2e78

0 commit comments

Comments
 (0)