Skip to content

Commit b5fa4dd

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 27714c2 commit b5fa4dd

File tree

103 files changed

+1528
-1154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1528
-1154
lines changed

docs/create_markdown.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def sanitise_line(line):
2626
return line
2727

2828

29-
# Process a single subcommand, adding new subcommands found to to_process.
29+
# Process a single subcommand, adding new subcommands found to to_process.
3030
def process(args, to_process):
3131
cmd = args + ["--help"]
3232
cmd_string = " ".join(cmd)
@@ -37,7 +37,7 @@ def process(args, to_process):
3737
p = subprocess.run(cmd, capture_output=True, text=True, check=True)
3838

3939
# Write output markdown file, identifying subcommands at the same time to provide
40-
# links to the subcommand markdown files.
40+
# links to the subcommand markdown files.
4141
subcommands = []
4242
with open(filename, "w") as f:
4343
f.write(f"({filename})=\n") # Target for links.
@@ -52,7 +52,9 @@ def process(args, to_process):
5252
if match:
5353
subcommand = match.group(2)
5454
subcommand_filename = get_filename(args + [subcommand])
55-
line = match.group(1) + f"[{subcommand}]({subcommand_filename})" + match.group(3)
55+
line = (
56+
match.group(1) + f"[{subcommand}]({subcommand_filename})" + match.group(3)
57+
)
5658
subcommands.append(subcommand)
5759
elif line.startswith("SUBCOMMANDS:"):
5860
in_subcommand_section = True
@@ -74,10 +76,10 @@ def process(args, to_process):
7476

7577

7678
if __name__ == "__main__":
77-
# Modify the PATH so that git2cpp is found by name, as using a full path will cause the help
79+
# Modify the PATH so that git2cpp is found by name, as using a full path will cause the help
7880
# pages to write that full path.
79-
git2cpp_dir = Path(__file__).parent.parent / 'build'
80-
os.environ["PATH"] = f'{git2cpp_dir}{os.pathsep}{os.environ["PATH"]}'
81+
git2cpp_dir = Path(__file__).parent.parent / "build"
82+
os.environ["PATH"] = f"{git2cpp_dir}{os.pathsep}{os.environ['PATH']}"
8183

8284
to_process = [["git2cpp"]]
8385
while len(to_process) > 0:

src/main.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#include <CLI/CLI.hpp>
21
#include <cmath>
3-
#include <git2.h> // For version number only
42
#include <iostream>
53

6-
#include "utils/git_exception.hpp"
7-
#include "version.hpp"
4+
#include <CLI/CLI.hpp>
5+
#include <git2.h> // For version number only
6+
87
#include "subcommand/add_subcommand.hpp"
98
#include "subcommand/branch_subcommand.hpp"
109
#include "subcommand/checkout_subcommand.hpp"
@@ -21,12 +20,14 @@
2120
#include "subcommand/rebase_subcommand.hpp"
2221
#include "subcommand/remote_subcommand.hpp"
2322
#include "subcommand/reset_subcommand.hpp"
23+
#include "subcommand/revlist_subcommand.hpp"
24+
#include "subcommand/revparse_subcommand.hpp"
25+
#include "subcommand/rm_subcommand.hpp"
2426
#include "subcommand/stash_subcommand.hpp"
2527
#include "subcommand/status_subcommand.hpp"
2628
#include "subcommand/tag_subcommand.hpp"
27-
#include "subcommand/revparse_subcommand.hpp"
28-
#include "subcommand/revlist_subcommand.hpp"
29-
#include "subcommand/rm_subcommand.hpp"
29+
#include "utils/git_exception.hpp"
30+
#include "version.hpp"
3031

