我想像“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();
答案 0 :(得分:0)
将git_describe_result
转换为git_describe_format
的字符串。
答案 1 :(得分:0)
现在这对我有用
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();