void test_object_tree_read__two(void) { /* read a tree from the repository */ git_oid id; git_tree *tree; const git_tree_entry *entry; git_object *obj; git_oid_fromstr(&id, tree_oid); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); cl_assert(git_tree_entrycount(tree) == 3); /* GH-86: git_object_lookup() should also check the type if the object comes from the cache */ cl_assert(git_object_lookup(&obj, g_repo, &id, GIT_OBJECT_TREE) == 0); cl_assert(obj != NULL); git_object_free(obj); obj = NULL; cl_git_fail(git_object_lookup(&obj, g_repo, &id, GIT_OBJECT_BLOB)); cl_assert(obj == NULL); entry = git_tree_entry_byname(tree, "README"); cl_assert(entry != NULL); cl_assert_equal_s(git_tree_entry_name(entry), "README"); cl_git_pass(git_tree_entry_to_object(&obj, g_repo, entry)); cl_assert(obj != NULL); git_object_free(obj); git_tree_free(tree); }
void test_checkout_tree__can_continue_when_dir_in_use(void) { #ifdef GIT_WIN32 git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid oid; git_object *obj = NULL; opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_assert(git_path_isfile("testrepo/a/b.txt")); git_object_free(obj); cl_git_pass(p_chdir("testrepo/a")); cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/master")); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(p_chdir("../..")); cl_assert(git_path_is_empty_dir("testrepo/a")); git_object_free(obj); #endif }
static int cb_note__each(const git_oid *blob_id, const git_oid *annotated_object_id, void *data) { VALUE rb_args = rb_ary_new2(2); struct rugged_cb_payload *payload = data; git_object *annotated_object; git_object *note_blob; git_repository *repo; Data_Get_Struct(payload->rb_data, git_repository, repo); rugged_exception_check( git_object_lookup(&annotated_object, repo, annotated_object_id, GIT_OBJ_ANY) ); rugged_exception_check( git_object_lookup(¬e_blob, repo, blob_id, GIT_OBJ_BLOB) ); rb_ary_push(rb_args, rugged_object_new(payload->rb_data, note_blob)); rb_ary_push(rb_args, rugged_object_new(payload->rb_data, annotated_object)); rb_protect(rb_yield_splat, rb_args, &payload->exception); return payload->exception ? GIT_ERROR : GIT_OK; }
void test_checkout_icase__conflicts_with_casechanged_subtrees(void) { git_reference *orig_ref; git_object *orig, *subtrees; git_oid oid; git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_reference_lookup_resolved(&orig_ref, repo, "HEAD", 100)); cl_git_pass(git_object_lookup(&orig, repo, git_reference_target(orig_ref), GIT_OBJ_COMMIT)); cl_git_pass(git_reset(repo, (git_object *)orig, GIT_RESET_HARD, NULL)); cl_must_pass(p_mkdir("testrepo/AB", 0777)); cl_must_pass(p_mkdir("testrepo/AB/C", 0777)); cl_git_write2file("testrepo/AB/C/3.txt", "Foobar!\n", 8, O_RDWR|O_CREAT, 0666); cl_git_pass(git_reference_name_to_id(&oid, repo, "refs/heads/subtrees")); cl_git_pass(git_object_lookup(&subtrees, repo, &oid, GIT_OBJ_ANY)); cl_git_fail(git_checkout_tree(repo, subtrees, &checkout_opts)); git_object_free(orig); git_object_free(subtrees); git_reference_free(orig_ref); }
static int retrieve_revobject_from_reflog(git_object **out, git_reference **base_ref, git_repository *repo, const char *identifier, size_t position) { git_reference *ref; git_oid oid; int error = -1; if (*base_ref == NULL) { if ((error = git_reference_dwim(&ref, repo, identifier)) < 0) return error; } else { ref = *base_ref; *base_ref = NULL; } if (position == 0) { error = git_object_lookup(out, repo, git_reference_target(ref), GIT_OBJ_ANY); goto cleanup; } if ((error = retrieve_oid_from_reflog(&oid, ref, position)) < 0) goto cleanup; error = git_object_lookup(out, repo, &oid, GIT_OBJ_ANY); cleanup: git_reference_free(ref); return error; }
void test_checkout_tree__can_switch_branches(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid oid; git_object *obj = NULL; assert_on_branch(g_repo, "master"); /* do first checkout with FORCE because we don't know if testrepo * base data is clean for a checkout or not */ opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir")); cl_assert(git_path_isfile("testrepo/README")); cl_assert(git_path_isfile("testrepo/branch_file.txt")); cl_assert(git_path_isfile("testrepo/new.txt")); cl_assert(git_path_isfile("testrepo/a/b.txt")); cl_assert(!git_path_isdir("testrepo/ab")); assert_on_branch(g_repo, "dir"); git_object_free(obj); /* do second checkout safe because we should be clean after first */ opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/subtrees")); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); cl_assert(git_path_isfile("testrepo/README")); cl_assert(git_path_isfile("testrepo/branch_file.txt")); cl_assert(git_path_isfile("testrepo/new.txt")); cl_assert(git_path_isfile("testrepo/ab/4.txt")); cl_assert(git_path_isfile("testrepo/ab/c/3.txt")); cl_assert(git_path_isfile("testrepo/ab/de/2.txt")); cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt")); cl_assert(!git_path_isdir("testrepo/a")); assert_on_branch(g_repo, "subtrees"); git_object_free(obj); }
void test_object_cache__cache_everything(void) { int i, start; git_oid oid; git_odb_object *odb_obj; git_object *obj; git_odb *odb; git_libgit2_opts( GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJ_BLOB, (size_t)32767); cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git"))); cl_git_pass(git_repository_odb(&odb, g_repo)); start = (int)git_cache_size(&g_repo->objects); for (i = 0; g_data[i].sha != NULL; ++i) { int count = (int)git_cache_size(&g_repo->objects); cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); /* alternate between loading raw and parsed objects */ if ((i & 1) == 0) { cl_git_pass(git_odb_read(&odb_obj, odb, &oid)); cl_assert(g_data[i].type == git_odb_object_type(odb_obj)); git_odb_object_free(odb_obj); } else { cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); } cl_assert_equal_i(count + 1, (int)git_cache_size(&g_repo->objects)); } cl_assert_equal_i(i, (int)git_cache_size(&g_repo->objects) - start); git_odb_free(odb); for (i = 0; g_data[i].sha != NULL; ++i) { int count = (int)git_cache_size(&g_repo->objects); cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); cl_assert_equal_i(count, (int)git_cache_size(&g_repo->objects)); } }
void test_object_blob_fromchunks__can_create_a_blob_from_a_in_memory_chunk_provider(void) { git_oid expected_oid, oid; git_object *blob; int howmany = 7; cl_git_pass(git_oid_fromstr(&expected_oid, "321cbdf08803c744082332332838df6bd160f8f9")); cl_git_fail(git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY)); cl_git_pass(git_blob_create_fromchunks(&oid, repo, NULL, text_chunked_source_cb, &howmany)); cl_git_pass(git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY)); git_object_free(blob); }
void test_refs_read__loose_tag(void) { // lookup a loose tag reference git_reference *reference; git_object *object; git_buf ref_name_from_tag_name = GIT_BUF_INIT; cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name)); cl_assert(git_reference_type(reference) & GIT_REF_OID); cl_assert(git_reference_is_packed(reference) == 0); cl_assert_equal_s(reference->name, loose_tag_ref_name); cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(reference), GIT_OBJ_ANY)); cl_assert(object != NULL); cl_assert(git_object_type(object) == GIT_OBJ_TAG); /* Ensure the name of the tag matches the name of the reference */ cl_git_pass(git_buf_joinpath(&ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object))); cl_assert_equal_s(ref_name_from_tag_name.ptr, loose_tag_ref_name); git_buf_free(&ref_name_from_tag_name); git_object_free(object); git_reference_free(reference); }
void test_checkout_tree__can_not_update_index(void) { git_oid oid; git_object *head; unsigned int status; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_index *index; opts.checkout_strategy |= GIT_CHECKOUT_FORCE | GIT_CHECKOUT_DONT_UPDATE_INDEX; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "HEAD")); cl_git_pass(git_object_lookup(&head, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts)); cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees")); cl_git_pass(git_checkout_tree(g_repo, g_object, &opts)); cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt")); cl_git_pass(git_status_file(&status, g_repo, "ab/de/2.txt")); cl_assert_equal_i(GIT_STATUS_WT_NEW, status); cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_index_write(index)); cl_git_pass(git_status_file(&status, g_repo, "ab/de/2.txt")); cl_assert_equal_i(GIT_STATUS_WT_NEW, status); git_object_free(head); git_index_free(index); }
void test_object_tag_write__lightweight(void) { // write a lightweight tag to the repository and read it again git_oid target_id, object_id; git_reference *ref_tag; git_object *target; git_oid_fromstr(&target_id, tagged_commit); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT)); cl_git_pass(git_tag_create_lightweight( &object_id, g_repo, "light-tag", target, 0)); git_object_free(target); cl_assert(git_oid_cmp(&object_id, &target_id) == 0); cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/light-tag")); cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &target_id) == 0); cl_git_pass(git_tag_delete(g_repo, "light-tag")); git_reference_free(ref_tag); }
/* * The remote is strictly newer than the local branch. */ static int reset_to_remote(git_repository *repo, git_reference *local, const git_oid *new_id) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_object *target; // If it's not checked out (bare or not HEAD), just update the reference */ if (git_repository_is_bare(repo) || git_branch_is_head(local) != 1) { git_reference *out; if (git_reference_set_target(&out, local, new_id, "Update to remote")) return report_error("Could not update local ref to newer remote ref"); git_reference_free(out); // Not really an error, just informational report_error("Updated local branch from remote"); return 0; } if (git_object_lookup(&target, repo, new_id, GIT_OBJ_COMMIT)) return report_error("Could not look up remote commit"); opts.checkout_strategy = GIT_CHECKOUT_SAFE; if (git_reset(repo, target, GIT_RESET_HARD, &opts)) return report_error("Local head checkout failed after update"); // Not really an error, just informational report_error("Updated local information from remote"); return 0; }
/* Emulate checking out in a repo created by clone --no-checkout, * which would not have written an index. */ void test_checkout_tree__safe_proceeds_if_no_index(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid oid; git_object *obj = NULL; assert_on_branch(g_repo, "master"); cl_must_pass(p_unlink("testrepo/.git/index")); /* do second checkout safe because we should be clean after first */ opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/subtrees")); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); cl_assert(git_path_isfile("testrepo/README")); cl_assert(git_path_isfile("testrepo/branch_file.txt")); cl_assert(git_path_isfile("testrepo/new.txt")); cl_assert(git_path_isfile("testrepo/ab/4.txt")); cl_assert(git_path_isfile("testrepo/ab/c/3.txt")); cl_assert(git_path_isfile("testrepo/ab/de/2.txt")); cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt")); cl_assert(!git_path_isdir("testrepo/a")); assert_on_branch(g_repo, "subtrees"); git_object_free(obj); }
static int create_branch( git_reference **branch, git_repository *repo, const git_oid *target, const char *name) { git_object *head_obj = NULL; git_reference *branch_ref; int error; /* Find the target commit */ if ((error = git_object_lookup(&head_obj, repo, target, GIT_OBJ_ANY)) < 0) return error; /* Create the new branch */ error = git_branch_create(&branch_ref, repo, name, head_obj, 0); git_object_free(head_obj); if (!error) *branch = branch_ref; else git_reference_free(branch_ref); return error; }
static int show_ref(git_reference *ref, void *data) { git_repository *repo = data; git_reference *resolved = NULL; char hex[GIT_OID_HEXSZ+1]; const git_oid *oid; git_object *obj; if (git_reference_type(ref) == GIT_REF_SYMBOLIC) check_lg2(git_reference_resolve(&resolved, ref), "Unable to resolve symbolic reference", git_reference_name(ref)); oid = git_reference_target(resolved ? resolved : ref); git_oid_fmt(hex, oid); hex[GIT_OID_HEXSZ] = 0; check_lg2(git_object_lookup(&obj, repo, oid, GIT_OBJ_ANY), "Unable to lookup object", hex); printf("%s %-6s\t%s\n", hex, git_object_type2string(git_object_type(obj)), git_reference_name(ref)); if (resolved) git_reference_free(resolved); return 0; }
void test_refs_read__nested_symbolic(void) { // lookup a nested symbolic reference git_reference *reference, *resolved_ref; git_object *object; git_oid id; cl_git_pass(git_reference_lookup(&reference, g_repo, head_tracker_sym_ref_name)); cl_assert(git_reference_type(reference) & GIT_REF_SYMBOLIC); cl_assert(git_reference_is_packed(reference) == 0); cl_assert_equal_s(reference->name, head_tracker_sym_ref_name); cl_git_pass(git_reference_resolve(&resolved_ref, reference)); cl_assert(git_reference_type(resolved_ref) == GIT_REF_OID); cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(resolved_ref), GIT_OBJ_ANY)); cl_assert(object != NULL); cl_assert(git_object_type(object) == GIT_OBJ_COMMIT); git_oid_fromstr(&id, current_master_tip); cl_assert(git_oid_cmp(&id, git_object_id(object)) == 0); git_object_free(object); git_reference_free(reference); git_reference_free(resolved_ref); }
static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex) { int error; git_oid oid; git_object *obj; while (!(error = git_revwalk_next(&oid, walk))) { error = git_object_lookup(&obj, git_revwalk_repository(walk), &oid, GIT_OBJ_COMMIT); if ((error < 0) && (error != GIT_ENOTFOUND)) return -1; if (!regexec(regex, git_commit_message((git_commit*)obj), 0, NULL, 0)) { *out = obj; return 0; } git_object_free(obj); } if (error < 0 && error == GIT_ITEROVER) error = GIT_ENOTFOUND; return error; }
static int revparse_lookup_object(git_object **out, git_repository *repo, const char *spec) { int error; git_reference *ref; error = maybe_describe(out, repo, spec); if (!error) return 0; if (error < 0 && error != GIT_ENOTFOUND) return error; error = disambiguate_refname(&ref, repo, spec); if (!error) { error = git_object_lookup(out, repo, git_reference_oid(ref), GIT_OBJ_ANY); git_reference_free(ref); return error; } if (error < 0 && error != GIT_ENOTFOUND) return error; error = maybe_sha_or_abbrev(out, repo, spec); if (!error) return 0; if (error < 0 && error != GIT_ENOTFOUND) return error; giterr_set(GITERR_REFERENCE, "Refspec '%s' not found.", spec); return GIT_ENOTFOUND; }
void test_object_tag_write__overwrite(void) { // Attempt to write a tag bearing the same name than an already existing tag git_oid target_id, tag_id; git_signature *tagger; git_object *target; git_oid_fromstr(&target_id, tagged_commit); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT)); /* create signature */ cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60)); cl_assert_equal_i(GIT_EEXISTS, git_tag_create( &tag_id, /* out id */ g_repo, "e90810b", target, tagger, tagger_message, 0)); git_object_free(target); git_signature_free(tagger); }
/* * call-seq: * tag.target -> git_object */ static VALUE rb_git_tag_target(VALUE self) { git_reference *ref, *resolved_ref; git_repository *repo; git_object *target; int error; VALUE rb_repo = rugged_owner(self); rugged_check_repo(rb_repo); Data_Get_Struct(self, git_reference, ref); Data_Get_Struct(rb_repo, git_repository, repo); error = git_reference_resolve(&resolved_ref, ref); rugged_exception_check(error); error = git_object_lookup(&target, repo, git_reference_target(resolved_ref), GIT_OBJ_ANY); git_reference_free(resolved_ref); rugged_exception_check(error); if (git_object_type(target) == GIT_OBJ_TAG) { git_object *annotation_target; error = git_tag_target(&annotation_target, (git_tag *)target); git_object_free(target); rugged_exception_check(error); return rugged_object_new(rb_repo, annotation_target); } else { return rugged_object_new(rb_repo, target); } }
static void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha) { git_oid oid; cl_git_pass(git_oid_fromstr(&oid, sha)); cl_git_pass(git_object_lookup(object_out, repo, &oid, GIT_OBJ_ANY)); }
static void assert_workdir_matches_tree( git_repository *repo, const git_oid *id, const char *root, bool recurse) { git_object *obj; git_tree *tree; size_t i, max_i; git_buf path = GIT_BUF_INIT; if (!root) root = git_repository_workdir(repo); cl_assert(root); cl_git_pass(git_object_lookup(&obj, repo, id, GIT_OBJ_ANY)); cl_git_pass(git_object_peel((git_object **)&tree, obj, GIT_OBJ_TREE)); git_object_free(obj); max_i = git_tree_entrycount(tree); for (i = 0; i < max_i; ++i) { const git_tree_entry *te = git_tree_entry_byindex(tree, i); cl_assert(te); cl_git_pass(git_buf_joinpath(&path, root, git_tree_entry_name(te))); switch (git_tree_entry_type(te)) { case GIT_OBJ_COMMIT: assert_dir_exists(path.ptr); break; case GIT_OBJ_TREE: assert_dir_exists(path.ptr); if (recurse) assert_workdir_matches_tree( repo, git_tree_entry_id(te), path.ptr, true); break; case GIT_OBJ_BLOB: switch (git_tree_entry_filemode(te)) { case GIT_FILEMODE_BLOB: case GIT_FILEMODE_BLOB_EXECUTABLE: assert_file_exists(path.ptr); /* because of cross-platform, don't confirm exec bit yet */ break; case GIT_FILEMODE_LINK: cl_assert_(git_path_exists(path.ptr), path.ptr); /* because of cross-platform, don't confirm link yet */ break; default: cl_assert(false); /* really?! */ } break; default: cl_assert(false); /* really?!! */ } } git_tree_free(tree); git_buf_free(&path); }
int git_reference_peel( git_object **peeled, git_reference *ref, git_otype target_type) { git_reference *resolved = NULL; git_object *target = NULL; int error; assert(ref); if (ref->type == GIT_REF_OID) { resolved = ref; } else { if ((error = git_reference_resolve(&resolved, ref)) < 0) return peel_error(error, ref, "Cannot resolve reference"); } if (!git_oid_iszero(&resolved->peel)) { error = git_object_lookup(&target, git_reference_owner(ref), &resolved->peel, GIT_OBJ_ANY); } else { error = git_object_lookup(&target, git_reference_owner(ref), &resolved->target.oid, GIT_OBJ_ANY); } if (error < 0) { peel_error(error, ref, "Cannot retrieve reference target"); goto cleanup; } if (target_type == GIT_OBJ_ANY && git_object_type(target) != GIT_OBJ_TAG) error = git_object_dup(peeled, target); else error = git_object_peel(peeled, target, target_type); cleanup: git_object_free(target); if (resolved != ref) git_reference_free(resolved); return error; }
void test_object_blob_fromchunks__can_stop_with_error(void) { git_oid expected_oid, oid; git_object *blob; int howmany = 7; cl_git_pass(git_oid_fromstr( &expected_oid, "321cbdf08803c744082332332838df6bd160f8f9")); cl_git_fail_with( git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY), GIT_ENOTFOUND); cl_git_fail_with(git_blob_create_fromchunks( &oid, repo, NULL, failing_chunked_source_cb, &howmany), -1234); cl_git_fail_with( git_object_lookup(&blob, repo, &expected_oid, GIT_OBJ_ANY), GIT_ENOTFOUND); }
static void env_check_objects_(bool a, bool t, bool p, const char *file, int line) { git_repository *repo; git_oid oid_a, oid_t, oid_p; git_object *object; cl_git_pass(git_oid_fromstr(&oid_a, "45141a79a77842c59a63229403220a4e4be74e3d")); cl_git_pass(git_oid_fromstr(&oid_t, "1385f264afb75a56a5bec74243be9b367ba4ca08")); cl_git_pass(git_oid_fromstr(&oid_p, "0df1a5865c8abfc09f1f2182e6a31be550e99f07")); cl_git_expect(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, line); if (a) { cl_git_expect(git_object_lookup(&object, repo, &oid_a, GIT_OBJ_BLOB), 0, file, line); git_object_free(object); } else { cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_a, GIT_OBJ_BLOB), file, line); } if (t) { cl_git_expect(git_object_lookup(&object, repo, &oid_t, GIT_OBJ_BLOB), 0, file, line); git_object_free(object); } else { cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_t, GIT_OBJ_BLOB), file, line); } if (p) { cl_git_expect(git_object_lookup(&object, repo, &oid_p, GIT_OBJ_COMMIT), 0, file, line); git_object_free(object); } else { cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_p, GIT_OBJ_COMMIT), file, line); } git_repository_free(repo); }
static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting, int from_glob) { git_oid commit_id; int error; git_object *obj, *oobj; git_commit_list_node *commit; git_commit_list *list; if ((error = git_object_lookup(&oobj, walk->repo, oid, GIT_OBJ_ANY)) < 0) return error; error = git_object_peel(&obj, oobj, GIT_OBJ_COMMIT); git_object_free(oobj); if (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL) { /* If this comes from e.g. push_glob("tags"), ignore this */ if (from_glob) return 0; giterr_set(GITERR_INVALID, "Object is not a committish"); return -1; } if (error < 0) return error; git_oid_cpy(&commit_id, git_object_id(obj)); git_object_free(obj); commit = git_revwalk__commit_lookup(walk, &commit_id); if (commit == NULL) return -1; /* error already reported by failed lookup */ /* A previous hide already told us we don't want this commit */ if (commit->uninteresting) return 0; if (uninteresting) walk->did_hide = 1; else walk->did_push = 1; commit->uninteresting = uninteresting; list = walk->user_input; if (git_commit_list_insert(commit, &list) == NULL) { giterr_set_oom(); return -1; } walk->user_input = list; return 0; }
static void assert_peel_error(int error, const char *sha, git_otype requested_type) { git_oid oid; git_object *obj; git_object *peeled; cl_git_pass(git_oid_fromstr(&oid, sha)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert_equal_i(error, git_object_peel(&peeled, obj, requested_type)); git_object_free(obj); }
static void *cache_parsed(void *arg) { int i; git_oid oid; git_object *obj; for (i = ((int *)arg)[1]; g_data[i].sha != NULL; i += 2) { cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); } for (i = 0; i < ((int *)arg)[1]; i += 2) { cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); } return arg; }
static int object_from_reference(git_object **object, git_reference *reference) { git_reference *resolved = NULL; int error; if (git_reference_resolve(&resolved, reference) < 0) return -1; error = git_object_lookup(object, reference->db->repo, git_reference_target(resolved), GIT_OBJ_ANY); git_reference_free(resolved); return error; }
void test_checkout_tree__can_cancel_checkout_from_notify(void) { struct checkout_cancel_at ca; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid oid; git_object *obj = NULL; assert_on_branch(g_repo, "master"); cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); ca.filename = "new.txt"; ca.error = -5555; ca.count = 0; opts.notify_flags = GIT_CHECKOUT_NOTIFY_UPDATED; opts.notify_cb = checkout_cancel_cb; opts.notify_payload = &ca; opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_assert(!git_path_exists("testrepo/new.txt")); cl_git_fail_with(git_checkout_tree(g_repo, obj, &opts), -5555); cl_assert(!git_path_exists("testrepo/new.txt")); /* on case-insensitive FS = a/b.txt, branch_file.txt, new.txt */ /* on case-sensitive FS = README, then above */ if (git_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */ cl_assert_equal_i(3, ca.count); else cl_assert_equal_i(4, ca.count); /* and again with a different stopping point and return code */ ca.filename = "README"; ca.error = 123; ca.count = 0; cl_git_fail_with(git_checkout_tree(g_repo, obj, &opts), 123); cl_assert(!git_path_exists("testrepo/new.txt")); if (git_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */ cl_assert_equal_i(4, ca.count); else cl_assert_equal_i(1, ca.count); git_object_free(obj); }