Add option to use cache dir to clone().
Preparation for caching the repository.
This commit is contained in:
parent
0f9736becd
commit
db18edd478
16
src/git.cpp
16
src/git.cpp
|
@ -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()
|
||||
|
|
10
src/git.hpp
10
src/git.hpp
|
@ -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();
|
||||
|
|
Reference in New Issue
Block a user