Commit 25743bd7 by Edward Thomson

add an index_remove_bypath that removes conflicts, renamed add_from_workdir to match

parent e2d2c6e5
......@@ -362,7 +362,7 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
/**@{*/
/**
* Add or update an index entry from a file in disk
* Add or update an index entry from a file on disk
*
* The file `path` must be relative to the repository's
* working folder and must be readable.
......@@ -381,7 +381,23 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
* @param path filename to add
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_add_from_workdir(git_index *index, const char *path);
GIT_EXTERN(int) git_index_add_bypath(git_index *index, const char *path);
/**
* Remove an index entry corresponding to a file on disk
*
* The file `path` must be relative to the repository's
* working folder. It may exist.
*
* If this file currently is the result of a merge conflict, this
* file will no longer be marked as conflicting. The data about
* the conflict will be moved to the "resolve undo" (REUC) section.
*
* @param index an existing index object
* @param path filename to remove
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path);
/**
* Find the first index of any entries which point to given
......
......@@ -730,7 +730,7 @@ static int index_conflict_to_reuc(git_index *index, const char *path)
return ret;
}
int git_index_add_from_workdir(git_index *index, const char *path)
int git_index_add_bypath(git_index *index, const char *path)
{
git_index_entry *entry = NULL;
int ret;
......@@ -753,6 +753,21 @@ on_error:
return ret;
}
int git_index_remove_bypath(git_index *index, const char *path)
{
int ret;
assert(index && path);
if (((ret = git_index_remove(index, path, 0)) < 0 &&
ret != GIT_ENOTFOUND) ||
((ret = index_conflict_to_reuc(index, path)) < 0 &&
ret != GIT_ENOTFOUND))
return ret;
return 0;
}
int git_index_add(git_index *index, const git_index_entry *source_entry)
{
git_index_entry *entry = NULL;
......
......@@ -208,7 +208,7 @@ static int update_index_cb(
}
if (add_path != NULL)
data->error = git_index_add_from_workdir(data->index, add_path);
data->error = git_index_add_bypath(data->index, add_path);
return data->error;
}
......
......@@ -332,7 +332,7 @@ int git_submodule_add_finalize(git_submodule *sm)
assert(sm);
if ((error = git_repository_index__weakptr(&index, sm->owner)) < 0 ||
(error = git_index_add_from_workdir(index, GIT_MODULES_FILE)) < 0)
(error = git_index_add_bypath(index, GIT_MODULES_FILE)) < 0)
return error;
return git_submodule_add_to_index(sm, true);
......
......@@ -270,7 +270,7 @@ static void assert_proper_normalization(git_index *index, const char *filename,
const git_index_entry *entry;
add_to_workdir(filename, CONTENT);
cl_git_pass(git_index_add_from_workdir(index, filename));
cl_git_pass(git_index_add_bypath(index, filename));
index_pos = git_index_find(index, filename);
cl_assert(index_pos >= 0);
......
......@@ -40,7 +40,7 @@ void test_checkout_head__with_index_only_tree(void)
p_mkdir("testrepo/newdir", 0777);
cl_git_mkfile("testrepo/newdir/newfile.txt", "new file\n");
cl_git_pass(git_index_add_from_workdir(index, "newdir/newfile.txt"));
cl_git_pass(git_index_add_bypath(index, "newdir/newfile.txt"));
cl_git_pass(git_index_write(index));
cl_assert(git_path_isfile("testrepo/newdir/newfile.txt"));
......
......@@ -417,8 +417,8 @@ void test_checkout_index__can_overcome_name_clashes(void)
cl_git_pass(p_mkdir("./testrepo/path1", 0777));
cl_git_mkfile("./testrepo/path1/file1", "content\r\n");
cl_git_pass(git_index_add_from_workdir(index, "path0"));
cl_git_pass(git_index_add_from_workdir(index, "path1/file1"));
cl_git_pass(git_index_add_bypath(index, "path0"));
cl_git_pass(git_index_add_bypath(index, "path1/file1"));
cl_git_pass(p_unlink("./testrepo/path0"));
cl_git_pass(git_futils_rmdir_r(
......
......@@ -406,7 +406,7 @@ void assert_conflict(
GIT_EMERGECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));
/* Stage the conflicting change */
cl_git_pass(git_index_add_from_workdir(index, entry_path));
cl_git_pass(git_index_add_bypath(index, entry_path));
cl_git_pass(git_index_write(index));
cl_assert_equal_i(
......
......@@ -154,7 +154,7 @@ void test_index_conflicts__remove(void)
}
}
void test_index_conflicts__moved_to_reuc(void)
void test_index_conflicts__moved_to_reuc_on_add(void)
{
const git_index_entry *entry;
size_t i;
......@@ -163,7 +163,7 @@ void test_index_conflicts__moved_to_reuc(void)
cl_git_mkfile("./mergedrepo/conflicts-one.txt", "new-file\n");
cl_git_pass(git_index_add_from_workdir(repo_index, "conflicts-one.txt"));
cl_git_pass(git_index_add_bypath(repo_index, "conflicts-one.txt"));
cl_assert(git_index_entrycount(repo_index) == 6);
......@@ -175,6 +175,25 @@ void test_index_conflicts__moved_to_reuc(void)
}
}
void test_index_conflicts__moved_to_reuc_on_remove(void)
{
const git_index_entry *entry;
size_t i;
cl_assert(git_index_entrycount(repo_index) == 8);
cl_git_pass(p_unlink("./mergedrepo/conflicts-one.txt"));
cl_git_pass(git_index_remove_bypath(repo_index, "conflicts-one.txt"));
cl_assert(git_index_entrycount(repo_index) == 5);
for (i = 0; i < git_index_entrycount(repo_index); i++) {
cl_assert(entry = git_index_get_byindex(repo_index, i));
cl_assert(strcmp(entry->path, "conflicts-one.txt") != 0);
}
}
void test_index_conflicts__remove_all_conflicts(void)
{
size_t i;
......
......@@ -56,7 +56,7 @@ static void add_and_check_mode(
int pos;
const git_index_entry *entry;
cl_git_pass(git_index_add_from_workdir(index, filename));
cl_git_pass(git_index_add_bypath(index, filename));
pos = git_index_find(index, filename);
cl_assert(pos >= 0);
......
......@@ -10,13 +10,13 @@ void test_index_inmemory__can_create_an_inmemory_index(void)
git_index_free(index);
}
void test_index_inmemory__cannot_add_from_workdir_to_an_inmemory_index(void)
void test_index_inmemory__cannot_add_bypath_to_an_inmemory_index(void)
{
git_index *index;
cl_git_pass(git_index_new(&index));
cl_assert_equal_i(GIT_ERROR, git_index_add_from_workdir(index, "test.txt"));
cl_assert_equal_i(GIT_ERROR, git_index_add_bypath(index, "test.txt"));
git_index_free(index);
}
......@@ -24,9 +24,9 @@ void test_index_read_tree__read_write_involution(void)
cl_git_mkfile("./read_tree/abc/d", NULL);
cl_git_mkfile("./read_tree/abc_d", NULL);
cl_git_pass(git_index_add_from_workdir(index, "abc-d"));
cl_git_pass(git_index_add_from_workdir(index, "abc_d"));
cl_git_pass(git_index_add_from_workdir(index, "abc/d"));
cl_git_pass(git_index_add_bypath(index, "abc-d"));
cl_git_pass(git_index_add_bypath(index, "abc_d"));
cl_git_pass(git_index_add_bypath(index, "abc/d"));
/* write-tree */
cl_git_pass(git_index_write_tree(&expected, index));
......
......@@ -19,7 +19,7 @@ void test_index_rename__single_file(void)
cl_git_mkfile("./rename/lame.name.txt", "new_file\n");
/* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
cl_git_pass(git_index_add_from_workdir(index, "lame.name.txt"));
cl_git_pass(git_index_add_bypath(index, "lame.name.txt"));
cl_assert(git_index_entrycount(index) == 1);
cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"));
......@@ -35,7 +35,7 @@ void test_index_rename__single_file(void)
p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt");
cl_git_pass(git_index_add_from_workdir(index, "fancy.name.txt"));
cl_git_pass(git_index_add_bypath(index, "fancy.name.txt"));
cl_assert(git_index_entrycount(index) == 1);
position = git_index_find(index, "fancy.name.txt");
......
......@@ -31,7 +31,7 @@ void test_index_stage__add_always_adds_stage_0(void)
cl_git_mkfile("./mergedrepo/new-file.txt", "new-file\n");
cl_git_pass(git_index_add_from_workdir(repo_index, "new-file.txt"));
cl_git_pass(git_index_add_bypath(repo_index, "new-file.txt"));
cl_assert((entry_idx = git_index_find(repo_index, "new-file.txt")) >= 0);
cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
......
......@@ -233,7 +233,7 @@ void test_index_tests__add(void)
cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"));
/* Add the new file to the index */
cl_git_pass(git_index_add_from_workdir(index, "test.txt"));
cl_git_pass(git_index_add_bypath(index, "test.txt"));
/* Wow... it worked! */
cl_assert(git_index_entrycount(index) == 1);
......@@ -250,7 +250,7 @@ void test_index_tests__add(void)
git_repository_free(repo);
}
void test_index_tests__add_from_workdir_to_a_bare_repository_returns_EBAREPO(void)
void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
{
git_repository *bare_repo;
git_index *index;
......@@ -258,7 +258,7 @@ void test_index_tests__add_from_workdir_to_a_bare_repository_returns_EBAREPO(voi
cl_git_pass(git_repository_open(&bare_repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_index(&index, bare_repo));
cl_assert_equal_i(GIT_EBAREREPO, git_index_add_from_workdir(index, "test.txt"));
cl_assert_equal_i(GIT_EBAREREPO, git_index_add_bypath(index, "test.txt"));
git_index_free(index);
git_repository_free(bare_repo);
......@@ -280,7 +280,7 @@ void test_index_tests__write_invalid_filename(void)
cl_git_mkfile("./read_tree/.git/hello", NULL);
cl_git_pass(git_index_add_from_workdir(index, ".git/hello"));
cl_git_pass(git_index_add_bypath(index, ".git/hello"));
/* write-tree */
cl_git_fail(git_index_write_tree(&expected, index));
......@@ -303,7 +303,7 @@ void test_index_tests__remove_entry(void)
cl_assert(git_index_entrycount(index) == 0);
cl_git_mkfile("index_test/hello", NULL);
cl_git_pass(git_index_add_from_workdir(index, "hello"));
cl_git_pass(git_index_add_bypath(index, "hello"));
cl_git_pass(git_index_write(index));
cl_git_pass(git_index_read(index)); /* reload */
......@@ -339,10 +339,10 @@ void test_index_tests__remove_directory(void)
cl_git_mkfile("index_test/a/3.txt", NULL);
cl_git_mkfile("index_test/b.txt", NULL);
cl_git_pass(git_index_add_from_workdir(index, "a/1.txt"));
cl_git_pass(git_index_add_from_workdir(index, "a/2.txt"));
cl_git_pass(git_index_add_from_workdir(index, "a/3.txt"));
cl_git_pass(git_index_add_from_workdir(index, "b.txt"));
cl_git_pass(git_index_add_bypath(index, "a/1.txt"));
cl_git_pass(git_index_add_bypath(index, "a/2.txt"));
cl_git_pass(git_index_add_bypath(index, "a/3.txt"));
cl_git_pass(git_index_add_bypath(index, "b.txt"));
cl_git_pass(git_index_write(index));
cl_git_pass(git_index_read(index)); /* reload */
......
......@@ -73,7 +73,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
*/
cl_git_mkfile("treebuilder/test.txt", "test\n");
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_from_workdir(index, "test.txt"));
cl_git_pass(git_index_add_bypath(index, "test.txt"));
entry = git_index_get_byindex(index, 0);
......
......@@ -34,7 +34,7 @@ static void push_three_states(void)
cl_git_mkfile("stash/zero.txt", "content\n");
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_from_workdir(index, "zero.txt"));
cl_git_pass(git_index_add_bypath(index, "zero.txt"));
commit_staged_files(&oid, index, signature);
cl_assert(git_path_exists("stash/zero.txt"));
......
......@@ -251,8 +251,8 @@ void test_stash_save__cannot_stash_when_there_are_no_local_change(void)
* 'what' and 'who' are being committed.
* 'when' remain untracked.
*/
cl_git_pass(git_index_add_from_workdir(index, "what"));
cl_git_pass(git_index_add_from_workdir(index, "who"));
cl_git_pass(git_index_add_bypath(index, "what"));
cl_git_pass(git_index_add_bypath(index, "who"));
cl_git_pass(git_index_write(index));
commit_staged_files(&commit_oid, index, signature);
git_index_free(index);
......
......@@ -46,10 +46,10 @@ void setup_stash(git_repository *repo, git_signature *signature)
cl_git_mkfile("stash/.gitignore", "*.ignore\n");
cl_git_pass(git_index_add_from_workdir(index, "what"));
cl_git_pass(git_index_add_from_workdir(index, "how"));
cl_git_pass(git_index_add_from_workdir(index, "who"));
cl_git_pass(git_index_add_from_workdir(index, ".gitignore"));
cl_git_pass(git_index_add_bypath(index, "what"));
cl_git_pass(git_index_add_bypath(index, "how"));
cl_git_pass(git_index_add_bypath(index, "who"));
cl_git_pass(git_index_add_bypath(index, ".gitignore"));
cl_git_pass(git_index_write(index));
commit_staged_files(&commit_oid, index, signature);
......@@ -58,8 +58,8 @@ void setup_stash(git_repository *repo, git_signature *signature)
cl_git_rewritefile("stash/how", "not so small and\n"); /* e6d64adb2c7f3eb8feb493b556cc8070dca379a3 */
cl_git_rewritefile("stash/who", "funky world\n"); /* a0400d4954659306a976567af43125a0b1aa8595 */
cl_git_pass(git_index_add_from_workdir(index, "what"));
cl_git_pass(git_index_add_from_workdir(index, "how"));
cl_git_pass(git_index_add_bypath(index, "what"));
cl_git_pass(git_index_add_bypath(index, "how"));
cl_git_pass(git_index_write(index));
cl_git_rewritefile("stash/what", "see you later\n"); /* bc99dc98b3eba0e9157e94769cd4d49cb49de449 */
......
......@@ -38,7 +38,7 @@ void test_status_worktree_init__first_commit_in_progress(void)
cl_assert(result.status == GIT_STATUS_WT_NEW);
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_from_workdir(index, "testfile.txt"));
cl_git_pass(git_index_add_bypath(index, "testfile.txt"));
cl_git_pass(git_index_write(index));
memset(&result, 0, sizeof(result));
......@@ -172,7 +172,7 @@ void test_status_worktree_init__bracket_in_filename(void)
/* add the file to the index */
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_from_workdir(index, FILE_WITH_BRACKET));
cl_git_pass(git_index_add_bypath(index, FILE_WITH_BRACKET));
cl_git_pass(git_index_write(index));
memset(&result, 0, sizeof(result));
......@@ -251,7 +251,7 @@ void test_status_worktree_init__space_in_filename(void)
/* add the file to the index */
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_from_workdir(index, FILE_WITH_SPACE));
cl_git_pass(git_index_add_bypath(index, FILE_WITH_SPACE));
cl_git_pass(git_index_write(index));
memset(&result, 0, sizeof(result));
......@@ -329,7 +329,7 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); // Content with CRLF
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_from_workdir(index, "testfile.txt"));
cl_git_pass(git_index_add_bypath(index, "testfile.txt"));
cl_git_pass(git_index_write(index));
cl_git_pass(git_status_file(&status, repo, "testfile.txt"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment