Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 16, 2026
commit b5fa4dd644c6a3074f4096344ec6b4749c3f0b58
14 changes: 8 additions & 6 deletions docs/create_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def sanitise_line(line):
return line


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

# Write output markdown file, identifying subcommands at the same time to provide
# links to the subcommand markdown files.
# links to the subcommand markdown files.
subcommands = []
with open(filename, "w") as f:
f.write(f"({filename})=\n") # Target for links.
Expand All @@ -52,7 +52,9 @@ def process(args, to_process):
if match:
subcommand = match.group(2)
subcommand_filename = get_filename(args + [subcommand])
line = match.group(1) + f"[{subcommand}]({subcommand_filename})" + match.group(3)
line = (
match.group(1) + f"[{subcommand}]({subcommand_filename})" + match.group(3)
)
subcommands.append(subcommand)
elif line.startswith("SUBCOMMANDS:"):
in_subcommand_section = True
Expand All @@ -74,10 +76,10 @@ def process(args, to_process):


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

to_process = [["git2cpp"]]
while len(to_process) > 0:
Expand Down
21 changes: 12 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <CLI/CLI.hpp>
#include <cmath>
#include <git2.h> // For version number only
#include <iostream>

#include "utils/git_exception.hpp"
#include "version.hpp"
#include <CLI/CLI.hpp>
#include <git2.h> // For version number only

#include "subcommand/add_subcommand.hpp"
#include "subcommand/branch_subcommand.hpp"
#include "subcommand/checkout_subcommand.hpp"
Expand All @@ -21,12 +20,14 @@
#include "subcommand/rebase_subcommand.hpp"
#include "subcommand/remote_subcommand.hpp"
#include "subcommand/reset_subcommand.hpp"
#include "subcommand/revlist_subcommand.hpp"
#include "subcommand/revparse_subcommand.hpp"
#include "subcommand/rm_subcommand.hpp"
#include "subcommand/stash_subcommand.hpp"
#include "subcommand/status_subcommand.hpp"
#include "subcommand/tag_subcommand.hpp"
#include "subcommand/revparse_subcommand.hpp"
#include "subcommand/revlist_subcommand.hpp"
#include "subcommand/rm_subcommand.hpp"
#include "utils/git_exception.hpp"
#include "version.hpp"

int main(int argc, char** argv)
{
Expand Down Expand Up @@ -69,7 +70,8 @@ int main(int argc, char** argv)

if (version->count())
{
std::cout << "git2cpp version " << GIT2CPP_VERSION_STRING << " (libgit2 " << LIBGIT2_VERSION << ")" << std::endl;
std::cout << "git2cpp version " << GIT2CPP_VERSION_STRING << " (libgit2 " << LIBGIT2_VERSION
<< ")" << std::endl;
}
else if (app.get_subcommands().size() == 0)
{
Expand All @@ -86,7 +88,8 @@ int main(int argc, char** argv)
std::cerr << e.what() << std::endl;
exit_code = e.error_code();
}
catch (std::exception& e) {
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
exit_code = 1;
}
Expand Down
14 changes: 9 additions & 5 deletions src/subcommand/add_subcommand.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "add_subcommand.hpp"

#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");
auto* sub = app.add_subcommand("add", "Add file contents to the index");

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

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

sub->callback([this]() { this->run(); });
sub->callback(
[this]()
{
this->run();
}
);
};


void add_subcommand::run()
{
auto directory = get_current_git_path();
Expand Down
1 change: 1 addition & 0 deletions src/subcommand/add_subcommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class add_subcommand
void run();

private:

bool m_all_flag = false;
std::vector<std::string> m_add_files;
};
16 changes: 13 additions & 3 deletions src/subcommand/branch_subcommand.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../subcommand/branch_subcommand.hpp"

#include <iostream>

#include "../subcommand/branch_subcommand.hpp"
#include "../wrapper/repository_wrapper.hpp"

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

sub->callback([this]() { this->run(); });
sub->callback(
[this]()
{
this->run();
}
);
}

void branch_subcommand::run()
Expand Down
36 changes: 20 additions & 16 deletions src/subcommand/checkout_subcommand.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "../subcommand/checkout_subcommand.hpp"

#include <iostream>
#include <sstream>
#include <set>
#include <sstream>

