-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathremote_wrapper.cpp
More file actions
102 lines (84 loc) · 2.64 KB
/
remote_wrapper.cpp
File metadata and controls
102 lines (84 loc) · 2.64 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "../wrapper/remote_wrapper.hpp"
#include <string>
#include <vector>
#include <git2/remote.h>
#include <git2/types.h>
#include "../utils/git_exception.hpp"
remote_wrapper::remote_wrapper(git_remote* remote)
: base_type(remote)
{
}
remote_wrapper::~remote_wrapper()
{
git_remote_free(p_resource);
p_resource = nullptr;
}
std::string_view remote_wrapper::name() const
{
const char* out = git_remote_name(*this);
return out ? std::string_view(out) : std::string_view();
}
std::string_view remote_wrapper::url() const
{
const char* out = git_remote_url(*this);
return out ? std::string_view(out) : std::string_view();
}
std::string_view remote_wrapper::pushurl() const
{
const char* out = git_remote_pushurl(*this);
return out ? std::string_view(out) : std::string_view();
}
std::vector<std::string> remote_wrapper::refspecs() const
{
git_strarray refspecs = {0};
std::vector<std::string> result;
if (git_remote_get_fetch_refspecs(&refspecs, *this) == 0)
{
for (size_t i = 0; i < refspecs.count; ++i)
{
result.emplace_back(refspecs.strings[i]);
}
git_strarray_dispose(&refspecs);
}
return result;
}
std::vector<const git_remote_head*> remote_wrapper::ls() const
{
const git_remote_head** remote_heads;
size_t remote_heads_size;
throw_if_error(git_remote_ls(&remote_heads, &remote_heads_size, *this));
std::vector<const git_remote_head*> remote_heads_vec;
for (size_t i = 0; i < remote_heads_size; i++)
{
remote_heads_vec.push_back(remote_heads[i]);
}
return remote_heads_vec;
}
// std::vector<std::string> remote_wrapper::ls() const
// {
// const git_remote_head** remote_heads;
// size_t remote_heads_size;
// throw_if_error(git_remote_ls(&remote_heads, &remote_heads_size, *this));
// std::vector<std::string> remote_branches;
// for (size_t i = 0; i < remote_heads_size; i++)
// {
// const git_remote_head* head = remote_heads[i];
// if (!head->local)
// {
// remote_branches.push_back(head->name);
// }
// }
// return remote_branches;
// }
void remote_wrapper::connect(git_direction direction, const git_remote_callbacks* callbacks)
{
throw_if_error(git_remote_connect(*this, direction, callbacks, NULL, NULL));
}
void remote_wrapper::fetch(const git_strarray* refspecs, const git_fetch_options* opts, const char* reflog_message)
{
throw_if_error(git_remote_fetch(*this, refspecs, opts, reflog_message));
}
void remote_wrapper::push(const git_strarray* refspecs, const git_push_options* opts)
{
throw_if_error(git_remote_push(*this, refspecs, opts));
}