Add option to use cache dir to clone().

Preparation for caching the repository.
This commit is contained in:
tastytea 2020-10-13 19:25:55 +02:00
parent 0f9736becd
commit db18edd478
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 21 additions and 5 deletions

View File

@ -71,12 +71,22 @@ int cred_acquire(git_cred **cred, const char * /*url*/,
(datadir / "ssh_id").c_str(), nullptr);
}
void clone()
void clone(const bool cache)
{
// clang-format off
const string destination{[&cache]
{
if (cache)
{
return files::get_cachedir() / "repo";
}
return files::get_tmpdir() / "repo";
}()};
// clang-format on
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
options.fetch_opts.callbacks.credentials = cred_acquire;
check(git_clone(&_repo, _clone_url.data(),
(files::get_tmpdir() / "repo").c_str(), &options));
check(git_clone(&_repo, _clone_url.data(), destination.c_str(), &options));
}
void create_branch()

View File

@ -38,8 +38,14 @@ int cred_acquire(git_cred **cred, const char *url,
const char *username_from_url, unsigned int allowed_types,
void *payload);
// Clone the git repo.
void clone();
/*!
* @brief Clone the git repo.
*
* @param cache Clone to cache if true, to temporary dir if false.
*
* @since 0.1.0
*/
void clone(bool cache = false);
// Make a new branch for preparing the pull request.
void create_branch();