void test_index_tests__remove_directory(void) { git_repository *repo; git_index *index; p_mkdir("index_test", 0770); cl_git_pass(git_repository_init(&repo, "index_test", 0)); cl_git_pass(git_repository_index(&index, repo)); cl_assert_equal_i(0, (int)git_index_entrycount(index)); p_mkdir("index_test/a", 0770); cl_git_mkfile("index_test/a/1.txt", NULL); cl_git_mkfile("index_test/a/2.txt", NULL); cl_git_mkfile("index_test/a/3.txt", NULL); cl_git_mkfile("index_test/b.txt", NULL); 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, true)); /* reload */ cl_assert_equal_i(4, (int)git_index_entrycount(index)); cl_assert(git_index_get_bypath(index, "a/1.txt", 0) != NULL); cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL); cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL); cl_git_pass(git_index_remove(index, "a/1.txt", 0)); cl_git_pass(git_index_write(index)); cl_git_pass(git_index_read(index, true)); /* reload */ cl_assert_equal_i(3, (int)git_index_entrycount(index)); cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL); cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL); cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL); cl_git_pass(git_index_remove_directory(index, "a", 0)); cl_git_pass(git_index_write(index)); cl_git_pass(git_index_read(index, true)); /* reload */ cl_assert_equal_i(1, (int)git_index_entrycount(index)); cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL); cl_assert(git_index_get_bypath(index, "a/2.txt", 0) == NULL); cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL); git_index_free(index); git_repository_free(repo); cl_fixture_cleanup("index_test"); }
void GitWrapper::commitDeleteBasket(BasketScene *basket) { GIT_RETURN_IF_DISABLED() QMutexLocker l(&gitMutex); git_index *index = NULL; git_repository* repo = openRepository(); if(repo == 0) return; int error = git_repository_index(&index, repo); if(error < 0) { gitErrorHandling(); return; } //remove the directory const QString dir("baskets/" + basket->folderName()); const QByteArray dirba = dir.toUtf8(); const char *dirCString = dirba.data(); error = git_index_remove_directory(index, dirCString, 0); if(error < 0) { gitErrorHandling(); return; } //change basket.xml const QString basketxml("baskets/baskets.xml"); QByteArray basketxmlba = basketxml.toUtf8(); char *basketxmlCString = basketxmlba.data(); error = git_index_add_bypath(index, basketxmlCString); if(error < 0) { gitErrorHandling(); return; } removeDeletedFromIndex(repo,index); bool result = commitIndex(repo,index); git_index_free(index); git_repository_free(repo); }
/* * call-seq: * index.remove_dir(dir[, stage = 0]) -> nil * * Removes all entries under the given +dir+ with the given +stage+ * from the index. */ static VALUE rb_git_index_remove_directory(int argc, VALUE *argv, VALUE self) { git_index *index; int error, stage = 0; VALUE rb_dir, rb_stage; Data_Get_Struct(self, git_index, index); if (rb_scan_args(argc, argv, "11", &rb_dir, &rb_stage) > 1) { Check_Type(rb_stage, T_FIXNUM); stage = FIX2INT(rb_stage); } Check_Type(rb_dir, T_STRING); error = git_index_remove_directory(index, StringValueCStr(rb_dir), stage); rugged_exception_check(error); return Qnil; }
void Index::removeDirectory(const std::string& dir, int stage) { Exception::git2_assert(git_index_remove_directory(data(), dir.c_str(), stage)); }