示例#1
0
 git_oid Index::write_tree() const
 {
     git_oid res;
     if (git_index_write_tree(&res, index_.get()) < 0)
         throw index_write_tree_error();
     return res;
 }
示例#2
0
void test_index_collision__add(void)
{
	git_index_entry entry;
	git_oid tree_id;
	git_tree *tree;

	memset(&entry, 0, sizeof(entry));
	entry.ctime.seconds = 12346789;
	entry.mtime.seconds = 12346789;
	entry.mode  = 0100644;
	entry.file_size = 0;
	git_oid_cpy(&entry.id, &g_empty_id);

	entry.path = "a/b";
	cl_git_pass(git_index_add(g_index, &entry));

	/* create a tree/blob collision */
	entry.path = "a/b/c";
	cl_git_fail(git_index_add(g_index, &entry));

	cl_git_pass(git_index_write_tree(&tree_id, g_index));
	cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));

	git_tree_free(tree);
}
示例#3
0
文件: collision.c 项目: AChep/libgit2
void test_index_collision__add(void)
{
	git_index *index;
	git_index_entry entry;
	git_oid tree_id;
	git_tree *tree;

	repo = cl_git_sandbox_init("empty_standard_repo");
	cl_git_pass(git_repository_index(&index, repo));

	memset(&entry, 0, sizeof(entry));
	entry.ctime.seconds = 12346789;
	entry.mtime.seconds = 12346789;
	entry.mode  = 0100644;
	entry.file_size = 0;
	git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");

	entry.path = "a/b";
	cl_git_pass(git_index_add(index, &entry));

	/* create a tree/blob collision */
	entry.path = "a/b/c";
	cl_git_fail(git_index_add(index, &entry));

	cl_git_pass(git_index_write_tree(&tree_id, index));
	cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));

	git_tree_free(tree);
	git_index_free(index);
}
示例#4
0
文件: tests.c 项目: lznuaa/libgit2
/* 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");
}
示例#5
0
static int create_initial_commit(git_repository *repo)
{
	git_signature *sign;
	git_index *index;
	git_oid tree_id, commit_id;
	git_tree *tree;
	int rc;

	git_signature_now(&sign, sign_name, sign_email);

	rc = git_repository_index(&index, repo);
	if (rc)
		__debug("could not open repository index");

	rc = git_index_write_tree(&tree_id, index);
	if (rc)
		__debug("unable to write initial tree from index");

	git_index_free(index);

	rc = git_tree_lookup(&tree, repo, &tree_id);
	if (rc)
		__debug("could not look up initial tree");

	rc = git_commit_create_v(&commit_id, repo, "HEAD", sign, sign, NULL, "Initial commit", tree, 0);
	if (rc)
		__debug("could not create the initial commit");

	git_tree_free(tree);
	git_signature_free(sign);

	return rc;
}
示例#6
0
bool PmrWorkspace::commit(const char *pMessage, const size_t &pParentCount,
                          const git_commit **pParents)
{
    // Commit everything that is staged

    git_signature *author = nullptr;
    QByteArray name = PreferencesInterface::preference(PluginName, SettingsPreferencesName, SettingsPreferencesNameDefault).toByteArray();
    QByteArray email = PreferencesInterface::preference(PluginName, SettingsPreferencesEmail, SettingsPreferencesEmailDefault).toByteArray();
    git_index *index = nullptr;
    git_oid treeId;
    git_tree *tree = nullptr;
    git_oid commitId;

    bool res =    (git_signature_now(&author, name.data(), email.data()) != GIT_OK)
               || (git_repository_index(&index, mGitRepository) != GIT_OK)
               || (git_index_write_tree(&treeId, index) != GIT_OK)
               || (git_tree_lookup(&tree, mGitRepository, &treeId) != GIT_OK)
               || (git_commit_create(&commitId, mGitRepository, "HEAD", author,
                                     author, nullptr, pMessage, tree,
                                     pParentCount, pParents) != GIT_OK);

    if (tree != nullptr) {
        git_tree_free(tree);
    }

    if (index != nullptr) {
        git_index_free(index);
    }

    if (author != nullptr) {
        git_signature_free(author);
    }

    return !res;
}
示例#7
0
文件: worktree.c 项目: da-x/gitlib
static void stage_and_commit(git_repository *repo, const char *path)
{
    git_oid tree_oid, commit_oid;
    git_tree *tree;
    git_signature *signature;
    git_index *index;

    cl_git_pass(git_repository_index(&index, repo));
    cl_git_pass(git_index_add_bypath(index, path));
    cl_git_pass(git_index_write(index));

    cl_git_pass(git_index_write_tree(&tree_oid, index));
    git_index_free(index);

    cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));

    cl_git_pass(git_signature_new(&signature, "nulltoken", "*****@*****.**", 1323847743, 60));

    cl_git_pass(git_commit_create_v(
                    &commit_oid,
                    repo,
                    "HEAD",
                    signature,
                    signature,
                    NULL,
                    "Initial commit\n\0",
                    tree,
                    0));

    git_tree_free(tree);
    git_signature_free(signature);
}
示例#8
0
ERL_NIF_TERM
geef_index_write_tree(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	geef_index *index;
	geef_repository *repo;
	ErlNifBinary bin;
	git_oid id;
	int error;

	if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index))
		return enif_make_badarg(env);

	if (argc == 2) {
		if (!enif_get_resource(env, argv[1], geef_repository_type, (void **) &repo))
			return enif_make_badarg(env);

		error = git_index_write_tree_to(&id, index->index, repo->repo);
	} else {
		error = git_index_write_tree(&id, index->index);
	}

	if (error < 0)
		return geef_error(env);

	if (geef_oid_bin(&bin, &id) < 0)
		return geef_oom(env);

	return enif_make_tuple2(env, atoms.ok, enif_make_binary(env, &bin));
}
示例#9
0
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));
}
示例#10
0
文件: stash.c 项目: aep/libgit2
static int build_tree_from_index(git_tree **out, git_index *index)
{
	int error;
	git_oid i_tree_oid;

	if ((error = git_index_write_tree(&i_tree_oid, index)) < 0)
		return -1;

	return git_tree_lookup(out, git_index_owner(index), &i_tree_oid);
}
示例#11
0
文件: read_tree.c 项目: 1336/libgit2
/* Test that reading and writing a tree is a no-op */
void test_index_read_tree__read_write_involution(void)
{
	git_repository *repo;
	git_index *index;
	git_oid tree_oid;
	git_tree *tree;
	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);

	p_mkdir("./read_tree/abc", 0700);

	/* Sort order: '-' < '/' < '_' */
	cl_git_mkfile("./read_tree/abc-d", NULL);
	cl_git_mkfile("./read_tree/abc/d", NULL);
	cl_git_mkfile("./read_tree/abc_d", NULL);

	cl_git_pass(git_index_add_bypath(index, "abc-d"));
	cl_git_pass(git_index_add_bypath(index, "abc_d"));
	cl_git_pass(git_index_add_bypath(index, "abc/d"));

	/* write-tree */
	cl_git_pass(git_index_write_tree(&expected, index));

	/* read-tree */
	git_tree_lookup(&tree, repo, &expected);
	cl_git_pass(git_index_read_tree(index, tree));
	git_tree_free(tree);

	cl_git_pass(git_index_write_tree(&tree_oid, index));
	cl_assert_equal_oid(&expected, &tree_oid);

	git_index_free(index);
	git_repository_free(repo);

	cl_fixture_cleanup("read_tree");
}
示例#12
0
NotesModel::NotesModel(QObject *parent)
    : QAbstractListModel(parent)
{
    m_categories=QStringList(QString("All"));
    m_filter=QString("All");

    QDir notesdir = notesFolder();

    if (!(git_repository_open_ext(
              NULL, notesdir.absolutePath().toUtf8().constData() , GIT_REPOSITORY_OPEN_NO_SEARCH, NULL) == 0)) {
        git_repository *repo = NULL;

        // Init Git Repository if not
        int gerr = git_repository_init(&repo, notesdir.absolutePath().toUtf8().constData(), false);
        if (gerr < 0) {
            const git_error *e = giterr_last();
            qDebug() << "Libgit error : %s\n" << e->message;
            emit error(QString().fromLatin1(e->message));
        }

        //Create Initial Commit
        git_signature *sig;
        git_index *index;
        git_oid tree_id, commit_id;
        git_tree *tree;

        gerr = git_signature_now(&sig, "sparkleNotes", "*****@*****.**");

        gerr = git_repository_index(&index, repo);
        if (!checkGitErr(gerr)) {
            gerr = git_index_write_tree(&tree_id, index);
            if (!checkGitErr(gerr)) {

                git_index_free(index);

                gerr = git_tree_lookup(&tree, repo, &tree_id);
                if (!checkGitErr(gerr)) {

                    gerr = git_commit_create_v(
                                &commit_id, repo, "HEAD", sig, sig,
                                NULL, "Initial commit", tree, 0);
                }
                git_tree_free(tree);
            }
        }
        git_signature_free(sig);
        git_repository_free(repo);

    }

    // Add already existing files in case created outside sparkleNotes
    updateGitStatus();
    QtConcurrent::run(this, &NotesModel::pullMergePush);
}
示例#13
0
void cl_repo_commit_from_index(
	git_oid *out,
	git_repository *repo,
	git_signature *sig,
	git_time_t time,
	const char *msg)
{
	git_index *index;
	git_oid commit_id, tree_id;
	git_object *parent = NULL;
	git_reference *ref = NULL;
	git_tree *tree = NULL;
	char buf[128];
	int free_sig = (sig == NULL);

	/* it is fine if looking up HEAD fails - we make this the first commit */
	git_revparse_ext(&parent, &ref, repo, "HEAD");

	/* write the index content as a tree */
	cl_git_pass(git_repository_index(&index, repo));
	cl_git_pass(git_index_write_tree(&tree_id, index));
	cl_git_pass(git_index_write(index));
	git_index_free(index);

	cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));

	if (sig)
		cl_assert(sig->name && sig->email);
	else if (!time)
		cl_git_pass(git_signature_now(&sig, CL_COMMIT_NAME, CL_COMMIT_EMAIL));
	else
		cl_git_pass(git_signature_new(
			&sig, CL_COMMIT_NAME, CL_COMMIT_EMAIL, time, 0));

	if (!msg) {
		strcpy(buf, CL_COMMIT_MSG);
		git_oid_tostr(buf + strlen(CL_COMMIT_MSG),
			sizeof(buf) - strlen(CL_COMMIT_MSG), &tree_id);
		msg = buf;
	}

	cl_git_pass(git_commit_create_v(
		&commit_id, repo, ref ? git_reference_name(ref) : "HEAD",
		sig, sig, NULL, msg, tree, parent ? 1 : 0, parent));

	if (out)
		git_oid_cpy(out, &commit_id);

	git_object_free(parent);
	git_reference_free(ref);
	if (free_sig)
		git_signature_free(sig);
	git_tree_free(tree);
}
示例#14
0
文件: index.c 项目: guocb/pygit2
PyObject *
Index_write_tree(Index *self)
{
    git_oid oid;
    int err;

    err = git_index_write_tree(&oid, self->index);
    if (err < 0)
        return Error_set(err);

    return git_oid_to_python(oid.id);
}
示例#15
0
/**
 * Create a commit
 *
 * @param out The oid of the newly created commit
 * @param repository The repository
 * @param index The index
 * @param message The commit message
 * @param author Who is the author of the commit
 * @param committer Who is the committer
 * @return 0 on success, or error code
 */
