コード例 #1
0
ファイル: reflog.c プロジェクト: csware/libgit2
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);
}
コード例 #2
0
ファイル: ggit-reflog.c プロジェクト: GNOME/libgit2-glib
/**
 * ggit_reflog_append:
 * @reflog: a #GgitReflog.
 * @oid: a #GgitOId.
 * @committer: a #GgitSignature.
 * @message: the message.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Creates a reflog entry.
 *
 * Returns: %TRUE if the reflog was successfully created, or %FALSE if error is set.
 */
gboolean
ggit_reflog_append (GgitReflog     *reflog,
                    GgitOId        *oid,
                    GgitSignature  *committer,
                    const gchar    *message,
                    GError        **error)
{
	gint ret;

	g_return_val_if_fail (reflog != NULL, FALSE);
	g_return_val_if_fail (oid != NULL, FALSE);
	g_return_val_if_fail (GGIT_IS_SIGNATURE (committer), FALSE);
	g_return_val_if_fail (message != NULL && *message != '\0', FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	ret = git_reflog_append (reflog->reflog,
	                         _ggit_oid_get_oid (oid),
	                         _ggit_native_get (committer),
	                         message);

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
		return FALSE;
	}

	return TRUE;
}
コード例 #3
0
ファイル: stash.c プロジェクト: aep/libgit2
static int update_reflog(
	git_oid *w_commit_oid,
	git_repository *repo,
	const git_signature *stasher,
	const char *message)
{
	git_reference *stash = NULL;
	git_reflog *reflog = NULL;
	int error;

	if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1)) < 0)
		goto cleanup;

	if ((error = git_reflog_read(&reflog, stash)) < 0)
		goto cleanup;

	if ((error = git_reflog_append(reflog, w_commit_oid, stasher, message)) < 0)
		goto cleanup;

	if ((error = git_reflog_write(reflog)) < 0)
		goto cleanup;

cleanup:
	git_reference_free(stash);
	git_reflog_free(reflog);
	return error;
}
コード例 #4
0
ファイル: delete.c プロジェクト: 1336/libgit2
void test_refs_branches_delete__removes_reflog(void)
{
	git_reference *branch;
	git_reflog *log;
	git_oid oidzero = {{0}};
	git_signature *sig;

	/* Ensure the reflog has at least one entry */
	cl_git_pass(git_signature_now(&sig, "Me", "*****@*****.**"));
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/track-local"));
	cl_git_pass(git_reflog_append(log, &oidzero, sig, "message"));
	cl_assert(git_reflog_entrycount(log) > 0);
	git_signature_free(sig);
	git_reflog_free(log);

	cl_git_pass(git_branch_lookup(&branch, repo, "track-local", GIT_BRANCH_LOCAL));
	cl_git_pass(git_branch_delete(branch));
	git_reference_free(branch);

	/* Reading a nonexistant reflog creates it, but it should be empty */
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/track-local"));
	cl_assert_equal_i(0, git_reflog_entrycount(log));
	git_reflog_free(log);
}