#include "../subcommand/checkout_subcommand.hpp"
#include "../subcommand/status_subcommand.hpp"
#include "../utils/git_exception.hpp"
#include "../wrapper/repository_wrapper.hpp"
Expand All @@ -15,9 +16,18 @@ checkout_subcommand::checkout_subcommand(const libgit2_object&, CLI::App& app)
sub->add_option("<branch>", m_branch_name, "Branch to checkout");
sub->add_flag("-b", m_create_flag, "Create a new branch before checking it out");
sub->add_flag("-B", m_force_create_flag, "Create a new branch or reset it if it exists before checking it out");
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");

sub->callback([this]() { this->run(); });
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"
);

sub->callback(
[this]()
{
this->run();
}
);
}

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

if (repo.state() != GIT_REPOSITORY_STATE_NONE)
{
throw std::runtime_error("Cannot checkout, repository is in unexpected state");
throw std::runtime_error("Cannot checkout, repository is in unexpected state");
}

git_checkout_options options;
Expand Down Expand Up @@ -112,19 +122,14 @@ void checkout_subcommand::run()
}
}

annotated_commit_wrapper checkout_subcommand::create_local_branch
(
repository_wrapper& repo,
const std::string_view target_name,
bool force
)
annotated_commit_wrapper
checkout_subcommand::create_local_branch(repository_wrapper& repo, const std::string_view target_name, bool force)
{
auto branch = repo.create_branch(target_name, force);
return repo.find_annotated_commit(branch);
}

void checkout_subcommand::checkout_tree
(
void checkout_subcommand::checkout_tree(
const repository_wrapper& repo,
const annotated_commit_wrapper& target_annotated_commit,
const std::string_view target_name,
Expand All @@ -135,8 +140,7 @@ void checkout_subcommand::checkout_tree
throw_if_error(git_checkout_tree(repo, target_commit, &options));
}

void checkout_subcommand::update_head
(
void checkout_subcommand::update_head(
repository_wrapper& repo,
const annotated_commit_wrapper& target_annotated_commit,
const std::string_view target_name
Expand Down
14 changes: 4 additions & 10 deletions src/subcommand/checkout_subcommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@ class checkout_subcommand

private:

annotated_commit_wrapper create_local_branch
(
repository_wrapper& repo,
const std::string_view target_name,
bool force
);
annotated_commit_wrapper
create_local_branch(repository_wrapper& repo, const std::string_view target_name, bool force);

void checkout_tree
(
void checkout_tree(
const repository_wrapper& repo,
const annotated_commit_wrapper& target_annotated_commit,
const std::string_view target_name,
const git_checkout_options& options
);

void update_head
(
void update_head(
repository_wrapper& repo,
const annotated_commit_wrapper& target_annotated_commit,
const std::string_view target_name
Expand Down
15 changes: 11 additions & 4 deletions src/subcommand/clone_subcommand.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../subcommand/clone_subcommand.hpp"

#include <iostream>

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

sub->callback([this]() { this->run(); });
sub->callback(
[this]()
{
this->run();
}
);
}

void clone_subcommand::run()
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/clone_subcommand.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <CLI/CLI.hpp>
#include <limits>

#include <CLI/CLI.hpp>

#include "../utils/common.hpp"

class clone_subcommand
Expand Down
14 changes: 9 additions & 5 deletions src/subcommand/commit_subcommand.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#include "../subcommand/commit_subcommand.hpp"

#include <git2.h>
#include <unistd.h>

#include "../subcommand/commit_subcommand.hpp"
#include "../utils/input_output.hpp"
#include "../wrapper/index_wrapper.hpp"
#include "../wrapper/repository_wrapper.hpp"


commit_subcommand::commit_subcommand(const libgit2_object&, CLI::App& app)
{
auto *sub = app.add_subcommand("commit", "Record changes to the repository");
auto* sub = app.add_subcommand("commit", "Record changes to the repository");

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

sub->callback([this]() { this->run(); });
sub->callback(
[this]()
{
this->run();
}
);
};


void commit_subcommand::run()
{
auto directory = get_current_git_path();
Expand Down
1 change: 1 addition & 0 deletions src/subcommand/commit_subcommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ class commit_subcommand
void run();

private:

std::string m_commit_message;
};
Loading
Loading