Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit 92367f6

Browse files
committed
Added remote::connect
1 parent 37b7f96 commit 92367f6

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,8 +1233,8 @@ The project is available under the [MIT](https://opensource.org/licenses/MIT) li
12331233
| --- | --- |
12341234
| `git_remote_add_fetch` | `repository::add_fetch_refspec_to_remote` |
12351235
| `git_remote_add_push` | `repository::add_push_refspec_to_remote` |
1236-
| `git_remote_autotag` | **Not Implemented** |
1237-
| `git_remote_connect` | **Not Implemented** |
1236+
| `git_remote_autotag` | `remote::autotag_option` |
1237+
| `git_remote_connect` | `remote::connect` |
12381238
| `git_remote_connected` | `remote::is_connected` |
12391239
| `git_remote_create` | `repository::create_remote` |
12401240
| `git_remote_create_anonymous` | `repository::create_anonymous_remote` |

include/cppgit2/remote.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <cppgit2/bitmask_operators.hpp>
3+
#include <cppgit2/connection_direction.hpp>
34
#include <cppgit2/data_buffer.hpp>
45
#include <cppgit2/fetch.hpp>
56
#include <cppgit2/indexer.hpp>
@@ -31,6 +32,35 @@ class remote : public libgit2_api {
3132
// is connected to the remote host.
3233
bool is_connected() const;
3334

35+
class callbacks : public libgit2_api {
36+
public:
37+
callbacks() : c_ptr_(nullptr) {
38+
auto ret = git_remote_init_callbacks(&default_options_,
39+
GIT_REMOTE_CALLBACKS_VERSION);
40+
c_ptr_ = &default_options_;
41+
if (ret != 0)
42+
throw git_exception();
43+
}
44+
45+
callbacks(git_remote_callbacks *c_ptr) : c_ptr_(c_ptr) {}
46+
47+
// Access libgit2 C ptr
48+
const git_remote_callbacks *c_ptr() const { return c_ptr_; }
49+
50+
private:
51+
git_remote_callbacks *c_ptr_;
52+
git_remote_callbacks default_options_;
53+
};
54+
55+
// Open a connection to a remote
56+
// The transport is selected based on the URL. The direction argument is due
57+
// to a limitation of the git protocol (over TCP or SSH) which starts up a
58+
// specific binary which can only do the one or the other.
59+
void connect(connection_direction direction,
60+
const callbacks &remote_callbacks = callbacks(),
61+
const proxy::options &proxy_options = proxy::options(),
62+
const strarray &custom_headers = strarray(nullptr));
63+
3464
// Remote creation options flags
3565
enum class create_flag {
3666
// Ignore the repository apply.insteadOf configuration

src/remote.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ fetch::options::autotag remote::autotag_option() {
1717

1818
bool remote::is_connected() const { return git_remote_connected(c_ptr_); }
1919

20+
void remote::connect(connection_direction direction,
21+
const callbacks &remote_callbacks,
22+
const proxy::options &proxy_options,
23+
const strarray &custom_headers) {
24+
if (git_remote_connect(c_ptr_, static_cast<git_direction>(direction),
25+
remote_callbacks.c_ptr(), proxy_options.c_ptr(),
26+
custom_headers.c_ptr()))
27+
throw git_exception();
28+
}
29+
2030
cppgit2::repository remote::create_options::repository() const {
2131
return cppgit2::repository(c_ptr_->repository);
2232
}

0 commit comments

Comments
 (0)