-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrepository_wrapper.hpp
More file actions
81 lines (60 loc) · 2.81 KB
/
repository_wrapper.hpp
File metadata and controls
81 lines (60 loc) · 2.81 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
#pragma once
#include <concepts>
#include <optional>
#include <string_view>
#include <git2.h>
#include "../utils/git_exception.hpp"
#include "../wrapper/annotated_commit_wrapper.hpp"
#include "../wrapper/branch_wrapper.hpp"
#include "../wrapper/commit_wrapper.hpp"
#include "../wrapper/index_wrapper.hpp"
#include "../wrapper/object_wrapper.hpp"
#include "../wrapper/refs_wrapper.hpp"
#include "../wrapper/signature_wrapper.hpp"
#include "../wrapper/wrapper_base.hpp"
class repository_wrapper : public wrapper_base<git_repository>
{
public:
~repository_wrapper();
repository_wrapper(repository_wrapper&&) noexcept = default;
repository_wrapper& operator=(repository_wrapper&&) noexcept = default;
static repository_wrapper init(std::string_view directory, bool bare);
static repository_wrapper open(std::string_view directory);
static repository_wrapper clone(std::string_view url, std::string_view path, const git_clone_options& opts);
git_repository_state_t state() const;
// References
reference_wrapper head() const;
reference_wrapper find_reference(std::string_view ref_name) const;
std::optional<reference_wrapper> find_reference_dwim(std::string_view ref_name) const;
// Index
index_wrapper make_index();
// Branches
branch_wrapper create_branch(std::string_view name, bool force);
branch_wrapper create_branch(std::string_view name, const commit_wrapper& commit, bool force);
branch_wrapper create_branch(std::string_view name, const annotated_commit_wrapper& commit, bool force);
branch_wrapper find_branch(std::string_view name) const;
branch_iterator iterate_branches(git_branch_t type) const;
// Commits
commit_wrapper find_commit(std::string_view ref_name = "HEAD") const;
commit_wrapper find_commit(const git_oid& id) const;
void create_commit(const signature_wrapper::author_committer_signatures&, const std::string&);
// Annotated commits
annotated_commit_wrapper find_annotated_commit(const git_oid& id) const;
template <std::convertible_to<git_reference*> T>
annotated_commit_wrapper find_annotated_commit(const T& wrapper) const;
// Objects
std::optional<object_wrapper> revparse_single(std::string_view spec) const;
// Head manipulations
void set_head(std::string_view ref_name);
void set_head_detached(const annotated_commit_wrapper& commit);
void reset(const object_wrapper& target, git_reset_t reset_type, const git_checkout_options& checkout_options);
private:
repository_wrapper() = default;
};
template <std::convertible_to<git_reference*> T>
annotated_commit_wrapper repository_wrapper::find_annotated_commit(const T& wrapper) const
{
git_annotated_commit* commit;
throw_if_error(git_annotated_commit_from_ref(&commit, *this, wrapper));
return annotated_commit_wrapper(commit);
}