mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
Merge pull request #7003 from mathworks/lrm29/issue6963
submodule: git_index_add_bypath does not move conflict entries to REU…
This commit is contained in:
@@ -1433,7 +1433,7 @@ out:
|
||||
return error;
|
||||
}
|
||||
|
||||
static int index_conflict_to_reuc(git_index *index, const char *path)
|
||||
int git_index__conflict_to_reuc(git_index *index, const char *path)
|
||||
{
|
||||
const git_index_entry *conflict_entries[3];
|
||||
int ancestor_mode, our_mode, their_mode;
|
||||
@@ -1513,7 +1513,7 @@ int git_index_add_from_buffer(
|
||||
return error;
|
||||
|
||||
/* Adding implies conflict was resolved, move conflict entries to REUC */
|
||||
if ((error = index_conflict_to_reuc(index, entry->path)) < 0 && error != GIT_ENOTFOUND)
|
||||
if ((error = git_index__conflict_to_reuc(index, entry->path)) < 0 && error != GIT_ENOTFOUND)
|
||||
return error;
|
||||
|
||||
git_tree_cache_invalidate_path(index->tree, entry->path);
|
||||
@@ -1609,7 +1609,7 @@ int git_index_add_bypath(git_index *index, const char *path)
|
||||
}
|
||||
|
||||
/* Adding implies conflict was resolved, move conflict entries to REUC */
|
||||
if ((ret = index_conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND)
|
||||
if ((ret = git_index__conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND)
|
||||
return ret;
|
||||
|
||||
git_tree_cache_invalidate_path(index->tree, entry->path);
|
||||
@@ -1625,7 +1625,7 @@ int git_index_remove_bypath(git_index *index, const char *path)
|
||||
|
||||
if (((ret = git_index_remove(index, path, 0)) < 0 &&
|
||||
ret != GIT_ENOTFOUND) ||
|
||||
((ret = index_conflict_to_reuc(index, path)) < 0 &&
|
||||
((ret = git_index__conflict_to_reuc(index, path)) < 0 &&
|
||||
ret != GIT_ENOTFOUND))
|
||||
return ret;
|
||||
|
||||
|
||||
@@ -147,6 +147,9 @@ GIT_INLINE(unsigned char *) git_index__checksum(git_index *index)
|
||||
return index->checksum;
|
||||
}
|
||||
|
||||
/* If the path is conflicted, move it from the index to reuc. */
|
||||
int git_index__conflict_to_reuc(git_index *index, const char *path);
|
||||
|
||||
/* Copy the current entries vector *and* increment the index refcount.
|
||||
* Call `git_index__release_snapshot` when done.
|
||||
*/
|
||||
|
||||
@@ -1074,16 +1074,23 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
|
||||
git_commit_free(head);
|
||||
|
||||
/* add it */
|
||||
error = git_index_add(index, &entry);
|
||||
if ((error = git_index_add(index, &entry)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Adding implies conflict was resolved, move conflict entries to REUC */
|
||||
if ((error = git_index__conflict_to_reuc(index, entry.path)) < 0 && error != GIT_ENOTFOUND)
|
||||
goto cleanup;
|
||||
|
||||
/* write it, if requested */
|
||||
if (!error && write_index) {
|
||||
error = git_index_write(index);
|
||||
if (write_index) {
|
||||
if ((error = git_index_write(index)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!error)
|
||||
git_oid_cpy(&sm->index_oid, &sm->wd_oid);
|
||||
git_oid_cpy(&sm->index_oid, &sm->wd_oid);
|
||||
}
|
||||
|
||||
error = 0;
|
||||
|
||||
cleanup:
|
||||
git_repository_free(sm_repo);
|
||||
git_str_dispose(&path);
|
||||
|
||||
@@ -53,6 +53,16 @@ void test_merge_workdir_submodules__automerge(void)
|
||||
|
||||
cl_git_pass(git_repository_index(&index, repo));
|
||||
cl_assert(merge_test_index(index, merge_index_entries, 6));
|
||||
cl_assert_equal_i(true, git_index_has_conflicts(index));
|
||||
|
||||
/* Put an actual Git repository into the submodule path on disk.
|
||||
* Add it to the index and assert that the conflict is resolved.
|
||||
*/
|
||||
cl_fixture_sandbox("testrepo");
|
||||
p_rename("testrepo", TEST_REPO_PATH "/submodule");
|
||||
p_rename(TEST_REPO_PATH "/submodule/.gitted", TEST_REPO_PATH "/submodule/.git");
|
||||
cl_git_pass(git_index_add_bypath(index, "submodule"));
|
||||
cl_assert_equal_i(false, git_index_has_conflicts(index));
|
||||
|
||||
git_index_free(index);
|
||||
git_annotated_commit_free(their_head);
|
||||
|
||||
Reference in New Issue
Block a user