[英]performing git describe in libgit2
I want to work this like "git describe" is working in terminal. 我想像“git describe”一样在终端工作。
How can I get current tag of my repo? 如何获得我的回购的当前标记? Now my program is printing 现在我的程序正在打印
09B8A518 09B8A518
Everytime I try that, this number is different so I dont think it is commit ID or so. 每次我尝试这个,这个数字是不同的所以我不认为它是提交ID左右。
When I perform "git describe" in terminal, output is "v0.1.2" 当我在终端中执行“git describe”时,输出为“v0.1.2”
Is there a way to do that? 有没有办法做到这一点?
By the way, how can I convert "git_describe_result *out;" 顺便说一句,我怎样才能转换“git_describe_result * out;” to string? 串?
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_format
将git_describe_result
转换为字符串。
Now this works for me 现在这适合我
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.