int git2r_commit_create(
    git_oid *out,
    git_repository *repository,
    git_index *index,
    const char *message,
    git_signature *author,
    git_signature *committer)
{
    int err;
    git_oid oid;
    git_tree *tree = NULL;
    git_commit **parents = NULL;
    size_t n_parents = 0;

    err = git_index_write_tree(&oid, index);
    if (GIT_OK != err)
        goto cleanup;

    err = git_tree_lookup(&tree, repository, &oid);
    if (GIT_OK != err)
        goto cleanup;

    err = git2r_retrieve_parents(&parents, &n_parents, repository);
    if (GIT_OK != err)
        goto cleanup;

    err = git_commit_create(
        out,
        repository,
        "HEAD",
        author,
        committer,
        NULL,
        message,
        tree,
        n_parents,
        (const git_commit**)parents);
    if (GIT_OK != err)
        goto cleanup;

    err = git_repository_state_cleanup(repository);

cleanup:
    if (parents)
        git2r_parents_free(parents, n_parents);

    if (tree)
        git_tree_free(tree);

    return err;
}
示例#16
0
void test_patch(
	const char *one,
	const char *two,
	const git_diff_options *opts,
	const char *expected)
{
	git_oid id_one, id_two;
	git_index *index = NULL;
	git_commit *commit_one, *commit_two = NULL;
	git_tree *tree_one, *tree_two;
	git_diff *diff;
	git_patch *patch;
	git_buf actual = GIT_BUF_INIT;

	cl_git_pass(git_oid_fromstr(&id_one, one));
	cl_git_pass(git_commit_lookup(&commit_one, repo, &id_one));
	cl_git_pass(git_commit_tree(&tree_one, commit_one));

	if (two) {
		cl_git_pass(git_oid_fromstr(&id_two, two));
		cl_git_pass(git_commit_lookup(&commit_two, repo, &id_two));
		cl_git_pass(git_commit_tree(&tree_two, commit_two));
	} else {
		cl_git_pass(git_repository_index(&index, repo));
		cl_git_pass(git_index_write_tree(&id_two, index));
		cl_git_pass(git_tree_lookup(&tree_two, repo, &id_two));
	}

	cl_git_pass(git_diff_tree_to_tree(&diff, repo, tree_one, tree_two, opts));

	cl_git_pass(git_patch_from_diff(&patch, diff, 0));
	cl_git_pass(git_patch_to_buf(&actual, patch));

	cl_assert_equal_s(expected, actual.ptr);

	git_buf_clear(&actual);
	cl_git_pass(git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, git_diff_print_callback__to_buf, &actual));

	cl_assert_equal_s(expected, actual.ptr);

	git_buf_dispose(&actual);
	git_patch_free(patch);
	git_diff_free(diff);
	git_tree_free(tree_one);
	git_tree_free(tree_two);
	git_commit_free(commit_one);
	git_commit_free(commit_two);
	git_index_free(index);
}
示例#17
0
文件: level1.c 项目: Posnet/gpu-cuda
static int prepare_index(git_index *index, char* msg){
    git_oid index_tree;
    git_tree *head_obj;
    git_reference *head;
    char tree_str[GIT_OID_HEXSZ+1], parent_str[GIT_OID_HEXSZ+1];

    // Get the head OID
    git_repository_head(&head, repo);
    git_reference_peel((git_object**)&head_obj, head, GIT_OBJ_COMMIT);
    git_oid_tostr(parent_str, GIT_OID_HEXSZ+1,
                   git_tree_id(head_obj));

    git_reference_free(head);
    git_object_free((git_object*)head_obj);

    // Write the coin
    // TODO: Use C for this?
    system("perl -i -pe 's/(null:)(\\d+)/$1 . ($2+1)/e' LEDGER.txt");
    system("grep -q \"null\" LEDGER.txt || echo \"null:1\" >> LEDGER.txt");

    // Update the index
    check_lg2(git_index_read(index, 0),
              "Could not re-read index from disk", NULL);

    check_lg2(git_index_add_bypath(index, "LEDGER.txt"),
              "Could not add to index", "LEDGER.txt");

    // Write the index and get the tree OID
    git_index_write_tree(&index_tree, index);
    git_oid_tostr(tree_str, GIT_OID_HEXSZ+1, &index_tree);

    snprintf(msg, BUFFER_LENGTH,
             "commit %d%c"
             "tree %s\n"
             "parent %s\n"
             "author null           <*****@*****.**> %d +0000\n"
             "committer null           <*****@*****.**> %d +0000\n"
             "\n"
             "coins now"
             "\x01\x01\x01\x01"
             "\x01\x01\x01\x01"
             "\x01\x01\x01", // Align 32 bit words on GPU
             MSG_LENGTH, 0, tree_str, parent_str,
             (int)time(NULL), (int)time(NULL));
    pad_message(msg, COMMIT_LENGTH, BUFFER_LENGTH);

    return 0;
}
示例#18
0
/* git reset --hard 72333f47d4e83616630ff3b0ffe4c0faebcc3c45
 * git revert --no-commit d1d403d22cbe24592d725f442835cf46fe60c8ac */
