繁体   English   中英

在libgit2中执行git describe

[英]performing git describe in libgit2

我想像“git describe”一样在终端工作。

如何获得我的回购的当前标记? 现在我的程序正在打印

09B8A518

每次我尝试这个,这个数字是不同的所以我不认为它是提交ID左右。

当我在终端中执行“git describe”时,输出为“v0.1.2”

有没有办法做到这一点?

顺便说一句,我怎样才能转换“git_describe_result * out;” 串?

    string path = C://my/local/repo;
    string result;
    git_libgit2_init();

    const char * REPO_PATH = path.c_str();
    git_repository * repo = nullptr;
    git_repository_open(&repo, REPO_PATH);

    git_describe_result *out;
    git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
    opts.version = GIT_DESCRIBE_FORMAT_OPTIONS_VERSION;  // GIT_DESCRIBE_OPTIONS_VERSION;

    git_describe_workdir(&out, repo, &opts);
    cout << out << endl;

    git_describe_result_free(out);
    git_repository_free(repo);
    git_libgit2_shutdown();

使用git_describe_formatgit_describe_result转换为字符串。

现在这适合我

            string path = C://my/local/repo;
            string result;
            git_libgit2_init();

            const char * REPO_PATH = path.c_str();
            git_repository * repo = nullptr;
            git_repository_open(&repo, REPO_PATH);
            git_describe_result *out;
            git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
 // ---------------------------------------
            // I added this
            opts.describe_strategy = GIT_DESCRIBE_ALL;
            opts.max_candidates_tags = 0;
            opts.only_follow_first_parent = 1;
 // ---------------------------------------
            git_describe_workdir(&out, repo, &opts);

    // --------------------------------------

    // and also this
                git_buf out1 = { 0 };
                const git_describe_format_options opts1=GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
                git_describe_format(&out1, out, &opts1);
                result = out1.ptr;
                cout << result << endl;

    // ---------------------------------------
            git_describe_result_free(out);
            git_repository_free(repo);
            git_libgit2_shutdown();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM