Esempio n. 1
0
void test_repo_head__orphan_branch_does_not_count(void)
{
    git_signature *sig;
    git_oid id;
    const char *msg;

    cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

    /* Have something known */
    msg = "message1";
    git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
    cl_git_pass(git_repository_set_head_detached(repo, &id, sig, msg));
    assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
                       "e90810b8df3e80c413d903f631643c716887138d", msg);

    /* Switching to an orphan branch does not write tot he reflog */
    cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan", sig, "ignored message"));
    assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
                       "e90810b8df3e80c413d903f631643c716887138d", msg);

    /* And coming back, we set the source to zero */
    msg = "message2";
    cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg));
    assert_head_reflog(repo, 0, "0000000000000000000000000000000000000000",
                       "258f0e2a959a364e40ed6603d5d44fbb24765b10", msg);

    git_signature_free(sig);
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
0
void test_refs_reflog_reflog__append_then_read(void)
{
	/* write a reflog for a given reference and ensure it can be read back */
	git_reference *ref;
	git_oid oid;
	git_signature *committer;
	git_reflog *reflog;

	/* Create a new branch pointing at the HEAD */
	git_oid_fromstr(&oid, current_master_tip);
	cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0, NULL));
	git_reference_free(ref);

	cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));

	cl_git_pass(git_reflog_read(&reflog, g_repo, new_ref));

	cl_git_fail(git_reflog_append(reflog, &oid, committer, "no inner\nnewline"));
	cl_git_pass(git_reflog_append(reflog, &oid, committer, NULL));
	cl_git_pass(git_reflog_append(reflog, &oid, committer, commit_msg "\n"));
	cl_git_pass(git_reflog_write(reflog));
	git_reflog_free(reflog);

	assert_appends(committer, &oid);

	git_signature_free(committer);
}
Esempio n. 5
0
void test_commit_commit__create_unexisting_update_ref(void)
{
	git_oid oid;
	git_tree *tree;
	git_commit *commit;
	git_signature *s;
	git_reference *ref;

	git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
	cl_git_pass(git_commit_lookup(&commit, _repo, &oid));

	git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
	cl_git_pass(git_tree_lookup(&tree, _repo, &oid));

	cl_git_pass(git_signature_now(&s, "alice", "*****@*****.**"));

	cl_git_fail(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
	cl_git_pass(git_commit_create(&oid, _repo, "refs/heads/foo/bar", s, s,
				      NULL, "some msg", tree, 1, (const git_commit **) &commit));

	/* fail because the parent isn't the tip of the branch anymore */
	cl_git_fail(git_commit_create(&oid, _repo, "refs/heads/foo/bar", s, s,
				      NULL, "some msg", tree, 1, (const git_commit **) &commit));

	cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
	cl_assert(!git_oid_cmp(&oid, git_reference_target(ref)));

	git_tree_free(tree);
	git_commit_free(commit);
	git_signature_free(s);
	git_reference_free(ref);
}
Esempio n. 6
0
void test_notes_notesref__config_corenotesref(void)
{
	git_oid oid, note_oid;
	const char *default_ref;

	cl_git_pass(git_signature_now(&_sig, "alice", "*****@*****.**"));
	cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));

	cl_git_pass(git_repository_config(&_cfg, _repo));

	cl_git_pass(git_config_set_string(_cfg, "core.notesRef", "refs/notes/mydefaultnotesref"));

	cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "test123test\n"));

	cl_git_pass(git_note_read(&_note, _repo, NULL, &oid));
	cl_assert(!strcmp(git_note_message(_note), "test123test\n"));
	cl_assert(!git_oid_cmp(git_note_oid(_note), &note_oid));

	git_note_free(_note);

	cl_git_pass(git_note_read(&_note, _repo, "refs/notes/mydefaultnotesref", &oid));
	cl_assert(!strcmp(git_note_message(_note), "test123test\n"));
	cl_assert(!git_oid_cmp(git_note_oid(_note), &note_oid));

	cl_git_pass(git_note_default_ref(&default_ref, _repo));
	cl_assert(!strcmp(default_ref, "refs/notes/mydefaultnotesref"));

	cl_git_pass(git_config_delete(_cfg, "core.notesRef"));

	cl_git_pass(git_note_default_ref(&default_ref, _repo));
	cl_assert(!strcmp(default_ref, GIT_NOTES_DEFAULT_REF));
}
Esempio n. 7
0
void test_repo_head__set_to_current_target(void)
{
    git_signature *sig;
    const char *msg;
    git_reflog *log;
    size_t nentries, nentries_after;

    cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
    nentries = git_reflog_entrycount(log);
    git_reflog_free(log);

    cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

    msg = "message 1";
    cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg));
    cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg));

    cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
    nentries_after = git_reflog_entrycount(log);
    git_reflog_free(log);

    cl_assert_equal_i(nentries + 1, nentries_after);

    git_signature_free(sig);

}
Esempio n. 8
0
int git_reference_rename(
	git_reference **out,
	git_reference *ref,
	const char *new_name,
	int force,
	const git_signature *signature,
	const char *log_message)
{
	git_signature *who = (git_signature*)signature;
	int error;

	/* Should we return an error if there is no default? */
	if (!who &&
	    ((error = git_signature_default(&who, ref->db->repo)) < 0) &&
	    ((error = git_signature_now(&who, "unknown", "unknown")) < 0)) {
		return error;
	}

	error = reference__rename(out, ref, new_name, force, who, log_message);

	if (!signature)
		git_signature_free(who);

	return error;
}
Esempio n. 9
0
void test_refs_settargetwithlog__updating_a_direct_reference_adds_a_reflog_entry(void)
{
	git_reference *reference, *reference_out;
	git_oid current_id, target_id;
	git_signature *signature;
	git_reflog *reflog;
	const git_reflog_entry *entry;

	const char *message = "You've been logged, mate!";

	git_oid_fromstr(&current_id, br2_tip);
	git_oid_fromstr(&target_id, master_tip);

	cl_git_pass(git_reference_lookup(&reference, g_repo, br2_name));

	cl_git_pass(git_signature_now(&signature, "foo", "foo@bar"));

	cl_git_pass(git_reference_set_target(
		&reference_out, reference, &target_id, signature, message));

	cl_git_pass(git_reflog_read(&reflog, g_repo, br2_name));

	entry = git_reflog_entry_byindex(reflog, 0);
	cl_assert(git_oid_cmp(&current_id, &entry->oid_old) == 0);
	cl_assert(git_oid_cmp(&target_id, &entry->oid_cur) == 0);
	cl_assert_equal_s(message, entry->msg);

	git_reflog_free(reflog);
	git_reference_free(reference_out);
	git_reference_free(reference);
	git_signature_free(signature);
}
Esempio n. 10
0
void MainWindow::on_pushButtonTag_clicked()
{
    //make a tag!

    if (repo == NULL)
        return;

    qDebug() << "making a tag...";
    git_oid oid;
    git_object *target = NULL;
    git_signature *tagger = NULL;

    int err = git_revparse_single(&target, repo, "HEAD^{commit}");
    qDebug() << "reverseparse: "<<err;
    err = git_signature_now(&tagger, "johnty", "*****@*****.**");
    qDebug() << "get signature: "<<err;

    //probably not the best text widgets to use?
    const char* tag_name = ui->textTagName->toPlainText().toStdString().c_str();
    const char* tag_msg = ui->textTagAnno->toPlainText().toStdString().c_str();

    err = git_tag_create(
          &oid,               /* new object id */
          repo,               /* repo */
          tag_name,           /* name */
          target,             /* target */
          tagger,             /* name/email/timestamp */
          tag_msg, /* message */
          false);             /* force? */
    qDebug() << "create tag: "<<err;

    git_object_free(target);
    git_signature_free(tagger);
}
Esempio n. 11
0
void test_refs_reflog_messages__detaching_writes_reflog(void)
{
	git_signature *sig;
	git_oid id;
	const char *msg;

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
	git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
	cl_git_pass(git_repository_set_head_detached(g_repo, &id));
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
		"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
		"e90810b8df3e80c413d903f631643c716887138d",
		NULL, msg);

	msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked";
	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
		"e90810b8df3e80c413d903f631643c716887138d",
		"258f0e2a959a364e40ed6603d5d44fbb24765b10",
		NULL, msg);

	git_signature_free(sig);
}
Esempio n. 12
0
void GitRepository::setSignature(const QString& authorName, const QString& authorEmail)
{
    git_signature* sig = m_signature;
    if (sig) { git_signature_free(sig); }
    git_eval(git_signature_now(&sig, authorName.toLocal8Bit(), authorEmail.toLocal8Bit()));
    m_signature = sig;
}
Esempio n. 13
0
File: head.c Progetto: 1336/libgit2
void test_repo_head__setting_head_updates_reflog(void)
{
	git_object *tag;
	git_signature *sig;
	git_annotated_commit *annotated;

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
	cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn"));
	cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
	cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
	cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));

	test_reflog(repo, 2, NULL, "refs/heads/haacked", "*****@*****.**", "checkout: moving from master to haacked");
	test_reflog(repo, 1, NULL, "tags/test^{commit}", "*****@*****.**", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
	test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "*****@*****.**", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "haacked~0"));
	cl_git_pass(git_repository_set_head_detached_from_annotated(repo, annotated));

	test_reflog(repo, 0, NULL, "refs/heads/haacked", "*****@*****.**", "checkout: moving from haacked to haacked~0");

	git_annotated_commit_free(annotated);
	git_object_free(tag);
	git_signature_free(sig);
}
Esempio n. 14
0
void test_refs_reflog_messages__branch_birth(void)
{
	git_signature *sig;
	git_oid id;
	git_tree *tree;
	git_reference *ref;
	const char *msg;
	size_t nentries, nentries_after;

	nentries = reflog_entrycount(g_repo, GIT_HEAD_FILE);

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	cl_git_pass(git_repository_head(&ref, g_repo));
	cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));

	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan"));

	nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);

	cl_assert_equal_i(nentries, nentries_after);

	msg = "message 2";
	cl_git_pass(git_commit_create(&id, g_repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));

	cl_assert_equal_i(1, reflog_entrycount(g_repo, "refs/heads/orphan"));

	nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);

	cl_assert_equal_i(nentries + 1, nentries_after);

	git_signature_free(sig);
	git_tree_free(tree);
	git_reference_free(ref);
}
Esempio n. 15
0
int configured_ident(git_signature **out, const git_repository *repo)
{
	if (repo->ident_name && repo->ident_email)
		return git_signature_now(out, repo->ident_name, repo->ident_email);

	/* if not configured let us fall-through to the next method  */
	return -1;
}
Esempio n. 16
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);
}
Esempio n. 17
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);
}
Esempio n. 18
0
int git_reference__log_signature(git_signature **out, git_repository *repo)
{
	int error;
	git_signature *who;

	if(((error = git_signature_default(&who, repo)) < 0) &&
	   ((error = git_signature_now(&who, "unknown", "unknown")) < 0))
		return error;

	*out = who;
	return 0;
}
Esempio n. 19
0
git_signature *rugged_signature_get(VALUE rb_sig, git_repository *repo)
{
	int error;
	VALUE rb_time, rb_unix_t, rb_offset, rb_name, rb_email, rb_time_offset;
	git_signature *sig;

	if (NIL_P(rb_sig)) {
		rugged_exception_check(
			git_signature_default(&sig, repo)
		);
		return sig;
	}

	Check_Type(rb_sig, T_HASH);

	rb_name = rb_hash_aref(rb_sig, CSTR2SYM("name"));
	rb_email = rb_hash_aref(rb_sig, CSTR2SYM("email"));
	rb_time = rb_hash_aref(rb_sig, CSTR2SYM("time"));
	rb_time_offset = rb_hash_aref(rb_sig, CSTR2SYM("time_offset"));

	Check_Type(rb_name, T_STRING);
	Check_Type(rb_email, T_STRING);


	if (NIL_P(rb_time)) {
		error = git_signature_now(&sig,
				StringValueCStr(rb_name),
				StringValueCStr(rb_email));
	} else {
		if (!rb_obj_is_kind_of(rb_time, rb_cTime))
			rb_raise(rb_eTypeError, "expected Time object");

		rb_unix_t = rb_funcall(rb_time, rb_intern("tv_sec"), 0);

		if (NIL_P(rb_time_offset)) {
			rb_offset = rb_funcall(rb_time, rb_intern("utc_offset"), 0);
		} else {
			Check_Type(rb_time_offset, T_FIXNUM);
			rb_offset = rb_time_offset;
		}

		error = git_signature_new(&sig,
				StringValueCStr(rb_name),
				StringValueCStr(rb_email),
				NUM2LONG(rb_unix_t),
				FIX2INT(rb_offset) / 60);
	}

	rugged_exception_check(error);

	return sig;
}
Esempio n. 20
0
void test_refs_reflog_messages__setting_head_updates_reflog(void)
{
	git_object *tag;
	git_signature *sig;
	git_annotated_commit *annotated;

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); /* 4 */
	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/unborn"));
	cl_git_pass(git_revparse_single(&tag, g_repo, "tags/test"));
	cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(tag))); /* 3 */
	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));        /* 2 */
	cl_git_pass(git_repository_set_head(g_repo, "refs/tags/test"));            /* 1 */
	cl_git_pass(git_repository_set_head(g_repo, "refs/remotes/test/master"));  /* 0 */

	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 4,
		NULL, "refs/heads/haacked",
		"*****@*****.**",
		"checkout: moving from master to haacked");
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 3,
		NULL, "tags/test^{commit}",
		"*****@*****.**",
		"checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 2,
		"tags/test^{commit}", "refs/heads/haacked",
		"*****@*****.**",
		"checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 1,
		"refs/heads/haacked", "tags/test^{commit}",
		"*****@*****.**",
		"checkout: moving from haacked to test");
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
		"tags/test^{commit}", "refs/remotes/test/master",
		"*****@*****.**",
		"checkout: moving from e90810b8df3e80c413d903f631643c716887138d to test/master");

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "haacked~0"));
	cl_git_pass(git_repository_set_head_detached_from_annotated(g_repo, annotated));

	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
		NULL, "refs/heads/haacked",
		"*****@*****.**",
		"checkout: moving from be3563ae3f795b2b4353bcce3a527ad0a4f7f644 to haacked~0");

	git_annotated_commit_free(annotated);
	git_object_free(tag);
	git_signature_free(sig);
}
Esempio n. 21
0
int git_signature_default(git_signature **out, git_repository *repo)
{
	int error;
	git_config *cfg;
	const char *user_name, *user_email;

	if ((error = git_repository_config_snapshot(&cfg, repo)) < 0)
		return error;

	if (!(error = git_config_get_string(&user_name, cfg, "user.name")) &&
		!(error = git_config_get_string(&user_email, cfg, "user.email")))
		error = git_signature_now(out, user_name, user_email);

	git_config_free(cfg);
	return error;
}
Esempio n. 22
0
int
Signature_init(Signature *self, PyObject *args, PyObject *kwds)
{
    char *keywords[] = {"name", "email", "time", "offset", "encoding", NULL};
    PyObject *py_name, *tname;
    char *email, *encoding = "utf-8";
    const char *name;
    long long time = -1;
    int offset = 0;
    int err;
    git_signature *signature;

    if (!PyArg_ParseTupleAndKeywords(
                args, kwds, "Os|Lis", keywords,
                &py_name, &email, &time, &offset, &encoding))
        return -1;

    name = py_str_borrow_c_str(&tname, py_name, encoding);
    if (name == NULL)
        return -1;

    if (time == -1) {
        err = git_signature_now(&signature, name, email);
    } else {
        err = git_signature_new(&signature, name, email, time, offset);
    }
    Py_DECREF(tname);

    if (err < 0) {
        Error_set(err);
        return -1;
    }

    self->obj = NULL;
    self->signature = signature;

    if (encoding) {
        self->encoding = strdup(encoding);
        if (self->encoding == NULL) {
            PyErr_NoMemory();
            return -1;
        }
    }

    return 0;
}
Esempio n. 23
0
static int rebase_copy_note(
	git_rebase *rebase,
	const char *notes_ref,
	git_oid *from,
	git_oid *to,
	const git_signature *committer)
{
	git_note *note = NULL;
	git_oid note_id;
	git_signature *who = NULL;
	int error;

	if ((error = git_note_read(&note, rebase->repo, notes_ref, from)) < 0) {
		if (error == GIT_ENOTFOUND) {
			giterr_clear();
			error = 0;
		}

		goto done;
	}

	if (!committer) {
		if((error = git_signature_default(&who, rebase->repo)) < 0) {
			if (error != GIT_ENOTFOUND ||
				(error = git_signature_now(&who, "unknown", "unknown")) < 0)
				goto done;

			giterr_clear();
		}

		committer = who;
	}

	error = git_note_create(&note_id, rebase->repo, notes_ref,
		git_note_author(note), committer, to, git_note_message(note), 0);

done:
	git_note_free(note);
	git_signature_free(who);

	return error;
}
Esempio n. 24
0
void test_repo_head__setting_head_updates_reflog(void)
{
    git_object *tag;
    git_signature *sig;

    cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

    cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, "message1"));
    cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn", sig, "message2"));
    cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
    cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag), sig, "message3"));
    cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, "message4"));

    test_reflog(repo, 2, NULL, "refs/heads/haacked", "*****@*****.**", "message1");
    test_reflog(repo, 1, NULL, "tags/test^{commit}", "*****@*****.**", "message3");
    test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "*****@*****.**", "message4");

    git_object_free(tag);
    git_signature_free(sig);
}
Esempio n. 25
0
/**
 * Commits a tree to the master branch of the repository.
 */