void test_revert_workdir__again_after_automerge(void)
{
	git_commit *head, *commit;
	git_tree *reverted_tree;
	git_oid head_oid, revert_oid, reverted_tree_oid, reverted_commit_oid;
	git_signature *signature;

	struct merge_index_entry merge_index_entries[] = {
		{ 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 0, "file1.txt" },
		{ 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
		{ 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
		{ 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
	};

	struct merge_index_entry second_revert_entries[] = {
		{ 0100644, "3a3ef367eaf3fe79effbfb0a56b269c04c2b59fe", 1, "file1.txt" },
		{ 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 2, "file1.txt" },
		{ 0100644, "747726e021bc5f44b86de60e3032fd6f9f1b8383", 3, "file1.txt" },
		{ 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
		{ 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
		{ 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
	};

	git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45");
	cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
	cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));

	git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac");
	cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));
	cl_git_pass(git_revert(repo, commit, NULL));

	cl_assert(merge_test_index(repo_index, merge_index_entries, 4));

	cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index));
	cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid));

	cl_git_pass(git_signature_new(&signature, "Reverter", "*****@*****.**", time(NULL), 0));
	cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&head));

	cl_git_pass(git_revert(repo, commit, NULL));
	cl_assert(merge_test_index(repo_index, second_revert_entries, 6));

	git_signature_free(signature);
	git_tree_free(reverted_tree);
	git_commit_free(commit);
	git_commit_free(head);
}
示例#19
0
文件: read_index.c 项目: 1336/libgit2
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);
		}
	}
}
示例#20
0
static bool roundtrip_with_read_index(const char *tree_idstr)
{
	git_oid tree_id, new_tree_id;
	git_tree *tree;
	git_index *tree_index;

	cl_git_pass(git_oid_fromstr(&tree_id, tree_idstr));
	cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
	cl_git_pass(git_index_new(&tree_index));
	cl_git_pass(git_index_read_tree(tree_index, tree));
	cl_git_pass(git_index_read_index(_index, tree_index));
	cl_git_pass(git_index_write_tree(&new_tree_id, _index));

	git_tree_free(tree);
	git_index_free(tree_index);

	return git_oid_equal(&tree_id, &new_tree_id);
}
示例#21
0
/*
 * revert the same commit twice (when the first reverts cleanly):
 *
 * git revert 2d440f2
 * git revert 2d440f2
 */
