-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGit.h
72 lines (66 loc) · 1.38 KB
/
Git.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include "git2.h"
#include <string>
#include <filesystem>
#include <functional>
#include <iostream>
class Git
{
class Promise
{
public:
Promise& operator()(std::function<int()>&& f)
{
mFunctions.emplace_back(f);
return *this;
}
~Promise()
{
for (auto& f: mFunctions)
if (f() < 0)
{
auto err = git_error_last();
std::cout << err->message << std::endl;
if(mFailure)
mFailure();
}
}
void error(std::function<void()>&& f)
{
mFailure = f;
}
private:
std::vector<std::function<int()>> mFunctions;
std::function<void()> mFailure;
};
public :
Git();
~Git();
void init(const std::string& localpath, const std::string& url , const std::string& usr, const std::string& pwd );
void close();
void sync();
private:
git_repository* mRepository{nullptr};
struct Callbacks
{
static std::string username;
static std::string password;
//git_credential_acquire_cb
static int credential_acquire_cb(
git_credential** out,
const char* url,
const char* username_from_url,
unsigned int allowed_types,
void* payload)
{
return git_cred_userpass_plaintext_new(out,username.c_str(), password.c_str());
}
static size_t matchedCount;
//git_index_matched_path_cb
static int index_matched_path_cb(const char* path, const char* matched_pathspec, void* payload)
{
matchedCount++;
return 0;
}
};
};