void test_network_remote_defaultbranch__detached_sharing_nonbranch_id(void) { git_oid id, id_cloned; git_reference *ref; git_buf buf = GIT_BUF_INIT; git_repository *cloned_repo; cl_git_pass(git_reference_name_to_id(&id, g_repo_a, "HEAD")); cl_git_pass(git_repository_detach_head(g_repo_a, NULL, NULL)); cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/master")); cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/not-good")); cl_git_pass(git_reference_create(&ref, g_repo_a, "refs/foo/bar", &id, 1, NULL, NULL)); git_reference_free(ref); cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH)); cl_git_fail_with(GIT_ENOTFOUND, git_remote_default_branch(&buf, g_remote)); cl_git_pass(git_clone(&cloned_repo, git_repository_path(g_repo_a), "./local-detached", NULL)); cl_assert(git_repository_head_detached(cloned_repo)); cl_git_pass(git_reference_name_to_id(&id_cloned, g_repo_a, "HEAD")); cl_assert(git_oid_equal(&id, &id_cloned)); git_repository_free(cloned_repo); }
int merge_commits_from_branches( git_index **index, git_repository *repo, const char *ours_name, const char *theirs_name, git_merge_options *opts) { git_commit *our_commit, *their_commit; git_oid our_oid, their_oid; git_buf branch_buf = GIT_BUF_INIT; git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name); cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr)); cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid)); git_buf_clear(&branch_buf); git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name); cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr)); cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid)); cl_git_pass(git_merge_commits(index, repo, our_commit, their_commit, opts)); git_buf_free(&branch_buf); git_commit_free(our_commit); git_commit_free(their_commit); return 0; }
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 }
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); }
static gboolean validate_at_head (struct EvTag *self, git_oid *specified_oid, GError **error) { gboolean ret = FALSE; git_oid head_oid; int r; r = git_reference_name_to_id (&head_oid, self->top_repo, "HEAD"); if (!handle_libgit_ret (r, error)) goto out; /* We have this restriction due to submodules; we require them to be * checked out and initialized. */ if (git_oid_cmp (&head_oid, specified_oid) != 0) { char head_oid_hexstr[GIT_OID_HEXSZ+1]; char specified_oid_hexstr[GIT_OID_HEXSZ+1]; g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Target %s is not HEAD (%s); currently git-evtag can only tag or verify HEAD in a pristine checkout", git_oid_tostr (specified_oid_hexstr, sizeof (specified_oid_hexstr), specified_oid), git_oid_tostr (head_oid_hexstr, sizeof (head_oid_hexstr), &head_oid)); goto out; } ret = TRUE; out: return ret; }
void test_refs_pack__symbolic(void) { /* create a packfile from loose refs skipping symbolic refs */ int i; git_oid head; git_reference *ref; char name[128]; cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD")); /* make a bunch of references */ for (i = 0; i < 100; ++i) { snprintf(name, sizeof(name), "refs/heads/symbolic-%03d", i); cl_git_pass(git_reference_symbolic_create( &ref, g_repo, name, "refs/heads/master", 0, NULL, NULL)); git_reference_free(ref); snprintf(name, sizeof(name), "refs/heads/direct-%03d", i); cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL)); git_reference_free(ref); } packall(); }
static void execute_test(void) { git_oid oid, check; git_commit *commit; git_tree *tree; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/branch1")); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); cl_git_pass(git_commit_tree(&tree, commit)); opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_checkout_tree(g_repo, (git_object *)tree, &opts)); git_tree_free(tree); git_commit_free(commit); /* Verify that the lenna.jpg file was checked out correctly */ cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1")); cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJ_BLOB)); cl_assert(git_oid_equal(&oid, &check)); /* Verify that the text file was checked out correctly */ cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a")); cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJ_BLOB)); cl_assert(git_oid_equal(&oid, &check)); }
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_refs_reflog_messages__creating_a_direct_reference(void) { git_reference *reference; git_oid id; git_reflog *reflog; const git_reflog_entry *entry; const char *name = "refs/heads/new-head"; const char *message = "You've been logged, mate!"; cl_git_pass(git_reference_name_to_id(&id, g_repo, "HEAD")); cl_git_pass(git_reference_create(&reference, g_repo, name, &id, 0, message)); cl_git_pass(git_reflog_read(&reflog, g_repo, name)); cl_assert_equal_sz(1, git_reflog_entrycount(reflog)); entry = git_reflog_entry_byindex(reflog, 0); cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); cl_assert_equal_oid(&id, &entry->oid_cur); cl_assert_equal_s(message, entry->msg); git_reflog_free(reflog); git_reference_free(reference); }
void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_change_the_target_of_the_Head(void) { git_oid oid; char raw_head_oid[GIT_OID_HEXSZ + 1]; cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); git_oid_fmt(raw_head_oid, &oid); raw_head_oid[GIT_OID_HEXSZ] = '\0'; retrieve_target_from_oid(&target, repo, raw_head_oid); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); cl_git_pass(git_oid_streq(&oid, raw_head_oid)); }
void test_checkout_index__options_dir_modes(void) { #ifndef GIT_WIN32 git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; struct stat st; git_oid oid; git_commit *commit; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); reset_index_to_treeish((git_object *)commit); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.dir_mode = 0701; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); cl_git_pass(p_stat("./testrepo/a", &st)); cl_assert_equal_i(st.st_mode & 0777, 0701); /* File-mode test, since we're on the 'dir' branch */ cl_git_pass(p_stat("./testrepo/a/b.txt", &st)); cl_assert_equal_i(st.st_mode & 0777, 0755); git_commit_free(commit); #endif }
static void *create_refs(void *arg) { int *id = arg, i; git_oid head; char name[128]; git_reference *ref[10]; cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD")); for (i = 0; i < 10; ++i) { p_snprintf(name, sizeof(name), "refs/heads/thread-%03d-%02d", *id, i); cl_git_pass(git_reference_create(&ref[i], g_repo, name, &head, 0, NULL)); if (i == 5) { git_refdb *refdb; cl_git_pass(git_repository_refdb(&refdb, g_repo)); cl_git_pass(git_refdb_compress(refdb)); git_refdb_free(refdb); } } for (i = 0; i < 10; ++i) git_reference_free(ref[i]); giterr_clear(); return arg; }
void test_checkout_index__options_dir_modes(void) { #ifndef GIT_WIN32 git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; struct stat st; git_oid oid; git_commit *commit; mode_t um; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); reset_index_to_treeish((git_object *)commit); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.dir_mode = 0701; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); /* umask will influence actual directory creation mode */ (void)p_umask(um = p_umask(022)); cl_git_pass(p_stat("./testrepo/a", &st)); cl_assert_equal_i_fmt(st.st_mode, (GIT_FILEMODE_TREE | 0701) & ~um, "%07o"); /* File-mode test, since we're on the 'dir' branch */ cl_git_pass(p_stat("./testrepo/a/b.txt", &st)); cl_assert_equal_i_fmt(st.st_mode, GIT_FILEMODE_BLOB_EXECUTABLE, "%07o"); git_commit_free(commit); #endif }
void GitRepository::commit(const QString& message) { git_repository* repo = repository(); { git_auto<git_status_list> changes; git_eval(git_status_list_new(&changes, repo, NULL)); if (git_status_list_entrycount(changes) == 0) { return; } } git_auto<git_index> index; git_eval(git_repository_index(&index, repo)); git_oid tree_id; git_eval(git_index_write_tree(&tree_id, index)); git_auto<git_tree> tree; git_eval(git_tree_lookup(&tree, repo, &tree_id)); git_oid parent_id; git_eval(git_reference_name_to_id(&parent_id, repo, "HEAD")); git_auto<git_commit> parent; git_eval(git_commit_lookup(&parent, repo, &parent_id)); git_oid commit_id; git_signature* sig = signature(); git_eval(git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, message.toLocal8Bit(), tree, 1, parent)); }
void test_checkout_index__options_dir_modes(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; struct stat st; git_oid oid; git_commit *commit; mode_t um; if (!cl_is_chmod_supported()) return; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); reset_index_to_treeish((git_object *)commit); opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING; opts.dir_mode = 0701; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); /* umask will influence actual directory creation mode */ (void)p_umask(um = p_umask(022)); cl_git_pass(p_stat("./testrepo/a", &st)); /* Haiku & Hurd use other mode bits, so we must mask them out */ cl_assert_equal_i_fmt(st.st_mode & (S_IFMT | 07777), (GIT_FILEMODE_TREE | 0701) & ~um, "%07o"); /* File-mode test, since we're on the 'dir' branch */ cl_git_pass(p_stat("./testrepo/a/b.txt", &st)); cl_assert_equal_i_fmt(st.st_mode & (S_IFMT | 07777), GIT_FILEMODE_BLOB_EXECUTABLE & ~um, "%07o"); git_commit_free(commit); }
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); }
Commit Commit::FromGitReference(const class Repository &repo, git_reference *ref) { git_oid oid; git_reference_name_to_id(&oid, repo.GetGitPointer(), git_reference_name(ref)); return Commit::FromGitOid(repo, oid); }
void MainWindow::lookupCommits() { if (repo != NULL) { git_oid parent_id; git_commit* commit; //get the head commit ID int error = git_reference_name_to_id(&parent_id, repo, "HEAD"); //get the actual commit object error = git_commit_lookup(&commit, repo, &parent_id); qDebug() << "Head commit = " << git_commit_message(commit); unsigned int count = git_commit_parentcount(commit); qDebug() << "numParents = " << count; commitIDs.clear(); lookupDone = false; walkHistory(commit); } }
/* 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); }
/** * Retrieve parents of the commit under construction * * @param parents The vector of parents to create and populate. * @param n_parents The length of parents vector * @param repository The repository * @return 0 on succes, or error code */ static int git2r_retrieve_parents( git_commit ***parents, size_t *n_parents, git_repository *repository) { int err; git_oid oid; git2r_merge_head_cb_data cb_data = {0, NULL, NULL}; git_repository_state_t state; err = git_repository_head_unborn(repository); if (1 == err) { *n_parents = 0; return GIT_OK; } else if (0 != err) { return err; } state = git_repository_state(repository); if (state == GIT_REPOSITORY_STATE_MERGE) { /* Count number of merge heads */ err = git_repository_mergehead_foreach( repository, git2r_repository_mergehead_foreach_cb, &cb_data); if (GIT_OK != err) return err; } *parents = calloc(cb_data.n + 1, sizeof(git_commit*)); if (!parents) { giterr_set_str(GITERR_NONE, git2r_err_alloc_memory_buffer); return GIT_ERROR; } *n_parents = cb_data.n + 1; err = git_reference_name_to_id(&oid, repository, "HEAD"); if (GIT_OK != err) return err; err = git_commit_lookup(&**parents, repository, &oid); if (GIT_OK != err) return err; if (state == GIT_REPOSITORY_STATE_MERGE) { /* Append merge heads to parents */ cb_data.n = 0; cb_data.repository = repository; cb_data.parents = *parents + 1; err = git_repository_mergehead_foreach( repository, git2r_repository_mergehead_foreach_cb, &cb_data); if (GIT_OK != err) return err; } return GIT_OK; }
void test_refs_lookup__oid(void) { git_oid tag, expected; cl_git_pass(git_reference_name_to_id(&tag, g_repo, "refs/tags/point_to_blob")); cl_git_pass(git_oid_fromstr(&expected, "1385f264afb75a56a5bec74243be9b367ba4ca08")); cl_assert(git_oid_cmp(&tag, &expected) == 0); }
static void assert_reset_soft(bool should_be_detached) { git_oid oid; cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); cl_git_fail(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO)); retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO); cl_assert(git_repository_head_detached(repo) == should_be_detached); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); cl_assert(git_repository_head_detached(repo) == should_be_detached); cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO)); }
static int push_ref(git_revwalk *walk, const char *refname, int hide, int from_glob) { git_oid oid; if (git_reference_name_to_id(&oid, walk->repo, refname) < 0) return -1; return push_commit(walk, &oid, hide, from_glob); }
void retrieve_top_stash_id(git_oid *out) { git_object *top_stash; cl_git_pass(git_revparse_single(&top_stash, repo, "stash@{0}")); cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE)); cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0); }
int merge_trees_from_branches( git_index **index, git_repository *repo, const char *ours_name, const char *theirs_name, git_merge_tree_opts *opts) { git_commit *our_commit, *their_commit, *ancestor_commit = NULL; git_tree *our_tree, *their_tree, *ancestor_tree = NULL; git_oid our_oid, their_oid, ancestor_oid; git_buf branch_buf = GIT_BUF_INIT; int error; git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name); cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr)); cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid)); git_buf_clear(&branch_buf); git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name); cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr)); cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid)); error = git_merge_base(&ancestor_oid, repo, git_commit_id(our_commit), git_commit_id(their_commit)); if (error != GIT_ENOTFOUND) { cl_git_pass(error); cl_git_pass(git_commit_lookup(&ancestor_commit, repo, &ancestor_oid)); cl_git_pass(git_commit_tree(&ancestor_tree, ancestor_commit)); } cl_git_pass(git_commit_tree(&our_tree, our_commit)); cl_git_pass(git_commit_tree(&their_tree, their_commit)); cl_git_pass(git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, opts)); git_buf_free(&branch_buf); git_tree_free(our_tree); git_tree_free(their_tree); git_tree_free(ancestor_tree); git_commit_free(our_commit); git_commit_free(their_commit); git_commit_free(ancestor_commit); return 0; }
bool PmrWorkspace::commitMerge() { // Get the number of merge heads so we can allocate an array for parents MergeheadForeachCallbackData data = { 0, nullptr, nullptr }; git_repository_mergehead_foreach(mGitRepository, mergeheadForeachCallback, &data); size_t parentsCount = data.size+1; auto parents = new git_commit*[parentsCount](); // HEAD is always a parent bool res = false; git_oid parentId; if ( (git_reference_name_to_id(&parentId, mGitRepository, "HEAD") == GIT_OK) && (git_commit_lookup(parents, mGitRepository, &parentId) == GIT_OK)) { res = true; // Populate the list of commit parents if (parentsCount > 1) { data.size = 0; data.repository = mGitRepository; data.parents = &(parents[1]); if (git_repository_mergehead_foreach(mGitRepository, mergeheadForeachCallback, &data) != GIT_OK) { res = false; } } if (res) { std::string message = std::string("Merge branch 'master' of "); if (commit(message.c_str(), parentsCount, const_cast<const git_commit **>(parents))) { git_repository_state_cleanup(mGitRepository); } else { res = false; } } } for (size_t n = 0; n < parentsCount; ++n) { git_commit_free(parents[n]); } delete[] parents; if (!res) { emitGitError(tr("An error occurred while trying to commit the merge.")); } return res; }
void test_refs_read__invalid_name_returns_EINVALIDSPEC(void) { git_reference *reference; git_oid id; cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_lookup(&reference, g_repo, "refs/heads/Inv@{id")); cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_name_to_id(&id, g_repo, "refs/heads/Inv@{id")); }
static int retrieve_tag_reference_oid( git_oid *oid, git_buf *ref_name_out, git_repository *repo, const char *tag_name) { if (git_buf_joinpath(ref_name_out, GIT_REFS_TAGS_DIR, tag_name) < 0) return -1; return git_reference_name_to_id(oid, repo, ref_name_out->ptr); }
void test_refs_reflog_reflog__show_merge_for_merge_commits(void) { git_oid b1_oid; git_oid b2_oid; git_oid merge_commit_oid; git_commit *b1_commit; git_commit *b2_commit; git_signature *s; git_commit *parent_commits[2]; git_tree *tree; git_reflog *log; const git_reflog_entry *entry; cl_git_pass(git_signature_now(&s, "alice", "*****@*****.**")); cl_git_pass(git_reference_name_to_id(&b1_oid, g_repo, "HEAD")); cl_git_pass(git_reference_name_to_id(&b2_oid, g_repo, "refs/heads/test")); cl_git_pass(git_commit_lookup(&b1_commit, g_repo, &b1_oid)); cl_git_pass(git_commit_lookup(&b2_commit, g_repo, &b2_oid)); parent_commits[0] = b1_commit; parent_commits[1] = b2_commit; cl_git_pass(git_commit_tree(&tree, b1_commit)); cl_git_pass(git_commit_create(&merge_commit_oid, g_repo, "HEAD", s, s, NULL, "Merge commit", tree, 2, (const struct git_commit **) parent_commits)); cl_git_pass(git_reflog_read(&log, g_repo, "HEAD")); entry = git_reflog_entry_byindex(log, 0); cl_assert_equal_s(merge_reflog_message, git_reflog_entry_message(entry)); git_reflog_free(log); git_tree_free(tree); git_commit_free(b1_commit); git_commit_free(b2_commit); git_signature_free(s); }
/** * Looks up a reference, ignoring not-found errors. */ static int sync_lookup_soft(git_oid *out, git_repository *repo, const char *name) { int e = git_reference_name_to_id(out, repo, name); if (e == GIT_ENOTFOUND) { giterr_clear(); return 0; } return e; }