void test_revert_workdir__again_after_edit(void)
{
	git_reference *head_ref;
	git_commit *orig_head, *commit;
	git_tree *reverted_tree;
	git_oid orig_head_oid, revert_oid, reverted_tree_oid, reverted_commit_oid;
	git_signature *signature;

	struct merge_index_entry merge_index_entries[] = {
		{ 0100644, "3721552e06c4bdc7d478e0674e6304888545d5fd", 0, "file1.txt" },
		{ 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
		{ 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
		{ 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
	};

	cl_git_pass(git_repository_head(&head_ref, repo));

	cl_git_pass(git_oid_fromstr(&orig_head_oid, "399fb3aba3d9d13f7d40a9254ce4402067ef3149"));
	cl_git_pass(git_commit_lookup(&orig_head, repo, &orig_head_oid));
	cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL));

	cl_git_pass(git_oid_fromstr(&revert_oid, "2d440f2b3147d3dc7ad1085813478d6d869d5a4d"));
	cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid));

	cl_git_pass(git_revert(repo, commit, NULL));

	cl_assert(merge_test_index(repo_index, merge_index_entries, 4));

	cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index));
	cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid));

	cl_git_pass(git_signature_new(&signature, "Reverter", "*****@*****.**", time(NULL), 0));
	cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&orig_head));

	cl_git_pass(git_revert(repo, commit, NULL));
	cl_assert(merge_test_index(repo_index, merge_index_entries, 4));

	git_signature_free(signature);
	git_tree_free(reverted_tree);
	git_commit_free(commit);
	git_commit_free(orig_head);
	git_reference_free(head_ref);
}
示例#22
0
/**
 * Creates a git tree object representing the state of the working directory.
 */
