-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathadd_subcommand.cpp
More file actions
44 lines (35 loc) · 1011 Bytes
/
add_subcommand.cpp
File metadata and controls
44 lines (35 loc) · 1011 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
40
41
42
43
44
#include "add_subcommand.hpp"
#include <git2.h>
#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>", m_add_files, "Files to add");
sub->add_flag("-A,--all,--no-ignore-removal", m_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 repo = repository_wrapper::open(directory);
index_wrapper index = repo.make_index();
if (m_all_flag)
{
index.add_all();
index.write();
}
else
{
index.add_entries(m_add_files);
index.write();
}
}