void test_index_conflicts__add_fixes_incorrect_stage(void) { git_index_entry ancestor_entry, our_entry, their_entry; const git_index_entry *conflict_entry[3]; cl_assert(git_index_entrycount(repo_index) == 8); memset(&ancestor_entry, 0x0, sizeof(git_index_entry)); memset(&our_entry, 0x0, sizeof(git_index_entry)); memset(&their_entry, 0x0, sizeof(git_index_entry)); ancestor_entry.path = "test-one.txt"; ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT); git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID); our_entry.path = "test-one.txt"; ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT); git_oid_fromstr(&our_entry.id, TEST_OUR_OID); their_entry.path = "test-one.txt"; ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT); git_oid_fromstr(&their_entry.id, TEST_THEIR_OID); cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry)); cl_assert(git_index_entrycount(repo_index) == 11); cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, "test-one.txt")); cl_assert(git_index_entry_stage(conflict_entry[0]) == 1); cl_assert(git_index_entry_stage(conflict_entry[1]) == 2); cl_assert(git_index_entry_stage(conflict_entry[2]) == 3); }
void test_index_conflicts__add(void) { git_index_entry ancestor_entry, our_entry, their_entry; cl_assert(git_index_entrycount(repo_index) == 8); memset(&ancestor_entry, 0x0, sizeof(git_index_entry)); memset(&our_entry, 0x0, sizeof(git_index_entry)); memset(&their_entry, 0x0, sizeof(git_index_entry)); ancestor_entry.path = "test-one.txt"; ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT); git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID); our_entry.path = "test-one.txt"; ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT); git_oid_fromstr(&our_entry.id, TEST_OUR_OID); their_entry.path = "test-one.txt"; ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT); git_oid_fromstr(&their_entry.id, TEST_THEIR_OID); cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry)); cl_assert(git_index_entrycount(repo_index) == 11); }
void test_index_tests__remove_entry(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(git_index_entrycount(index) == 0); cl_git_mkfile("index_test/hello", NULL); cl_git_pass(git_index_add_bypath(index, "hello")); cl_git_pass(git_index_write(index)); cl_git_pass(git_index_read(index, true)); /* reload */ cl_assert(git_index_entrycount(index) == 1); cl_assert(git_index_get_bypath(index, "hello", 0) != NULL); cl_git_pass(git_index_remove(index, "hello", 0)); cl_git_pass(git_index_write(index)); cl_git_pass(git_index_read(index, true)); /* reload */ cl_assert(git_index_entrycount(index) == 0); cl_assert(git_index_get_bypath(index, "hello", 0) == NULL); git_index_free(index); git_repository_free(repo); cl_fixture_cleanup("index_test"); }
void test_index_conflicts__partial(void) { git_index_entry ancestor_entry, our_entry, their_entry; const git_index_entry *conflict_entry[3]; cl_assert(git_index_entrycount(repo_index) == 8); memset(&ancestor_entry, 0x0, sizeof(git_index_entry)); memset(&our_entry, 0x0, sizeof(git_index_entry)); memset(&their_entry, 0x0, sizeof(git_index_entry)); ancestor_entry.path = "test-one.txt"; ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT); git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID); cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, NULL, NULL)); cl_assert(git_index_entrycount(repo_index) == 9); cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, "test-one.txt")); cl_assert_equal_oid(&ancestor_entry.id, &conflict_entry[0]->id); cl_assert(conflict_entry[1] == NULL); cl_assert(conflict_entry[2] == NULL); }
void test_index_tests__add_frombuffer(void) { git_index *index; git_repository *repo; git_index_entry entry; const git_index_entry *returned_entry; git_oid id1; git_blob *blob; const char *content = "hey there\n"; cl_set_cleanup(&cleanup_myrepo, NULL); /* Intialize a new repository */ cl_git_pass(git_repository_init(&repo, "./myrepo", 0)); /* Ensure we're the only guy in the room */ cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); /* Store the expected hash of the file/blob * This has been generated by executing the following * $ echo "hey there" | git hash-object --stdin */ cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* Add the new file to the index */ memset(&entry, 0x0, sizeof(git_index_entry)); entry.mode = GIT_FILEMODE_BLOB; entry.path = "test.txt"; cl_git_pass(git_index_add_frombuffer(index, &entry, content, strlen(content))); /* Wow... it worked! */ cl_assert(git_index_entrycount(index) == 1); returned_entry = git_index_get_byindex(index, 0); /* And the built-in hashing mechanism worked as expected */ cl_assert_equal_oid(&id1, &returned_entry->id); /* And mode is the one asked */ cl_assert_equal_i(GIT_FILEMODE_BLOB, returned_entry->mode); /* Test access by path instead of index */ cl_assert((returned_entry = git_index_get_bypath(index, "test.txt", 0)) != NULL); cl_assert_equal_oid(&id1, &returned_entry->id); /* Test the blob is in the repository */ cl_git_pass(git_blob_lookup(&blob, repo, &id1)); cl_assert_equal_s( content, git_blob_rawcontent(blob)); git_blob_free(blob); git_index_free(index); git_repository_free(repo); }
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 test_index_tests__reload_from_disk(void) { git_repository *repo; git_index *read_index; git_index *write_index; cl_set_cleanup(&cleanup_myrepo, NULL); cl_git_pass(git_futils_mkdir("./myrepo", NULL, 0777, GIT_MKDIR_PATH)); cl_git_mkfile("./myrepo/a.txt", "a\n"); cl_git_mkfile("./myrepo/b.txt", "b\n"); cl_git_pass(git_repository_init(&repo, "./myrepo", 0)); cl_git_pass(git_repository_index(&write_index, repo)); cl_assert_equal_i(false, write_index->on_disk); cl_git_pass(git_index_open(&read_index, write_index->index_file_path)); cl_assert_equal_i(false, read_index->on_disk); /* Stage two new files against the write_index */ cl_git_pass(git_index_add_bypath(write_index, "a.txt")); cl_git_pass(git_index_add_bypath(write_index, "b.txt")); cl_assert_equal_sz(2, git_index_entrycount(write_index)); /* Persist the index changes to disk */ cl_git_pass(git_index_write(write_index)); cl_assert_equal_i(true, write_index->on_disk); /* Sync the changes back into the read_index */ cl_assert_equal_sz(0, git_index_entrycount(read_index)); cl_git_pass(git_index_read(read_index, true)); cl_assert_equal_i(true, read_index->on_disk); cl_assert_equal_sz(2, git_index_entrycount(read_index)); /* Remove the index file from the filesystem */ cl_git_pass(p_unlink(write_index->index_file_path)); /* Sync the changes back into the read_index */ cl_git_pass(git_index_read(read_index, true)); cl_assert_equal_i(false, read_index->on_disk); cl_assert_equal_sz(0, git_index_entrycount(read_index)); git_index_free(read_index); git_index_free(write_index); git_repository_free(repo); }
void test_index_conflicts__add_removes_stage_zero(void) { git_index_entry staged, ancestor_entry, our_entry, their_entry; const git_index_entry *conflict_entry[3]; cl_assert(git_index_entrycount(repo_index) == 8); memset(&staged, 0x0, sizeof(git_index_entry)); memset(&ancestor_entry, 0x0, sizeof(git_index_entry)); memset(&our_entry, 0x0, sizeof(git_index_entry)); memset(&their_entry, 0x0, sizeof(git_index_entry)); staged.path = "test-one.txt"; staged.mode = 0100644; git_oid_fromstr(&staged.id, TEST_STAGED_OID); cl_git_pass(git_index_add(repo_index, &staged)); cl_assert(git_index_entrycount(repo_index) == 9); ancestor_entry.path = "test-one.txt"; ancestor_entry.mode = 0100644; GIT_IDXENTRY_STAGE_SET(&ancestor_entry, 3); git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID); our_entry.path = "test-one.txt"; our_entry.mode = 0100644; GIT_IDXENTRY_STAGE_SET(&our_entry, 1); git_oid_fromstr(&our_entry.id, TEST_OUR_OID); their_entry.path = "test-one.txt"; their_entry.mode = 0100644; GIT_IDXENTRY_STAGE_SET(&their_entry, 2); git_oid_fromstr(&their_entry.id, TEST_THEIR_OID); cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry)); cl_assert(git_index_entrycount(repo_index) == 11); cl_assert_equal_p(NULL, git_index_get_bypath(repo_index, "test-one.txt", 0)); cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, "test-one.txt")); cl_assert_equal_oid(&ancestor_entry.id, &conflict_entry[0]->id); cl_assert_equal_i(1, git_index_entry_stage(conflict_entry[0])); cl_assert_equal_oid(&our_entry.id, &conflict_entry[1]->id); cl_assert_equal_i(2, git_index_entry_stage(conflict_entry[1])); cl_assert_equal_oid(&their_entry.id, &conflict_entry[2]->id); cl_assert_equal_i(3, git_index_entry_stage(conflict_entry[2])); }
/* Test that writing an invalid filename fails */ void test_index_tests__write_invalid_filename(void) { git_repository *repo; git_index *index; git_oid expected; p_mkdir("read_tree", 0700); cl_git_pass(git_repository_init(&repo, "./read_tree", 0)); cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); cl_git_mkfile("./read_tree/.git/hello", NULL); cl_git_pass(git_index_add_bypath(index, ".git/hello")); /* write-tree */ cl_git_fail(git_index_write_tree(&expected, index)); git_index_free(index); git_repository_free(repo); cl_fixture_cleanup("read_tree"); }
void test_index_rename__single_file(void) { git_repository *repo; git_index *index; size_t position; git_oid expected; const git_index_entry *entry; p_mkdir("rename", 0700); cl_git_pass(git_repository_init(&repo, "./rename", 0)); cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); 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_bypath(index, "lame.name.txt")); cl_assert(git_index_entrycount(index) == 1); cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a")); cl_assert(!git_index_find(&position, index, "lame.name.txt")); entry = git_index_get_byindex(index, position); cl_assert_equal_oid(&expected, &entry->id); /* This removes the entry from the index, but not from the object database */ cl_git_pass(git_index_remove(index, "lame.name.txt", 0)); cl_assert(git_index_entrycount(index) == 0); p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt"); cl_git_pass(git_index_add_bypath(index, "fancy.name.txt")); cl_assert(git_index_entrycount(index) == 1); cl_assert(!git_index_find(&position, index, "fancy.name.txt")); entry = git_index_get_byindex(index, position); cl_assert_equal_oid(&expected, &entry->id); git_index_free(index); git_repository_free(repo); cl_fixture_cleanup("rename"); }
static bool try_create_file_with_nsec_timestamp(const char *path) { struct stat st; int try; /* retry a few times to avoid nanos *actually* equal 0 race condition */ for (try = 0; try < 3; try++) { cl_git_mkfile(path, "This is hopefully a file with nanoseconds!"); cl_must_pass(p_stat(path, &st)); if (st.st_ctime_nsec && st.st_mtime_nsec) return true; } return false; } /* try to determine if the underlying filesystem supports a resolution * higher than a single second. (i'm looking at you, hfs+) */ static bool should_expect_nsecs(void) { git_buf nsec_path = GIT_BUF_INIT; bool expect; git_buf_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test"); expect = try_create_file_with_nsec_timestamp(nsec_path.ptr); p_unlink(nsec_path.ptr); git_buf_clear(&nsec_path); return expect; } static bool has_nsecs(void) { const git_index_entry *entry; size_t i; bool has_nsecs = false; for (i = 0; i < git_index_entrycount(repo_index); i++) { entry = git_index_get_byindex(repo_index, i); if (entry->ctime.nanoseconds || entry->mtime.nanoseconds) { has_nsecs = true; break; } } return has_nsecs; } void test_index_nsec__has_nanos(void) { cl_assert_equal_b(true, has_nsecs()); }
void test_index_read_index__maintains_stat_cache(void) { git_index *new_index; git_oid index_id; git_index_entry new_entry; const git_index_entry *e; git_tree *tree; size_t i; cl_assert_equal_i(4, git_index_entrycount(_index)); /* write-tree */ cl_git_pass(git_index_write_tree(&index_id, _index)); /* read-tree, then read index */ git_tree_lookup(&tree, _repo, &index_id); cl_git_pass(git_index_new(&new_index)); cl_git_pass(git_index_read_tree(new_index, tree)); git_tree_free(tree); /* add a new entry that will not have stat data */ memset(&new_entry, 0, sizeof(git_index_entry)); new_entry.path = "Hello"; git_oid_fromstr(&new_entry.id, "0123456789012345678901234567890123456789"); new_entry.file_size = 1234; new_entry.mode = 0100644; cl_git_pass(git_index_add(new_index, &new_entry)); cl_assert_equal_i(5, git_index_entrycount(new_index)); cl_git_pass(git_index_read_index(_index, new_index)); git_index_free(new_index); cl_assert_equal_i(5, git_index_entrycount(_index)); for (i = 0; i < git_index_entrycount(_index); i++) { e = git_index_get_byindex(_index, i); if (strcmp(e->path, "Hello") == 0) { cl_assert_equal_i(0, e->ctime.seconds); cl_assert_equal_i(0, e->mtime.seconds); } else { cl_assert(0 != e->ctime.seconds); cl_assert(0 != e->mtime.seconds); } } }
void test_index_tests__add(void) { git_index *index; git_filebuf file = GIT_FILEBUF_INIT; git_repository *repo; const git_index_entry *entry; git_oid id1; cl_set_cleanup(&cleanup_myrepo, NULL); /* Intialize a new repository */ cl_git_pass(git_repository_init(&repo, "./myrepo", 0)); /* Ensure we're the only guy in the room */ cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); /* Create a new file in the working directory */ cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777)); cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0, 0666)); cl_git_pass(git_filebuf_write(&file, "hey there\n", 10)); cl_git_pass(git_filebuf_commit(&file)); /* Store the expected hash of the file/blob * This has been generated by executing the following * $ echo "hey there" | git hash-object --stdin */ cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* Add the new file to the index */ cl_git_pass(git_index_add_bypath(index, "test.txt")); /* Wow... it worked! */ cl_assert(git_index_entrycount(index) == 1); entry = git_index_get_byindex(index, 0); /* And the built-in hashing mechanism worked as expected */ cl_assert_equal_oid(&id1, &entry->id); /* Test access by path instead of index */ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL); cl_assert_equal_oid(&id1, &entry->id); git_index_free(index); git_repository_free(repo); }
int CGitIndexList::ReadIndex(CString dgitdir) { this->clear(); m_critRepoSec.Lock(); if (repository.Open(dgitdir)) { m_critRepoSec.Unlock(); return -1; } // add config files CAutoConfig config(true); CString projectConfig = dgitdir + _T("config"); CString globalConfig = g_Git.GetGitGlobalConfig(); CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig(); CString systemConfig(CRegString(REG_SYSTEM_GITCONFIGPATH, _T(""), FALSE)); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(projectConfig), GIT_CONFIG_LEVEL_LOCAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(globalConfig), GIT_CONFIG_LEVEL_GLOBAL, FALSE); git_config_add_file_ondisk(config, CGit::GetGitPathStringA(globalXDGConfig), GIT_CONFIG_LEVEL_XDG, FALSE); if (!systemConfig.IsEmpty()) git_config_add_file_ondisk(config, CGit::GetGitPathStringA(systemConfig), GIT_CONFIG_LEVEL_SYSTEM, FALSE); git_repository_set_config(repository, config); CAutoIndex index; // load index in order to enumerate files if (git_repository_index(index.GetPointer(), repository)) { repository.Free(); m_critRepoSec.Unlock(); return -1; } size_t ecount = git_index_entrycount(index); resize(ecount); for (size_t i = 0; i < ecount; ++i) { const git_index_entry *e = git_index_get_byindex(index, i); this->at(i).m_FileName.Empty(); this->at(i).m_FileName = CUnicodeUtils::GetUnicode(e->path); this->at(i).m_FileName.MakeLower(); this->at(i).m_ModifyTime = e->mtime.seconds; this->at(i).m_Flags = e->flags | e->flags_extended; this->at(i).m_IndexHash = e->id.id; this->at(i).m_Size = e->file_size; } g_Git.GetFileModifyTime(dgitdir + _T("index"), &this->m_LastModifyTime); std::sort(this->begin(), this->end(), SortIndex); m_critRepoSec.Unlock(); return 0; }
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_inmemory__can_create_an_inmemory_index(void) { git_index *index; cl_git_pass(git_index_new(&index)); cl_assert_equal_i(0, (int)git_index_entrycount(index)); git_index_free(index); }
int cmd_ls_files(git_repository *repo, int argc, char **argv) { int i; int rc = EXIT_FAILURE; int show_cached = 1; int err = 0; char *file = NULL; char buf[GIT_OID_HEXSZ+1]; git_index *idx = NULL; for (i=1;i<argc;i++) { if (strcmp(argv[i], "--stage") == 0 || strcmp(argv[i], "-s") == 0) show_cached = 0; else if (strcmp(argv[i], "--cached") == 0 || strcmp(argv[i], "-c") == 0) show_cached = 1; else if (argv[i][0] == '-') { fprintf(stderr,"Unknown option %s!\n",argv[i]); goto out; } else { file = argv[i]; } } if (!file) file = "*"; if ((err = git_repository_index(&idx, repo)) != GIT_OK) goto out; const char *prefix = ""; size_t prefix_len = strlen(prefix); for (unsigned i = 0; i < git_index_entrycount(idx); i++) { const git_index_entry *gie = git_index_get_byindex(idx, i); if (prefixcmp(gie->path, prefix)) continue; if (pathspeccmp(gie->path,file)) continue; if (!show_cached) printf("%06o %s %i\t", gie->mode, git_oid_tostr(buf, GIT_OID_HEXSZ+1, &gie->id), git_index_entry_stage(gie)); write_name_quoted(gie->path + prefix_len, stdout, '\n'); } rc = EXIT_SUCCESS; out: if (err) libgit_error(); if (idx) git_index_free(idx); return rc; }
int git_tree_create_fromindex(git_oid *oid, git_index *index) { int error; if (index->repository == NULL) return GIT_EBAREINDEX; error = write_index(oid, index, "", 0, 0, git_index_entrycount(index)); return (error < GIT_SUCCESS) ? error : GIT_SUCCESS; }
ERL_NIF_TERM geef_index_count(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { geef_index *index; if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index)) return enif_make_badarg(env); return enif_make_uint(env, git_index_entrycount(index->index)); }
static void add_invalid_filename(git_repository *repo, const char *fn) { git_index *index; git_buf path = GIT_BUF_INIT; cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); git_buf_joinpath(&path, "./invalid", fn); cl_git_mkfile(path.ptr, NULL); cl_git_fail(git_index_add_bypath(index, fn)); cl_must_pass(p_unlink(path.ptr)); cl_assert(git_index_entrycount(index) == 0); git_buf_free(&path); git_index_free(index); }
/** * ggit_index_entries_size: * @entries: a #GgitIndexEntries. * * Get the number of #GgitIndexEntry entries. * * Returns: the number of entries. * **/ guint ggit_index_entries_size (GgitIndexEntries *entries) { git_index *gidx; g_return_val_if_fail (entries != NULL, 0); gidx = _ggit_index_get_index (entries->owner); return git_index_entrycount (gidx); }
void test_index_conflicts__remove_all_conflicts(void) { size_t i; const git_index_entry *entry; cl_assert(git_index_entrycount(repo_index) == 8); cl_assert_equal_i(true, git_index_has_conflicts(repo_index)); git_index_conflict_cleanup(repo_index); cl_assert_equal_i(false, git_index_has_conflicts(repo_index)); cl_assert(git_index_entrycount(repo_index) == 2); for (i = 0; i < git_index_entrycount(repo_index); i++) { cl_assert(entry = git_index_get_byindex(repo_index, i)); cl_assert(git_index_entry_stage(entry) == 0); } }
void test_index_conflicts__moved_to_reuc_on_add(void) { const git_index_entry *entry; size_t i; cl_assert(git_index_entrycount(repo_index) == 8); cl_git_mkfile("./mergedrepo/conflicts-one.txt", "new-file\n"); cl_git_pass(git_index_add_bypath(repo_index, "conflicts-one.txt")); cl_assert(git_index_entrycount(repo_index) == 6); for (i = 0; i < git_index_entrycount(repo_index); i++) { cl_assert(entry = git_index_get_byindex(repo_index, i)); if (strcmp(entry->path, "conflicts-one.txt") == 0) cl_assert(git_index_entry_stage(entry) == 0); } }
void test_index_tests__preserves_case(void) { git_repository *repo; git_index *index; const git_index_entry *entry; int index_caps; cl_set_cleanup(&cleanup_myrepo, NULL); cl_git_pass(git_repository_init(&repo, "./myrepo", 0)); cl_git_pass(git_repository_index(&index, repo)); index_caps = git_index_caps(index); cl_git_rewritefile("myrepo/test.txt", "hey there\n"); cl_git_pass(git_index_add_bypath(index, "test.txt")); cl_git_pass(p_rename("myrepo/test.txt", "myrepo/TEST.txt")); cl_git_rewritefile("myrepo/TEST.txt", "hello again\n"); cl_git_pass(git_index_add_bypath(index, "TEST.txt")); if (index_caps & GIT_INDEXCAP_IGNORE_CASE) cl_assert_equal_i(1, (int)git_index_entrycount(index)); else cl_assert_equal_i(2, (int)git_index_entrycount(index)); /* Test access by path instead of index */ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL); /* The path should *not* have changed without an explicit remove */ cl_assert(git__strcmp(entry->path, "test.txt") == 0); cl_assert((entry = git_index_get_bypath(index, "TEST.txt", 0)) != NULL); if (index_caps & GIT_INDEXCAP_IGNORE_CASE) /* The path should *not* have changed without an explicit remove */ cl_assert(git__strcmp(entry->path, "test.txt") == 0); else cl_assert(git__strcmp(entry->path, "TEST.txt") == 0); git_index_free(index); git_repository_free(repo); }
void test_index_tests__empty_index(void) { git_index *index; cl_git_pass(git_index_open(&index, "in-memory-index")); cl_assert(index->on_disk == 0); cl_assert(git_index_entrycount(index) == 0); cl_assert(index->entries.sorted); git_index_free(index); }
void test_index_tests__gitgit_index(void) { git_index *index; cl_git_pass(git_index_open(&index, TEST_INDEX2_PATH)); cl_assert(index->on_disk); cl_assert(git_index_entrycount(index) == (unsigned int)index_entry_count_2); cl_assert(index->entries.sorted); cl_assert(index->tree != NULL); git_index_free(index); }
void test_index_tests__gitgit_index(void) { git_index *index; cl_git_pass(git_index_open(&index, TEST_INDEX2_PATH)); cl_assert(index->on_disk); cl_assert(git_index_entrycount(index) == index_entry_count_2); cl_assert(git_vector_is_sorted(&index->entries)); cl_assert(index->tree != NULL); git_index_free(index); }
int main (int argc, char** argv) { git_repository *repo; git_index *index; unsigned int i, ecount; char *dir = "."; char out[41]; out[40] = '\0'; if (argc > 1) dir = argv[1]; if (argc > 2) { fprintf(stderr, "usage: showindex [<repo-dir>]\n"); return 1; } if (git_repository_open_ext(&repo, dir, 0, NULL) < 0) { fprintf(stderr, "could not open repository: %s\n", dir); return 1; } git_repository_index(&index, repo); git_index_read(index); ecount = git_index_entrycount(index); if (!ecount) printf("Empty index\n"); for (i = 0; i < ecount; ++i) { const git_index_entry *e = git_index_get_byindex(index, i); git_oid_fmt(out, &e->oid); printf("File Path: %s\n", e->path); printf(" Stage: %d\n", git_index_entry_stage(e)); printf(" Blob SHA: %s\n", out); printf("File Size: %d\n", (int)e->file_size); printf(" Device: %d\n", (int)e->dev); printf(" Inode: %d\n", (int)e->ino); printf(" UID: %d\n", (int)e->uid); printf(" GID: %d\n", (int)e->gid); printf(" ctime: %d\n", (int)e->ctime.seconds); printf(" mtime: %d\n", (int)e->mtime.seconds); printf("\n"); } git_index_free(index); git_repository_free(repo); return 0; }
void test_index_conflicts__remove(void) { const git_index_entry *entry; size_t i; cl_assert(git_index_entrycount(repo_index) == 8); cl_git_pass(git_index_conflict_remove(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); } cl_git_pass(git_index_conflict_remove(repo_index, "conflicts-two.txt")); cl_assert(git_index_entrycount(repo_index) == 2); 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-two.txt") != 0); } }
static size_t merge_trivial_conflict_entrycount(void) { const git_index_entry *entry; size_t count = 0; size_t i; for (i = 0; i < git_index_entrycount(repo_index); i++) { cl_assert(entry = git_index_get_byindex(repo_index, i)); if (git_index_entry_stage(entry) > 0) count++; } return count; }