static int sync_workdir_tree(git_oid *out,
                             git_repository *repo)
{
    int e = 0;
    git_index *index = NULL;

    git_check(git_repository_index(&index, repo));
    git_check(git_index_clear(index));
    git_strarray paths = {NULL, 0};
    git_check(git_index_add_all(index, &paths, 0, NULL, NULL));
    git_check(git_index_write_tree(out, index));
    if (!git_repository_is_bare(repo))
    {
        git_check(git_index_write(index));
    }

exit:
    if (index)          git_index_free(index);
    return e;
}
示例#23
0
文件: index.c 项目: flowroute/pygit2
PyObject *
Index_write_tree(Index *self, PyObject *args)
{
    git_oid oid;
    Repository *repo = NULL;
    int err;

    if (!PyArg_ParseTuple(args, "|O!", &RepositoryType, &repo))
        return NULL;

    if (repo)
        err = git_index_write_tree_to(&oid, self->index, repo->repo);
    else
        err = git_index_write_tree(&oid, self->index);

    if (err < 0)
        return Error_set(err);

    return git_oid_to_python(&oid);
}
示例#24
0
文件: submodule.c 项目: Arhzi/libgit2
// Fixture setup and teardown
void test_rebase_submodule__initialize(void)
{
	git_index *index;
	git_oid tree_oid, commit_id;
	git_tree *tree;
	git_commit *parent;
	git_object *obj;
	git_reference *master_ref;
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
	opts.checkout_strategy = GIT_CHECKOUT_FORCE;

	repo = cl_git_sandbox_init("rebase-submodule");
	cl_git_pass(git_signature_new(&signature,
		"Rebaser", "*****@*****.**", 1405694510, 0));

	rewrite_gitmodules(git_repository_workdir(repo));

	cl_git_pass(git_submodule_set_url(repo, "my-submodule", git_repository_path(repo)));

	/* We have to commit the rewritten .gitmodules file */
	cl_git_pass(git_repository_index(&index, repo));
	cl_git_pass(git_index_add_bypath(index, ".gitmodules"));
	cl_git_pass(git_index_write_tree(&tree_oid, index));

	cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));

	cl_git_pass(git_repository_head(&master_ref, repo));
	cl_git_pass(git_commit_lookup(&parent, repo, git_reference_target(master_ref)));

	cl_git_pass(git_commit_create_v(&commit_id, repo, git_reference_name(master_ref), signature, signature, NULL, "Fixup .gitmodules", tree, 1, parent));

	/* And a final reset, for good measure */
	cl_git_pass(git_object_lookup(&obj, repo, &commit_id, GIT_OBJ_COMMIT));
	cl_git_pass(git_reset(repo, obj, GIT_RESET_HARD, &opts));

	git_index_free(index);
	git_object_free(obj);
	git_commit_free(parent);
	git_reference_free(master_ref);
	git_tree_free(tree);
}
示例#25
0
void GitRepository::init()
{
    git_repository* repo = NULL;

    git_repository_init_options initopts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
    initopts.flags = GIT_REPOSITORY_INIT_MKPATH;
    git_eval(git_repository_init_ext(&repo, m_local_dir_path.absolutePath().toLocal8Bit(), &initopts));

    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 commit_id;
    git_eval(git_commit_create_v(&commit_id, repo, "HEAD", signature(), signature(), NULL, "Initial commit", tree, 0));

    setRepository(repo);
}
示例#26
0
文件: tests.c 项目: 1336/libgit2
static void write_invalid_filename(git_repository *repo, const char *fn_orig)
{
	git_index *index;
	git_oid expected;
	const git_index_entry *entry;
	git_buf path = GIT_BUF_INIT;
	char *fn;

	cl_git_pass(git_repository_index(&index, repo));
	cl_assert(git_index_entrycount(index) == 0);

	/*
	 * Sneak a valid path into the index, we'll update it
	 * to an invalid path when we try to write the index.
	 */
	fn = git__strdup(fn_orig);
	replace_char(fn, '/', '_');

	git_buf_joinpath(&path, "./invalid", fn);

	cl_git_mkfile(path.ptr, NULL);

	cl_git_pass(git_index_add_bypath(index, fn));

	cl_assert(entry = git_index_get_bypath(index, fn, 0));

	/* kids, don't try this at home */
	replace_char((char *)entry->path, '_', '/');

	/* write-tree */
	cl_git_fail(git_index_write_tree(&expected, index));

	p_unlink(path.ptr);

	cl_git_pass(git_index_remove_all(index, NULL, NULL, NULL));
	git_buf_free(&path);
	git_index_free(index);
	git__free(fn);
}
示例#27
0
/*
 *  call-seq:
 *    index.write_tree([repo]) -> oid
 *
 *  Write the index to a tree, either in the index's repository, or in
 *  the given +repo+.
 *
 *  If the index contains any files in conflict, writing the tree will fail.
 *
 *  Returns the OID string of the written tree object.
 */
