Skip to content

submodule: git_index_add_bypath does not move conflict entries to REU… #7003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
submodule: git_index_add_bypath does not move conflict entries to REU…
…C for submodules

Fixes #6963

submodule: git_index_add_bypath does not move conflict entries to REUC for submodules
Fixes #6963
  • Loading branch information
lrm29 committed Jun 1, 2025
commit 14abe60fd4230060fa2d4f1b742eb7e34cea2bbc
8 changes: 4 additions & 4 deletions src/libgit2/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ static int index_insert(
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/libgit2/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
17 changes: 12 additions & 5 deletions src/libgit2/submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/libgit2/merge/workdir/submodules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
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