This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathapply.hpp
More file actions
68 lines (55 loc) · 1.91 KB
/
Copy pathapply.hpp
File metadata and controls
68 lines (55 loc) · 1.91 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
#pragma once
#include <cppgit2/bitmask_operators.hpp>
#include <cppgit2/diff.hpp>
#include <cppgit2/git_exception.hpp>
#include <cppgit2/libgit2_api.hpp>
#include <cppgit2/ownership.hpp>
#include <functional>
#include <git2.h>
namespace cppgit2 {
class apply : public libgit2_api {
public:
// Possible application locations for git_apply
enum class location {
// Apply the patch to the workdir, leaving the index untouched.
// This is the equivalent of `git apply` with no location argument.
workdir = 0,
// Apply the patch to the index, leaving the working directory
// untouched. This is the equivalent of `git apply --cached
index = 1,
// Apply the patch to both the working directory and the index.
// This is the equivalent of `git apply --index`.
both = 2
};
class options : public libgit2_api {
public:
// Default construct apply::options
options() {
if (git_apply_options_init(&default_options_, GIT_APPLY_OPTIONS_VERSION))
throw git_exception();
c_ptr_ = &default_options_;
}
// Construct from libgit2 C ptr
options(git_apply_options *c_ptr) : c_ptr_(c_ptr) {}
// Version
unsigned int version() const { return c_ptr_->version; }
void set_version(unsigned int value) { c_ptr_->version = value; }
// Flags controlling the behavior of git_apply
enum class flag {
// Don't actually make changes, just test that the patch applies.
// This is the equivalent of `git apply --check`.
check = (1 << 0)
};
flag flags() const { return static_cast<flag>(c_ptr_->flags); }
void set_flags(flag flag) {
c_ptr_->flags = static_cast<unsigned int>(flag);
}
// Access libgit2 C ptr
const git_apply_options *c_ptr() const { return c_ptr_; }
private:
git_apply_options *c_ptr_;
git_apply_options default_options_;
};
};
ENABLE_BITMASK_OPERATORS(apply::options::flag);
}; // namespace cppgit2