Example #1
0
void test_describe_describe__describe_a_repo_with_no_refs(void)
{
	git_repository *repo;
	git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
	git_buf buf = GIT_BUF_INIT;
	git_object *object;
	git_describe_result *result = NULL;

	repo = cl_git_sandbox_init("testrepo.git");
	cl_git_pass(git_revparse_single(&object, repo, "HEAD"));

	cl_git_pass(git_reference_foreach(repo, delete_cb, NULL));

	/* Impossible to describe without falling back to OIDs */
	cl_git_fail(git_describe_commit(&result, object, &opts));

	/* Try again with OID fallbacks */
	opts.show_commit_oid_as_fallback = 1;
	cl_git_pass(git_describe_commit(&result, object, &opts));

	git_describe_result_free(result);
	git_object_free(object);
	git_buf_dispose(&buf);
	cl_git_sandbox_cleanup();
}
Example #2
0
void assert_describe_workdir(
	const char *expected_output,
	git_repository *repo,
	git_describe_options *opts,
	git_describe_format_options *fmt_opts)
{
	git_buf label = GIT_BUF_INIT;
	git_describe_result *result;

	cl_git_pass(git_describe_workdir(&result, repo, opts));
	cl_git_pass(git_describe_format(&label, result, fmt_opts));

	cl_must_pass(p_fnmatch(expected_output, git_buf_cstr(&label), 0));

	git_describe_result_free(result);
	git_buf_free(&label);
}
Example #3
0
void assert_describe(
	const char *expected_output,
	const char *revparse_spec,
	git_repository *repo,
	git_describe_options *opts,
	git_describe_format_options *fmt_opts)
{
	git_object *object;
	git_buf label = GIT_BUF_INIT;
	git_describe_result *result;

	cl_git_pass(git_revparse_single(&object, repo, revparse_spec));

	cl_git_pass(git_describe_commit(&result, object, opts));
	cl_git_pass(git_describe_format(&label, result, fmt_opts));

	cl_must_pass(p_fnmatch(expected_output, git_buf_cstr(&label), 0));

	git_describe_result_free(result);
	git_object_free(object);
	git_buf_free(&label);
}
Example #4
0
//-----------------------------------------------------------------------------------------//
int AdVersion::getGitVersion(QString gitDirectory, QString &version)
{
    int ierr;
    QFile dir(gitDirectory+"/.git");
    QByteArray tempData;
    git_repository *repo;
    git_describe_result *description;
    git_describe_options options;
    git_describe_format_options format;
    git_object *headObject;
    git_buf buffer = { 0 };

    version = QString();

    if(!dir.exists())
        return -1;

    tempData = gitDirectory.toLatin1();
    const char *cgitDirectory = tempData.data();

    git_libgit2_init();

    ierr = git_repository_open(&repo,cgitDirectory);
    if(ierr<0)
    {
        git_repository_free(repo);
        git_libgit2_shutdown();
        return ierr;
    }

    ierr = git_describe_init_options(&options,GIT_DESCRIBE_OPTIONS_VERSION);
    options.show_commit_oid_as_fallback = 1;
    if(ierr<0)
    {
        git_repository_free(repo);
        git_libgit2_shutdown();
        return ierr;
    }

    ierr = git_describe_init_format_options(&format,GIT_DESCRIBE_FORMAT_OPTIONS_VERSION);
    if(ierr<0)
    {
        git_repository_free(repo);
        git_libgit2_shutdown();
        return ierr;
    }

    ierr = git_revparse_single(&headObject,repo,"HEAD");
    if(ierr<0)
    {
        git_object_free(headObject);
        git_repository_free(repo);
        git_libgit2_shutdown();
        return ierr;
    }

    ierr = git_describe_commit(&description,headObject,&options);
    if(ierr<0)
    {
        git_object_free(headObject);
        git_repository_free(repo);
        git_libgit2_shutdown();
        return ierr;
    }

    ierr = git_describe_format(&buffer,description,&format);
    if(ierr<0)
    {
        git_object_free(headObject);
        git_describe_result_free(description);
        git_repository_free(repo);
        git_libgit2_shutdown();
        return ierr;
    }

    version.sprintf("%s",buffer.ptr);

    git_object_free(headObject);
    git_describe_result_free(description);
    git_repository_free(repo);
    git_libgit2_shutdown();

    return ERROR_NOERROR;
}