bool git_signature__equal(const git_signature *one, const git_signature *two) { assert(one && two); return git__strcmp(one->name, two->name) == 0 && git__strcmp(one->email, two->email) == 0 && one->when.time == two->when.time && one->when.offset == two->when.offset; }
void test_object_blob_fromchunks__doesnot_overwrite_an_already_existing_object(void) { git_buf path = GIT_BUF_INIT; git_buf content = GIT_BUF_INIT; git_oid expected_oid, oid; int howmany = 7; cl_git_pass(git_oid_fromstr(&expected_oid, "321cbdf08803c744082332332838df6bd160f8f9")); cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany)); /* Let's replace the content of the blob file storage with something else... */ cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/32/1cbdf08803c744082332332838df6bd160f8f9")); cl_git_pass(p_unlink(git_buf_cstr(&path))); cl_git_mkfile(git_buf_cstr(&path), "boom"); /* ...request a creation of the same blob... */ howmany = 7; cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany)); /* ...and ensure the content of the faked blob file hasn't been altered */ cl_git_pass(git_futils_readbuffer(&content, git_buf_cstr(&path))); cl_assert(!git__strcmp("boom", git_buf_cstr(&content))); git_buf_free(&path); git_buf_free(&content); }
static int update_wt_heads(git_repository *repo, const char *path, void *payload) { rename_cb_data *data = (rename_cb_data *) payload; git_reference *head = NULL; char *gitdir = NULL; int error; if ((error = git_reference__read_head(&head, repo, path)) < 0) { giterr_set(GITERR_REFERENCE, "could not read HEAD when renaming references"); goto out; } if ((gitdir = git_path_dirname(path)) == NULL) { error = -1; goto out; } if (git_reference_type(head) != GIT_REF_SYMBOLIC || git__strcmp(head->target.symbolic, data->old_name) != 0) { error = 0; goto out; } /* Update HEAD it was pointing to the reference being renamed */ if ((error = git_repository_create_head(gitdir, data->new_name)) < 0) { giterr_set(GITERR_REFERENCE, "failed to update HEAD after renaming reference"); goto out; } out: git_reference_free(head); git__free(gitdir); return error; }
int git_revparse( git_revspec *revspec, git_repository *repo, const char *spec) { const char *dotdot; int error = 0; assert(revspec && repo && spec); memset(revspec, 0x0, sizeof(*revspec)); if ((dotdot = strstr(spec, "..")) != NULL) { char *lstr; const char *rstr; revspec->flags = GIT_REVPARSE_RANGE; /* * Following git.git, don't allow '..' because it makes command line * arguments which can be either paths or revisions ambiguous when the * path is almost certainly intended. The empty range '...' is still * allowed. */ if (!git__strcmp(spec, "..")) { giterr_set(GITERR_INVALID, "Invalid pattern '..'"); return GIT_EINVALIDSPEC; } lstr = git__substrdup(spec, dotdot - spec); rstr = dotdot + 2; if (dotdot[2] == '.') { revspec->flags |= GIT_REVPARSE_MERGE_BASE; rstr++; } error = git_revparse_single( &revspec->from, repo, *lstr == '\0' ? "HEAD" : lstr); if (!error) { error = git_revparse_single( &revspec->to, repo, *rstr == '\0' ? "HEAD" : rstr); } git__free((void*)lstr); } else { revspec->flags = GIT_REVPARSE_SINGLE; error = git_revparse_single(&revspec->from, repo, spec); } return error; }
void test_core_string__strcmp(void) { cl_assert(git__strcmp("", "") == 0); cl_assert(git__strcmp("foo", "foo") == 0); cl_assert(git__strcmp("Foo", "foo") < 0); cl_assert(git__strcmp("foo", "FOO") > 0); cl_assert(git__strcmp("foo", "fOO") > 0); cl_assert(strcmp("rt\303\202of", "rt dev\302\266h") > 0); cl_assert(strcmp("e\342\202\254ghi=", "et") > 0); cl_assert(strcmp("rt dev\302\266h", "rt\303\202of") < 0); cl_assert(strcmp("et", "e\342\202\254ghi=") < 0); cl_assert(strcmp("\303\215", "\303\255") < 0); cl_assert(git__strcmp("rt\303\202of", "rt dev\302\266h") > 0); cl_assert(git__strcmp("e\342\202\254ghi=", "et") > 0); cl_assert(git__strcmp("rt dev\302\266h", "rt\303\202of") < 0); cl_assert(git__strcmp("et", "e\342\202\254ghi=") < 0); cl_assert(git__strcmp("\303\215", "\303\255") < 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); }
static int fetchhead_ref_write( git_filebuf *file, git_fetchhead_ref *fetchhead_ref) { char oid[GIT_OID_HEXSZ + 1]; const char *type, *name; int head = 0; assert(file && fetchhead_ref); git_oid_fmt(oid, &fetchhead_ref->oid); oid[GIT_OID_HEXSZ] = '\0'; if (git__prefixcmp(fetchhead_ref->ref_name, GIT_REFS_HEADS_DIR) == 0) { type = "branch "; name = fetchhead_ref->ref_name + strlen(GIT_REFS_HEADS_DIR); } else if(git__prefixcmp(fetchhead_ref->ref_name, GIT_REFS_TAGS_DIR) == 0) { type = "tag "; name = fetchhead_ref->ref_name + strlen(GIT_REFS_TAGS_DIR); } else if (!git__strcmp(fetchhead_ref->ref_name, GIT_HEAD_FILE)) { head = 1; } else { type = ""; name = fetchhead_ref->ref_name; } if (head) return git_filebuf_printf(file, "%s\t\t%s\n", oid, fetchhead_ref->remote_url); return git_filebuf_printf(file, "%s\t%s\t%s'%s' of %s\n", oid, (fetchhead_ref->is_merge) ? "" : "not-for-merge", type, name, fetchhead_ref->remote_url); }
void test_index_conflicts__iterate(void) { git_index_conflict_iterator *iterator; const git_index_entry *conflict_entry[3]; git_oid oid; cl_git_pass(git_index_conflict_iterator_new(&iterator, repo_index)); cl_git_pass(git_index_conflict_next(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], iterator)); git_oid_fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); git_oid_fromstr(&oid, CONFLICTS_ONE_OUR_OID); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); git_oid_fromstr(&oid, CONFLICTS_ONE_THEIR_OID); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); cl_git_pass(git_index_conflict_next(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], iterator)); git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); cl_assert(git_index_conflict_next(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], iterator) == GIT_ITEROVER); cl_assert(conflict_entry[0] == NULL); cl_assert(conflict_entry[2] == NULL); cl_assert(conflict_entry[2] == NULL); git_index_conflict_iterator_free(iterator); }