static int sync_commit_master(git_repository *repo,
                              const char *message,
                              git_oid *tree_id,
                              size_t parent_count,
                              const git_oid *parents[])
{
    int e = 0;
    git_signature *sig = NULL;
    git_oid commit_id;

    git_check(git_signature_now(&sig, SYNC_GIT_NAME, SYNC_GIT_EMAIL));

    git_check(git_commit_create_from_ids(&commit_id, repo, SYNC_REF_MASTER,
        sig, sig, NULL, message,
        tree_id, parent_count, parents));

exit:
    if (sig)            git_signature_free(sig);
    return e;
}
Esempio n. 26
0
void test_refs_branches_create__creation_creates_new_reflog(void)
{
	git_reflog *log;
	const git_reflog_entry *entry;
	git_signature *sig;

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	retrieve_known_commit(&target, repo);
	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, sig, "create!"));
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));

	cl_assert_equal_i(1, git_reflog_entrycount(log));
	entry = git_reflog_entry_byindex(log, 0);
	cl_assert_equal_s("create!", git_reflog_entry_message(entry));
	cl_assert_equal_s("*****@*****.**", git_reflog_entry_committer(entry)->email);

	git_reflog_free(log);
	git_signature_free(sig);
}
Esempio n. 27
0
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);
}
Esempio n. 28
0
void test_repo_head__detaching_writes_reflog(void)
{
    git_signature *sig;
    git_oid id;
    const char *msg;

    cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

    msg = "message1";
    git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
    cl_git_pass(git_repository_set_head_detached(repo, &id, sig, msg));
    assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
                       "e90810b8df3e80c413d903f631643c716887138d", msg);

    msg = "message2";
    cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg));
    assert_head_reflog(repo, 0, "e90810b8df3e80c413d903f631643c716887138d",
                       "258f0e2a959a364e40ed6603d5d44fbb24765b10", msg);

    git_signature_free(sig);
}
Esempio n. 29
0
void test_repo_head__head_detached(void)
{
    git_reference *ref;
    git_signature *sig;

    cl_git_pass(git_signature_now(&sig, "Foo Bar", "*****@*****.**"));

    cl_assert_equal_i(false, git_repository_head_detached(repo));

    cl_git_pass(git_repository_detach_head(repo, sig, "CABLE DETACHED"));
    check_last_reflog_entry(sig->email, "CABLE DETACHED");
    cl_assert_equal_i(true, git_repository_head_detached(repo));

    /* take the repo back to it's original state */
    cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master",
                true, sig, "REATTACH"));
    git_reference_free(ref);

    check_last_reflog_entry(sig->email, "REATTACH");
    cl_assert_equal_i(false, git_repository_head_detached(repo));
    git_signature_free(sig);
}
Esempio n. 30
0
void test_refs_reflog_messages__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;

	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_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
		NULL,
		git_oid_tostr_s(&merge_commit_oid),
		NULL, "commit (merge): Merge commit");

	git_tree_free(tree);
	git_commit_free(b1_commit);
	git_commit_free(b2_commit);
	git_signature_free(s);
}