Skip to content

Commit 14abe60

Browse files
committed
submodule: git_index_add_bypath does not move conflict entries to REUC for submodules
Fixes #6963 submodule: git_index_add_bypath does not move conflict entries to REUC for submodules Fixes #6963
1 parent 666bbed commit 14abe60

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/libgit2/index.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ static int index_insert(
14331433
return error;
14341434
}
14351435

1436-
static int index_conflict_to_reuc(git_index *index, const char *path)
1436+
int git_index__conflict_to_reuc(git_index *index, const char *path)
14371437
{
14381438
const git_index_entry *conflict_entries[3];
14391439
int ancestor_mode, our_mode, their_mode;
@@ -1513,7 +1513,7 @@ int git_index_add_from_buffer(
15131513
return error;
15141514

15151515
/* Adding implies conflict was resolved, move conflict entries to REUC */
1516-
if ((error = index_conflict_to_reuc(index, entry->path)) < 0 && error != GIT_ENOTFOUND)
1516+
if ((error = git_index__conflict_to_reuc(index, entry->path)) < 0 && error != GIT_ENOTFOUND)
15171517
return error;
15181518

15191519
git_tree_cache_invalidate_path(index->tree, entry->path);
@@ -1609,7 +1609,7 @@ int git_index_add_bypath(git_index *index, const char *path)
16091609
}
16101610

16111611
/* Adding implies conflict was resolved, move conflict entries to REUC */
1612-
if ((ret = index_conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND)
1612+
if ((ret = git_index__conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND)
16131613
return ret;
16141614

16151615
git_tree_cache_invalidate_path(index->tree, entry->path);
@@ -1625,7 +1625,7 @@ int git_index_remove_bypath(git_index *index, const char *path)
16251625

16261626
if (((ret = git_index_remove(index, path, 0)) < 0 &&
16271627
ret != GIT_ENOTFOUND) ||
1628-
((ret = index_conflict_to_reuc(index, path)) < 0 &&
1628+
((ret = git_index__conflict_to_reuc(index, path)) < 0 &&
16291629
ret != GIT_ENOTFOUND))
16301630
return ret;
16311631

src/libgit2/index.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ GIT_INLINE(unsigned char *) git_index__checksum(git_index *index)
147147
return index->checksum;
148148
}
149149

150+
/* If the path is conflicted, move it from the index to reuc. */
151+
int git_index__conflict_to_reuc(git_index *index, const char *path);
152+
150153
/* Copy the current entries vector *and* increment the index refcount.
151154
* Call `git_index__release_snapshot` when done.
152155
*/

src/libgit2/submodule.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,16 +1074,23 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
10741074
git_commit_free(head);
10751075

10761076
/* add it */
1077-
error = git_index_add(index, &entry);
1077+
if ((error = git_index_add(index, &entry)) < 0)
1078+
goto cleanup;
1079+
1080+
/* Adding implies conflict was resolved, move conflict entries to REUC */
1081+
if ((error = git_index__conflict_to_reuc(index, entry.path)) < 0 && error != GIT_ENOTFOUND)
1082+
goto cleanup;
10781083

10791084
/* write it, if requested */
1080-
if (!error && write_index) {
1081-
error = git_index_write(index);
1085+
if (write_index) {
1086+
if ((error = git_index_write(index)) < 0)
1087+
goto cleanup;
10821088

1083-
if (!error)
1084-
git_oid_cpy(&sm->index_oid, &sm->wd_oid);
1089+
git_oid_cpy(&sm->index_oid, &sm->wd_oid);
10851090
}
10861091

1092+
error = 0;
1093+
10871094
cleanup:
10881095
git_repository_free(sm_repo);
10891096
git_str_dispose(&path);

tests/libgit2/merge/workdir/submodules.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ void test_merge_workdir_submodules__automerge(void)
5353

5454
cl_git_pass(git_repository_index(&index, repo));
5555
cl_assert(merge_test_index(index, merge_index_entries, 6));
56+
cl_assert_equal_i(true, git_index_has_conflicts(index));
57+
58+
/* Put an actual Git repository into the submodule path on disk.
59+
* Add it to the index and assert that the conflict is resolved.
60+
*/
61+
cl_fixture_sandbox("testrepo");
62+
p_rename("testrepo", TEST_REPO_PATH "/submodule");
63+
p_rename(TEST_REPO_PATH "/submodule/.gitted", TEST_REPO_PATH "/submodule/.git");
64+
cl_git_pass(git_index_add_bypath(index, "submodule"));
65+
cl_assert_equal_i(false, git_index_has_conflicts(index));
5666

5767
git_index_free(index);
5868
git_annotated_commit_free(their_head);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy