在 libgit2 中执行 git 描述
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_result
转换为git_describe_format
的字符串。
现在这对我有用
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();
我想像 "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_result
转换为git_describe_format
的字符串。
现在这对我有用
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();