aboutsummaryrefslogtreecommitdiff
path: root/src/GitRepository.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/GitRepository.cpp')
-rw-r--r--src/GitRepository.cpp104
1 files changed, 0 insertions, 104 deletions
diff --git a/src/GitRepository.cpp b/src/GitRepository.cpp
deleted file mode 100644
index 7818bdb..0000000
--- a/src/GitRepository.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-#include "../include/GitRepository.hpp"
-#include "../include/Dependency.hpp"
-#include <git2.h>
-#include <string>
-#include <cassert>
-
-using namespace std;
-
-static bool libgitInitialized = false;
-
-namespace sibs
-{
- void gitInit()
- {
- if(!libgitInitialized)
- {
- libgitInitialized = true;
- // TODO: Call git_libgit2_shutdown in destructor? dont really need to do that though
- git_libgit2_init();
- }
- }
-
- Result<bool> buildGitError(int error, const string &errorPrefix)
- {
- const git_error *e = giterr_last();
- string errMsg = errorPrefix;
- errMsg += ": ";
- errMsg += to_string(error);
- errMsg += "/";
- errMsg += to_string(e->klass);
- errMsg += ": ";
- errMsg += e->message;
- return Result<bool>::Err(errMsg, error);
- }
-
- Result<bool> GitRepository::clone(GitDependency *gitDependency, const FileString &repoDirPath)
- {
- // TODO: Use git dependency revision when cloning
- gitInit();
- git_repository *repo;
- git_clone_options options = GIT_CLONE_OPTIONS_INIT;
- options.checkout_branch = gitDependency->branch.c_str();
- int error = git_clone(&repo, gitDependency->url.c_str(), toUtf8(repoDirPath).c_str(), &options);
- if(error != 0)
- return buildGitError(error, "Failed to clone git repository");
-
- git_repository_free(repo);
- return Result<bool>::Ok(true);
- }
-
- Result<bool> GitRepository::pull(GitDependency *gitDependency, const FileString &repoDirPath)
- {
- gitInit();
- int error;
-
- git_repository *repo;
- error = git_repository_open(&repo, toUtf8(repoDirPath).c_str());
- if(error != 0)
- return buildGitError(error, "Failed to open git repository");
-
- git_remote *remote;
- error = git_remote_lookup(&remote, repo, "origin");
- if(error != 0)
- return buildGitError(error, "Failed to do remote lookup for git repository");
-
- // TODO: Setup option to be able to use callback for progress (for output in console) and handling credentials
- error = git_remote_fetch(remote, NULL, NULL, "pull");
- if(error != 0)
- {
- Result<bool> err = buildGitError(error, "Failed to do remote fetch for git repository");
- git_remote_free(remote);
- git_repository_free(repo);
- return err;
- }
-
- git_reference *ref;
- error = git_reference_dwim(&ref, repo, gitDependency->branch.c_str());
- if(error != 0)
- {
- Result<bool> err = buildGitError(error, "Failed to do reference lookup for git repository");
- git_remote_free(remote);
- git_repository_free(repo);
- return err;
- }
-
- git_annotated_commit *annotatedCommit;
- error = git_annotated_commit_from_ref(&annotatedCommit, repo, ref);
- if(error != 0)
- {
- Result<bool> err = buildGitError(error, "Failed to get commit from ref");
- git_annotated_commit_free(annotatedCommit);
- git_remote_free(remote);
- git_repository_free(repo);
- return err;
- }
-
- assert(false);
-
- git_annotated_commit_free(annotatedCommit);
- git_remote_free(remote);
- git_repository_free(repo);
- return Result<bool>::Ok(true);
- }
-}