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_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])); }
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 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; }
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; }
int cmd_ls_files(int argc, const char **argv) { /* Delete the following line once git tests pass */ please_git_do_it_for_me(); int show_cached = 1; /* options parsing */ if (argc > 1) { if (argc > 2) please_git_do_it_for_me(); if (strcmp(argv[1], "--stage") == 0 || strcmp(argv[1], "-s") == 0) show_cached = 0; else if (strcmp(argv[1], "--cached") == 0 || strcmp(argv[1], "-c") == 0) show_cached = 1; else please_git_do_it_for_me(); } git_repository *repo = get_git_repository(); git_index *index_cur; int e = git_repository_index(&index_cur, repo); if (e) libgit_error(); char buf[GIT_OID_HEXSZ+1]; const char *prefix = get_git_prefix(); size_t prefix_len = strlen(prefix); for (unsigned i = 0; i < git_index_entrycount(index_cur); i++) { git_index_entry *gie = git_index_get(index_cur, i); if (prefixcmp(gie->path, prefix)) continue; if (!show_cached) printf("%06o %s %i\t", gie->mode, git_oid_tostr(buf, GIT_OID_HEXSZ+1, &gie->oid), git_index_entry_stage(gie)); write_name_quoted(gie->path + prefix_len, stdout, '\n'); } git_index_free(index_cur); return EXIT_SUCCESS; }
void merge__dump_index_entries(git_vector *index_entries) { size_t i; const git_index_entry *index_entry; printf ("\nINDEX [%d]:\n", (int)index_entries->length); for (i = 0; i < index_entries->length; i++) { index_entry = index_entries->contents[i]; printf("%o ", index_entry->mode); printf("%s ", git_oid_allocfmt(&index_entry->oid)); printf("%d ", git_index_entry_stage(index_entry)); printf("%s ", index_entry->path); printf("\n"); } printf("\n"); }
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); } }
static int index_entry_eq_merge_index_entry(const struct merge_index_entry *expected, const git_index_entry *actual) { git_oid expected_oid; bool test_oid; if (strlen(expected->oid_str) != 0) { cl_git_pass(git_oid_fromstr(&expected_oid, expected->oid_str)); test_oid = 1; } else test_oid = 0; if (actual->mode != expected->mode || (test_oid && git_oid_cmp(&actual->oid, &expected_oid) != 0) || git_index_entry_stage(actual) != expected->stage) return 0; if (actual->mode == 0 && (actual->path != NULL || strlen(expected->path) > 0)) return 0; if (actual->mode != 0 && (strcmp(actual->path, expected->path) != 0)) return 0; return 1; }
int IndexEntry::stage() const { return git_index_entry_stage(constData()); }