You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 19, 2021. It is now read-only.
`cppgit2` is a `libgit2` wrapper library for use in modern C++ `( >= C++11)`. See the [Build and Integration](#build-and-integration) section for details on how to build and integrate `cppgit2` in your projects.
18
+
`cppgit2` is a `libgit2` wrapper library for use in modern C++ `( >= C++11)`. See the [Build and Integration](#build-and-integration) section for details on how to build and integrate `cppgit2` in your projects.
19
19
20
-
<palign="center">
21
-
<imgsrc="img/init_add_commit.png"/>
22
-
</p>
20
+
```cpp
21
+
// Create new repo
22
+
std::string repo_name = "my_project";
23
+
auto repo = repository::init(repo_name, false);
24
+
25
+
// Write README file
26
+
std::string file_name = "README.md";
27
+
auto readme = std::ofstream(repo_name + "/" + file_name);
28
+
readme << "Hello, World!\n";
29
+
readme.close();
30
+
31
+
// Stage README.md
32
+
auto index = repo.index();
33
+
index.add_entry_by_path(file_name);
34
+
index.write();
35
+
36
+
// Prepare signatures
37
+
auto author = signature("foobar", "foo.bar@baz.com");
**NOTE**: This also builds `libgit2` from source. `libgit2` is a submodule in the `ext/` directory that points to a stable release commit, e.g., [v0.99.0](https://github.com/libgit2/libgit2/releases/tag/v0.99.0).
51
73
@@ -83,7 +105,7 @@ For integration in your projects,
83
105
* Add `build/include` to your `include_directories`
84
106
* Add `build/lib` to your `link_directories`
85
107
* Build your application, linking with `cppgit2`
86
-
* Add `build/lib` to your `LD_LIBRARY_PATH` to load the shared libraries at runtime.
108
+
* Add `build/lib` to your `LD_LIBRARY_PATH` to load the shared libraries at runtime.
This section presents some simple examples illustrating various `cppgit2` features. You can find the full set of available examples in the `/samples` directory. Samples are still a work-in-progress. Pull requests are welcome here.
133
+
This section presents some simple examples illustrating various `cppgit2` features. You can find the full set of available examples in the `/samples` directory. Samples are still a work-in-progress. Pull requests are welcome here.
112
134
113
135
### Initialize a new repository (`git init`)
114
136
115
-
To initialize a new repository, simply call `repository::init`.
137
+
To initialize a new repository, simply call `repository::init`.
116
138
117
139
```cpp
118
140
#include<cppgit2/repository.hpp>
@@ -123,11 +145,11 @@ int main() {
123
145
}
124
146
```
125
147
126
-
If you want to create a bare repository, set the second argument to `true`.
148
+
If you want to create a bare repository, set the second argument to `true`.
127
149
128
150
### Clone a repository and checkout specific branch (`git clone --branch`)
129
151
130
-
Let's say you want to clone a repository and checkout a specific branch. Construct an `options` object using `clone::options`, set the checkout branch name, and then use `repository::clone` to clone the repository.
152
+
Let's say you want to clone a repository and checkout a specific branch. Construct an `options` object using `clone::options`, set the checkout branch name, and then use `repository::clone` to clone the repository.
`libgit2` sometimes allocates memory and returns pointers to data structures that are owned by the user (required to be free'd by the user), and at other times returns a pointer to memory that is managed by the `libgit2` layer.
717
+
`libgit2` sometimes allocates memory and returns pointers to data structures that are owned by the user (required to be free'd by the user), and at other times returns a pointer to memory that is managed by the `libgit2` layer.
696
718
697
719
To properly cleanup memory that is owned by the user, use the `ownership` enum to explicitly specify the ownership when wrapping.
698
720
699
721
```cpp
700
722
cppgit2::tree tree1(&tree_cptr, ownership::user);
701
723
```
702
724
703
-
If the pointer being wrapped is owned by the user, the class destructor will call `git_<type>_free` on the pointer and clean up properly. If you specify the ownership as `ownership::libgit2`, the pointer is left alone.
725
+
If the pointer being wrapped is owned by the user, the class destructor will call `git_<type>_free` on the pointer and clean up properly. If you specify the ownership as `ownership::libgit2`, the pointer is left alone.
0 commit comments