63 lines
2.3 KiB
Plaintext
63 lines
2.3 KiB
Plaintext
repo_path = ex_base_exe_ex.toStdString() + target_name;
|
|
std::cout << "target_name: " << target_name << std::endl;
|
|
std::cout << "repo_path: " << repo_path << std::endl;
|
|
std::cout << "src_name: " << src_name << std::endl;
|
|
std::cout << "remote_url: " << remote_url << std::endl;
|
|
/*
|
|
if (git_mode == GIT_MODE::BRANCH)
|
|
{
|
|
clone_branch();
|
|
}
|
|
else if (git_mode == GIT_MODE::TAG)
|
|
{
|
|
clone_tag();
|
|
}
|
|
*/
|
|
git_libgit2_init();
|
|
// create a bare local repository
|
|
git_repository_init(&repo, repo_path.c_str(), false);
|
|
// set remote url
|
|
git_remote_create(&remote, repo, "origin", remote_url.c_str());
|
|
// generate refspec
|
|
// http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions
|
|
std::string refspec; // for git fetch
|
|
std::string revspec; // for git checkout
|
|
/*
|
|
if (branch_name.size())
|
|
{
|
|
refspec = "+refs/heads/" + branch_name + ":refs/remotes/origin/" + branch_name;
|
|
revspec = "refs/remotes/origin/" + branch_name;
|
|
}
|
|
*/
|
|
std::string target_name="457140_457141_5898877434354585407";
|
|
if (target_name.size())
|
|
{
|
|
refspec = "+refs/tags/" + target_name + ":refs/tags/" + target_name;
|
|
revspec = "refs/tags/"+target_name;
|
|
}
|
|
// construct fetch_opts and run fetch
|
|
// for libgit:v1.7.0 the GIT_FETCH_OPTIONS_INIT was
|
|
// missing some field, so we must assign then manually.
|
|
char *refspec_addr[] = {refspec.data()};
|
|
git_strarray refspecs{refspec_addr, 1};
|
|
|
|
git_fetch_options fetch_opt = GIT_FETCH_OPTIONS_INIT;
|
|
fetch_opt.proxy_opts.type = GIT_PROXY_AUTO;
|
|
fetch_opt.depth = 1;
|
|
fetch_opt.follow_redirects = GIT_REMOTE_REDIRECT_INITIAL;
|
|
fetch_opt.custom_headers = git_strarray{nullptr, 0};
|
|
git_remote_fetch(remote, &refspecs, &fetch_opt, NULL);
|
|
|
|
// find revision
|
|
git_object *rev;
|
|
git_revparse_single(&rev, repo, revspec.c_str());
|
|
|
|
// git checkout $branch
|
|
// git checkout tags/$tag
|
|
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
|
|
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
|
|
git_reset(repo, rev, GIT_RESET_HARD, &checkout_opts);
|
|
|
|
// finally close
|
|
git_remote_free(remote);
|
|
git_repository_free(repo); |