static VALUE rb_git_index_writetree(int argc, VALUE *argv, VALUE self)
{
	git_index *index;
	git_oid tree_oid;
	int error;
	VALUE rb_repo;

	Data_Get_Struct(self, git_index, index);

	if (rb_scan_args(argc, argv, "01", &rb_repo) == 1) {
		git_repository *repo = NULL;
		rugged_check_repo(rb_repo);
		Data_Get_Struct(rb_repo, git_repository, repo);
		error = git_index_write_tree_to(&tree_oid, index, repo);
	}
	else {
		error = git_index_write_tree(&tree_oid, index);
	}

	rugged_exception_check(error);
	return rugged_create_oid(&tree_oid);
}
示例#28
0
void GitWrapper::initializeGitRepository(QString folder)
{
    GIT_RETURN_IF_DISABLED()
    QMutexLocker l(&gitMutex);
    // this is not thread safe, we use locking elsewhere
    git_repository *repo = NULL;
    QByteArray ba = folder.toUtf8();

    const char *cString = ba.data();

    int error = git_repository_init(&repo, cString, false);
    if (error < 0) {
        const git_error *e = giterr_last();
        kDebug() << e->message;
    }

    git_signature *sig = NULL;
    git_index *index = NULL;
    git_oid tree_id;
    git_oid commit_id;
    git_tree *tree = NULL;


    // no error handling at the moment
    git_signature_now(&sig, "AutoGit", "auto@localhost");
    git_repository_index(&index, repo);
    git_index_write_tree(&tree_id, index);
    git_tree_lookup(&tree, repo, &tree_id);
    git_commit_create_v(&commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0);

    git_signature_free(sig);
    git_index_free(index);
    git_tree_free(tree);

    //first commit
    commitPattern(repo, "*", "Initial full commit");
    git_repository_free(repo);
}
示例#29
0
/*
 * revert the same commit twice (when the first reverts cleanly):
 *
 * git revert 2d440f2
 * git revert 2d440f2
 */