3132
int main(int argc, char** argv)
3233
{
@@ -69,7 +70,8 @@ int main(int argc, char** argv)
6970

7071
if (version->count())
7172
{
72-
std::cout << "git2cpp version " << GIT2CPP_VERSION_STRING << " (libgit2 " << LIBGIT2_VERSION << ")" << std::endl;
73+
std::cout << "git2cpp version " << GIT2CPP_VERSION_STRING << " (libgit2 " << LIBGIT2_VERSION
74+
<< ")" << std::endl;
7375
}
7476
else if (app.get_subcommands().size() == 0)
7577
{
@@ -86,7 +88,8 @@ int main(int argc, char** argv)
8688
std::cerr << e.what() << std::endl;
8789
exit_code = e.error_code();
8890
}
89-
catch (std::exception& e) {
91+
catch (std::exception& e)
92+
{
9093
std::cerr << e.what() << std::endl;
9194
exit_code = 1;
9295
}

src/subcommand/add_subcommand.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
#include "add_subcommand.hpp"
2+
13
#include <git2.h>
24

3-
#include "add_subcommand.hpp"
45
#include "../wrapper/index_wrapper.hpp"
56
#include "../wrapper/repository_wrapper.hpp"
67

7-
88
add_subcommand::add_subcommand(const libgit2_object&, CLI::App& app)
99
{
10-
auto *sub = app.add_subcommand("add", "Add file contents to the index");
10+
auto* sub = app.add_subcommand("add", "Add file contents to the index");
1111

1212
sub->add_option("<files>", m_add_files, "Files to add");
1313

@@ -16,10 +16,14 @@ add_subcommand::add_subcommand(const libgit2_object&, CLI::App& app)
1616
// sub->add_flag("-u,--update", update_flag, "");
1717
// sub->add_flag("-v,--verbose", verbose_flag, "");
1818

19-
sub->callback([this]() { this->run(); });
19+
sub->callback(
20+
[this]()
21+
{
22+
this->run();
23+
}
24+
);
2025
};
2126

22-
2327
void add_subcommand::run()
2428
{
2529
auto directory = get_current_git_path();

src/subcommand/add_subcommand.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class add_subcommand
1212
void run();
1313

1414
private:
15+
1516
bool m_all_flag = false;
1617
std::vector<std::string> m_add_files;
1718
};

src/subcommand/branch_subcommand.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
#include "../subcommand/branch_subcommand.hpp"
2+
13
#include <iostream>
24

3-
#include "../subcommand/branch_subcommand.hpp"
45
#include "../wrapper/repository_wrapper.hpp"
56

67
branch_subcommand::branch_subcommand(const libgit2_object&, CLI::App& app)
@@ -14,9 +15,18 @@ branch_subcommand::branch_subcommand(const libgit2_object&, CLI::App& app)
1415
sub->add_flag("-r,--remotes", m_remote_flag, "List or delete (if used with -d) the remote-tracking branches");
1516
sub->add_flag("-l,--list", m_list_flag, "List branches");
1617
sub->add_flag("-f,--force", m_force_flag, "Skips confirmation");
17-
sub->add_flag("--show-current", m_show_current_flag, "Print the name of the current branch. In detached HEAD state, nothing is printed.");
18+
sub->add_flag(
19+
"--show-current",
20+
m_show_current_flag,
21+
"Print the name of the current branch. In detached HEAD state, nothing is printed."
22+
);
1823

19-
sub->callback([this]() { this->run(); });
24+
sub->callback(
25+
[this]()
26+
{
27+
this->run();
28+
}
29+
);
2030
}
2131

2232
void branch_subcommand::run()

src/subcommand/checkout_subcommand.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
#include "../subcommand/checkout_subcommand.hpp"
2+
13
#include <iostream>
2-
#include <sstream>
34
#include <set>
5+
#include <sstream>
46

5-
#include "../subcommand/checkout_subcommand.hpp"
67
#include "../subcommand/status_subcommand.hpp"
78
#include "../utils/git_exception.hpp"
89
#include "../wrapper/repository_wrapper.hpp"
@@ -15,9 +16,18 @@ checkout_subcommand::checkout_subcommand(const libgit2_object&, CLI::App& app)
1516
sub->add_option("<branch>", m_branch_name, "Branch to checkout");
1617
sub->add_flag("-b", m_create_flag, "Create a new branch before checking it out");
1718
sub->add_flag("-B", m_force_create_flag, "Create a new branch or reset it if it exists before checking it out");
18-
sub->add_flag("-f, --force", m_force_checkout_flag, "When switching branches, proceed even if the index or the working tree differs from HEAD, and even if there are untracked files in the way");
19-
20-
sub->callback([this]() { this->run(); });
19+
sub->add_flag(
20+
"-f, --force",
21+
m_force_checkout_flag,
22+
"When switching branches, proceed even if the index or the working tree differs from HEAD, and even if there are untracked files in the way"
23+
);
24+
25+
sub->callback(
26+
[this]()
27+
{
28+
this->run();
29+
}
30+
);
2131
}
2232

2333
void print_no_switch(status_list_wrapper& sl)
@@ -44,7 +54,7 @@ void checkout_subcommand::run()
4454

4555
if (repo.state() != GIT_REPOSITORY_STATE_NONE)
4656
{
47-
throw std::runtime_error("Cannot checkout, repository is in unexpected state");
57+
throw std::runtime_error("Cannot checkout, repository is in unexpected state");
4858
}
4959

5060
git_checkout_options options;
@@ -112,19 +122,14 @@ void checkout_subcommand::run()
112122
}
113123
}
114124

