forked from QuantStack/git2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_subcommand.cpp
More file actions
39 lines (29 loc) · 943 Bytes
/
add_subcommand.cpp
File metadata and controls
39 lines (29 loc) · 943 Bytes
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
#include <git2.h>
#include "add_subcommand.hpp"
#include "../wrapper/index_wrapper.hpp"
#include "../wrapper/repository_wrapper.hpp"
add_subcommand::add_subcommand(const libgit2_object&, CLI::App& app)
{
auto *sub = app.add_subcommand("add", "Add file contents to the index");
sub->add_option("files", add_files, "Files to add");
sub->add_flag("-A,--all,--no-ignore-removal", all_flag, "");
// sub->add_flag("-n,--dryrun", dryrun_flag, "");
// sub->add_flag("-u,--update", update_flag, "");
// sub->add_flag("-v,--verbose", verbose_flag, "");
sub->callback([this]() { this->run(); });
};
void add_subcommand::run()
{
auto directory = get_current_git_path();
auto bare = false;
auto repo = repository_wrapper::init(directory, bare);
index_wrapper index = repo.make_index();
if (all_flag)
{
index.add_all();
}
else
{
index.add_entries(add_files);
}
}