summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2013-01-12 13:47:56 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2013-01-12 13:47:56 -0600
commit25743bd7c5f14f2287d9c4fdf953c978e3b16916 (patch)
tree7390d1d2d5d52f549329853903f381e58c1b1de6
parente2d2c6e57d122f381fb42b7df1c7a12819050490 (diff)
downloadlibgit2-25743bd7c5f14f2287d9c4fdf953c978e3b16916.tar.gz
add an index_remove_bypath that removes conflicts, renamed add_from_workdir to match
-rw-r--r--include/git2/index.h20
-rw-r--r--src/index.c17
-rw-r--r--src/stash.c2
-rw-r--r--src/submodule.c2
-rw-r--r--tests-clar/attr/repo.c2
-rw-r--r--tests-clar/checkout/head.c2
-rw-r--r--tests-clar/checkout/index.c4
-rw-r--r--tests-clar/checkout/tree.c2
-rw-r--r--tests-clar/index/conflicts.c23
-rw-r--r--tests-clar/index/filemodes.c2
-rw-r--r--tests-clar/index/inmemory.c4
-rw-r--r--tests-clar/index/read_tree.c6
-rw-r--r--tests-clar/index/rename.c4
-rw-r--r--tests-clar/index/stage.c2
-rw-r--r--tests-clar/index/tests.c18
-rw-r--r--tests-clar/object/commit/commitstagedfile.c2
-rw-r--r--tests-clar/stash/drop.c2
-rw-r--r--tests-clar/stash/save.c4
-rw-r--r--tests-clar/stash/stash_helpers.c12
-rw-r--r--tests-clar/status/worktree_init.c8
20 files changed, 94 insertions, 44 deletions
diff --git a/include/git2/index.h b/include/git2/index.h
index 2df5103fd..ad6d19733 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -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
diff --git a/src/index.c b/src/index.c
index 606a431a4..76384288e 100644
--- a/src/index.c
+++ b/src/index.c
@@ -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;
diff --git a/src/stash.c b/src/stash.c
index e63a362f0..d4f81aefe 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -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;
}
diff --git a/src/submodule.c b/src/submodule.c
index a72326602..a38ece079 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -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);
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index 1d2b1e8df..926a0d8a2 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -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);
diff --git a/tests-clar/checkout/head.c b/tests-clar/checkout/head.c
index 8b3099303..46646f8bf 100644
--- a/tests-clar/checkout/head.c
+++ b/tests-clar/checkout/head.c
@@ -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"));
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index 2dc08715d..9a70f3166 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -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(
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
index 80e26a15a..176dcceb9 100644
--- a/tests-clar/checkout/tree.c
+++ b/tests-clar/checkout/tree.c
@@ -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(
diff --git a/tests-clar/index/conflicts.c b/tests-clar/index/conflicts.c
index 2fbad3e67..4b8a0cffd 100644
--- a/tests-clar/index/conflicts.c
+++ b/tests-clar/index/conflicts.c
@@ -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;
diff --git a/tests-clar/index/filemodes.c b/tests-clar/index/filemodes.c
index 6140b11ed..1acd2e341 100644
--- a/tests-clar/index/filemodes.c
+++ b/tests-clar/index/filemodes.c
@@ -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);
diff --git a/tests-clar/index/inmemory.c b/tests-clar/index/inmemory.c
index a5f72c422..38e91e0fd 100644
--- a/tests-clar/index/inmemory.c
+++ b/tests-clar/index/inmemory.c
@@ -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);
}
diff --git a/tests-clar/index/read_tree.c b/tests-clar/index/read_tree.c
index 3ae883d18..6c6b40121 100644
--- a/tests-clar/index/read_tree.c
+++ b/tests-clar/index/read_tree.c
@@ -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));
diff --git a/tests-clar/index/rename.c b/tests-clar/index/rename.c
index adbbcfaac..400bbdf15 100644
--- a/tests-clar/index/rename.c
+++ b/tests-clar/index/rename.c
@@ -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");
diff --git a/tests-clar/index/stage.c b/tests-clar/index/stage.c
index 0f3b29832..477456846 100644
--- a/tests-clar/index/stage.c
+++ b/tests-clar/index/stage.c
@@ -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);
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 5c3d4cf41..3c2a6899c 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -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 */
diff --git a/tests-clar/object/commit/commitstagedfile.c b/tests-clar/object/commit/commitstagedfile.c
index 55c70d98e..9867ab418 100644
--- a/tests-clar/object/commit/commitstagedfile.c
+++ b/tests-clar/object/commit/commitstagedfile.c
@@ -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);
diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c
index 2af95c737..16e3d77ac 100644
--- a/tests-clar/stash/drop.c
+++ b/tests-clar/stash/drop.c
@@ -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"));
diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c
index e6033e1ef..ea2eb282d 100644
--- a/tests-clar/stash/save.c
+++ b/tests-clar/stash/save.c
@@ -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);
diff --git a/tests-clar/stash/stash_helpers.c b/tests-clar/stash/stash_helpers.c
index 86a741853..f462a1351 100644
--- a/tests-clar/stash/stash_helpers.c
+++ b/tests-clar/stash/stash_helpers.c
@@ -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 */
diff --git a/tests-clar/status/worktree_init.c b/tests-clar/status/worktree_init.c
index 6d790b1c9..0c34dde87 100644
--- a/tests-clar/status/worktree_init.c
+++ b/tests-clar/status/worktree_init.c
@@ -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"));