115-
annotated_commit_wrapper checkout_subcommand::create_local_branch
116-
(
117-
repository_wrapper& repo,
118-
const std::string_view target_name,
119-
bool force
120-
)
125+
annotated_commit_wrapper
126+
checkout_subcommand::create_local_branch(repository_wrapper& repo, const std::string_view target_name, bool force)
121127
{
122128
auto branch = repo.create_branch(target_name, force);
123129
return repo.find_annotated_commit(branch);
124130
}
125131

126-
void checkout_subcommand::checkout_tree
127-
(
132+
void checkout_subcommand::checkout_tree(
128133
const repository_wrapper& repo,
129134
const annotated_commit_wrapper& target_annotated_commit,
130135
const std::string_view target_name,
@@ -135,8 +140,7 @@ void checkout_subcommand::checkout_tree
135140
throw_if_error(git_checkout_tree(repo, target_commit, &options));
136141
}
137142

138-
void checkout_subcommand::update_head
139-
(
143+
void checkout_subcommand::update_head(
140144
repository_wrapper& repo,
141145
const annotated_commit_wrapper& target_annotated_commit,
142146
const std::string_view target_name

src/subcommand/checkout_subcommand.hpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,17 @@ class checkout_subcommand
1717

1818
private:
1919

20-
annotated_commit_wrapper create_local_branch
21-
(
22-
repository_wrapper& repo,
23-
const std::string_view target_name,
24-
bool force
25-
);
20+
annotated_commit_wrapper
21+
create_local_branch(repository_wrapper& repo, const std::string_view target_name, bool force);
2622

27-
void checkout_tree
28-
(
23+
void checkout_tree(
2924
const repository_wrapper& repo,
3025
const annotated_commit_wrapper& target_annotated_commit,
3126
const std::string_view target_name,
3227
const git_checkout_options& options
3328
);
3429

35-
void update_head
36-
(
30+
void update_head(
3731
repository_wrapper& repo,
3832
const annotated_commit_wrapper& target_annotated_commit,
3933
const std::string_view target_name

src/subcommand/clone_subcommand.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
#include "../subcommand/clone_subcommand.hpp"
2+
13
#include <iostream>
24

3-
#include "../subcommand/clone_subcommand.hpp"
45
#include "../utils/credentials.hpp"
56
#include "../utils/input_output.hpp"
67
#include "../utils/progress.hpp"
@@ -13,11 +14,17 @@ clone_subcommand::clone_subcommand(const libgit2_object&, CLI::App& app)
1314
sub->add_option("<repository>", m_repository, "The (possibly remote) repository to clone from.")->required();
1415
sub->add_option("<directory>", m_directory, "The name of a new directory to clone into.");
1516
sub->add_option("--depth", m_depth, "Create a shallow clone of that depth.");
16-
// sub->add_option("--shallow-since", m_shallow_since, "<time>\ndeepen history of shallow repository based on time.");
17-
// sub->add_option("--shallow-exclude", m_shallow_exclude, "<ref>\ndeepen history of shallow clone, excluding ref");
17+
// sub->add_option("--shallow-since", m_shallow_since, "<time>\ndeepen history of shallow repository based
18+
// on time."); sub->add_option("--shallow-exclude", m_shallow_exclude, "<ref>\ndeepen history of shallow
19+
// clone, excluding ref");
1820
sub->add_flag("--bare", m_bare, "Create a bare Git repository.");
1921

20-
sub->callback([this]() { this->run(); });
22+
sub->callback(
23+
[this]()
24+
{
25+
this->run();
26+
}
27+
);
2128
}
2229

2330
void clone_subcommand::run()

src/subcommand/clone_subcommand.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
22

3-
#include <CLI/CLI.hpp>
43
#include <limits>
54

5+
#include <CLI/CLI.hpp>
6+
67
#include "../utils/common.hpp"
78

89
class clone_subcommand

src/subcommand/commit_subcommand.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1+
#include "../subcommand/commit_subcommand.hpp"
2+
13
#include <git2.h>
24
#include <unistd.h>
35

4-
#include "../subcommand/commit_subcommand.hpp"
56
#include "../utils/input_output.hpp"
67
#include "../wrapper/index_wrapper.hpp"
78
#include "../wrapper/repository_wrapper.hpp"
89

9-
1010
commit_subcommand::commit_subcommand(const libgit2_object&, CLI::App& app)
1111
{
12-
auto *sub = app.add_subcommand("commit", "Record changes to the repository");
12+
auto* sub = app.add_subcommand("commit", "Record changes to the repository");
1313

1414
sub->add_option("-m,--message", m_commit_message, "Commit message");
1515

16-
sub->callback([this]() { this->run(); });
16+
sub->callback(
17+
[this]()
18+
{
19+
this->run();
20+
}
21+
);
1722
};
1823

19-
2024
void commit_subcommand::run()
2125
{
2226
auto directory = get_current_git_path();

0 commit comments

Comments
 (0)