11#pragma once
2+ #include < cppgit2/bitmask_operators.hpp>
23#include < cppgit2/data_buffer.hpp>
34#include < cppgit2/fetch.hpp>
45#include < cppgit2/indexer.hpp>
@@ -30,6 +31,56 @@ class remote : public libgit2_api {
3031 // is connected to the remote host.
3132 bool is_connected () const ;
3233
34+ // Remote creation options flags
35+ enum class create_flag {
36+ // Ignore the repository apply.insteadOf configuration
37+ skip_insteadof = (1 << 0 ),
38+ // Don't build a fetchspec from the name if none is set
39+ default_fetchspec = (1 << 1 )
40+ };
41+
42+ class create_options : public libgit2_api {
43+ public:
44+ create_options () : c_ptr_(nullptr ) {
45+ auto ret =
46+ git_remote_create_init_options (&default_options_, GIT_REMOTE_CREATE_OPTIONS_VERSION);
47+ c_ptr_ = &default_options_;
48+ if (ret != 0 )
49+ throw git_exception ();
50+ }
51+
52+ create_options (git_remote_create_options *c_ptr) : c_ptr_(c_ptr) {}
53+
54+ // Version
55+ unsigned int version () const { return c_ptr_->version ; }
56+ void set_version (unsigned int version) { c_ptr_->version = version; }
57+
58+ // Repository
59+ class repository repository () const ;
60+ void set_repository (const class repository &repo);
61+
62+ // Name
63+ std::string name () const { return c_ptr_->name ? std::string (c_ptr_->name ) : " " ; }
64+ void set_name (const std::string &name) { c_ptr_->name = name.c_str (); }
65+
66+ // Fetchspec
67+ std::string fetchspec () const { return c_ptr_->fetchspec ? std::string (c_ptr_->fetchspec ) : " " ; }
68+ void set_fetchspec (const std::string &fetchspec) { c_ptr_->fetchspec = fetchspec.c_str (); }
69+
70+ // Flags
71+ create_flag flags () const { return static_cast <create_flag>(c_ptr_->flags ); }
72+ void set_flags (const create_flag &flags) {
73+ c_ptr_->flags = static_cast <unsigned int >(flags);
74+ }
75+
76+ // Access libgit2 C ptr
77+ const git_remote_create_options *c_ptr () const { return c_ptr_; }
78+
79+ private:
80+ git_remote_create_options *c_ptr_;
81+ git_remote_create_options default_options_;
82+ };
83+
3384 // Create a copy of an existing remote.
3485 // All internal strings are also duplicated.
3586 // Callbacks are not duplicated.
@@ -43,6 +94,11 @@ class remote : public libgit2_api {
4394 // values (such as instead of url substitutions).
4495 static remote create_detached_remote (const std::string &url);
4596
97+ // Create a remote, with options.
98+ // This function allows more fine-grained control over the remote creation.
99+ static remote create_remote (const std::string &url,
100+ const create_options &options = create_options());
101+
46102 // Retrieve the name of the remote's default branch
47103 // This function must only be called after connecting.
48104 data_buffer default_branch () const ;
@@ -117,5 +173,6 @@ class remote : public libgit2_api {
117173 ownership owner_;
118174 git_remote *c_ptr_;
119175};
176+ ENABLE_BITMASK_OPERATORS (remote::create_flag);
120177
121178} // namespace cppgit2
0 commit comments