void test_revert_workdir__again(void)
{
	git_reference *head_ref;
	git_commit *orig_head;
	git_tree *reverted_tree;
	git_oid reverted_tree_oid, reverted_commit_oid;
	git_signature *signature;

	struct merge_index_entry merge_index_entries[] = {
		{ 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 0, "file1.txt" },
		{ 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" },
		{ 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" },
		{ 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" },
	};

	cl_git_pass(git_repository_head(&head_ref, repo));
	cl_git_pass(git_reference_peel((git_object **)&orig_head, head_ref, GIT_OBJ_COMMIT));
	cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL));

	cl_git_pass(git_revert(repo, orig_head, NULL));

	cl_assert(merge_test_index(repo_index, merge_index_entries, 4));

	cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index));
	cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid));

	cl_git_pass(git_signature_new(&signature, "Reverter", "*****@*****.**", time(NULL), 0));
	cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&orig_head));

	cl_git_pass(git_revert(repo, orig_head, NULL));
	cl_assert(merge_test_index(repo_index, merge_index_entries, 4));

	git_signature_free(signature);
	git_tree_free(reverted_tree);
	git_commit_free(orig_head);
	git_reference_free(head_ref);
}
示例#30
0
文件: nonetwork.c 项目: 1336/libgit2
void test_clone_nonetwork__clone_submodule(void)
{
	git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
	git_index *index;
	git_oid tree_id, commit_id;
	git_submodule *sm;
	git_signature *sig;
	git_repository *sm_repo;

	cl_git_pass(git_repository_init(&g_repo, "willaddsubmodule", false));


	/* Create the submodule structure, clone into it and finalize */
	cl_git_pass(git_submodule_add_setup(&sm, g_repo, cl_fixture("testrepo.git"), "testrepo", true));

	clone_opts.repository_cb = just_return_repo;
	clone_opts.repository_cb_payload = sm;
	clone_opts.remote_cb = just_return_origin;
	clone_opts.remote_cb_payload = sm;
	cl_git_pass(git_clone(&sm_repo, cl_fixture("testrepo.git"), "testrepo", &clone_opts));
	cl_git_pass(git_submodule_add_finalize(sm));
	git_repository_free(sm_repo);
	git_submodule_free(sm);

	cl_git_pass(git_repository_index(&index, g_repo));
	cl_git_pass(git_index_write_tree(&tree_id, index));
	git_index_free(index);

	cl_git_pass(git_signature_now(&sig, "Submoduler", "submoduler@local"));
	cl_git_pass(git_commit_create_from_ids(&commit_id, g_repo, "HEAD", sig, sig, NULL, "A submodule\n",
					       &tree_id, 0, NULL));

	git_signature_free(sig);

	assert_submodule_exists(g_repo, "testrepo");
}