summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-01-03 14:08:53 -0800
committerRussell Belfer <rb@github.com>2013-01-04 15:47:44 -0800
commitd8889d2b64a0a28f33a189216e1d63669b9be206 (patch)
treee6f7deafb92f9c260c1ebdff94409438b8934a77 /tests-clar
parentdde7602ae633a557acdb74c8027335bb2584aa77 (diff)
downloadlibgit2-d8889d2b64a0a28f33a189216e1d63669b9be206.tar.gz
Fix checkout bug rmv untracked trees from index
When checking out with the GIT_CHECKOUT_REMOVE_UNTRACKED option and there was an entire tree in the working directory and in the index that is not in the baseline nor target commit, the tree was correctly(?) removed from the working directory but was not successfully removed from the index. This fixes that and adds a test of the functionality.
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/checkout/head.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests-clar/checkout/head.c b/tests-clar/checkout/head.c
index aed203a06..8b3099303 100644
--- a/tests-clar/checkout/head.c
+++ b/tests-clar/checkout/head.c
@@ -1,6 +1,8 @@
#include "clar_libgit2.h"
#include "refs.h"
#include "repo/repo_helpers.h"
+#include "path.h"
+#include "fileops.h"
static git_repository *g_repo;
@@ -20,3 +22,42 @@ void test_checkout_head__orphaned_head_returns_GIT_EORPHANEDHEAD(void)
cl_assert_equal_i(GIT_EORPHANEDHEAD, git_checkout_head(g_repo, NULL));
}
+
+void test_checkout_head__with_index_only_tree(void)
+{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_index *index;
+
+ /* let's start by getting things into a known state */
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+
+ /* now let's stage some new stuff including a new directory */
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ 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_write(index));
+
+ cl_assert(git_path_isfile("testrepo/newdir/newfile.txt"));
+ cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) != NULL);
+
+ git_index_free(index);
+
+ /* okay, so now we have staged this new file; let's see if we can remove */
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_read(index)); /* reload if needed */
+
+ cl_assert(!git_path_isfile("testrepo/newdir/newfile.txt"));
+ cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) == NULL);
+
+ git_index_free(index);
+}