Skip to content

Commit 8daa41e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 0956b04 commit 8daa41e

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

src/subcommand/checkout_subcommand.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <filesystem>
44
#include <iostream>
55
#include <set>
6+
67
#include <git2/oid.h>
78

89
#include "../subcommand/status_subcommand.hpp"
@@ -16,8 +17,8 @@ checkout_subcommand::checkout_subcommand(const libgit2_object&, CLI::App& app)
1617

1718
// "-- file" lands in m_positional_args because CLI11 consumes "--" silently.
1819
sub->add_option("<tree-ish|pathspec>", m_positional_args, "Tree-ish to checkout, and/or one/many pathspec(s)");
19-
// checkout <branch>, checkout <tag>, checkout <file> ..., checkout <branch> <file> ...
20-
// Use without "--"
20+
// checkout <branch>, checkout <tag>, checkout <file> ..., checkout <branch> <file> ...
21+
// Use without "--"
2122
sub->add_flag("-b", m_create_flag, "Create a new branch before checking it out");
2223
sub->add_flag("-B", m_force_create_flag, "Create a new branch or reset it if it exists before checking it out");
2324
sub->add_flag(
@@ -85,7 +86,10 @@ void checkout_subcommand::checkout_paths(
8586
auto obj = repo.revparse_single(tree_ish);
8687
if (!obj)
8788
{
88-
throw git_exception("error: could not resolve tree-ish '" + std::string(tree_ish) + "'", git2cpp_error_code::BAD_ARGUMENT);
89+
throw git_exception(
90+
"error: could not resolve tree-ish '" + std::string(tree_ish) + "'",
91+
git2cpp_error_code::BAD_ARGUMENT
92+
);
8993
}
9094

9195
std::vector<const char*> pathspec_strings;
@@ -129,8 +133,8 @@ void checkout_subcommand::run()
129133
throw std::runtime_error("error: no branch or file specified");
130134
}
131135

132-
const std::string& target_name = m_positional_args[0]; // can be a branch or a tag
133-
const std::vector<std::string> pathspecs(m_positional_args.begin()+1, m_positional_args.end());
136+
const std::string& target_name = m_positional_args[0]; // can be a branch or a tag
137+
const std::vector<std::string> pathspecs(m_positional_args.begin() + 1, m_positional_args.end());
134138

135139
if (m_create_flag || m_force_create_flag)
136140
{
@@ -198,7 +202,10 @@ void checkout_subcommand::run()
198202
if (!std::filesystem::exists(std::filesystem::path(directory) / target_name))
199203
{
200204
// Neither a branch/tag nor a file
201-
throw git_exception("error: pathspec '" + target_name + "' did not match any file(s) known to git", git2cpp_error_code::BAD_ARGUMENT);
205+
throw git_exception(
206+
"error: pathspec '" + target_name + "' did not match any file(s) known to git",
207+
git2cpp_error_code::BAD_ARGUMENT
208+
);
202209
}
203210

204211
options.checkout_strategy = GIT_CHECKOUT_FORCE;
@@ -300,13 +307,15 @@ void checkout_subcommand::update_head(
300307

301308
if (head_was_detached)
302309
{
303-
// Only print "Previous HEAD position..." if HEAD was already detached before and if there is an actual checkout
310+
// Only print "Previous HEAD position..." if HEAD was already detached before and if there is an
311+
// actual checkout
304312
auto new_head_commit = repo.find_commit("HEAD");
305313
if (!git_oid_equal(&previous_head_commit.oid(), &new_head_commit.oid()))
306314
{
307315
std::string previous_head_message;
308-
previous_head_message = "Previous HEAD position was " + std::string(previous_head_commit.commit_oid_tostr().substr(0,7)) +
309-
" " + previous_head_commit.summary();
316+
previous_head_message = "Previous HEAD position was "
317+
+ std::string(previous_head_commit.commit_oid_tostr().substr(0, 7)) + " "
318+
+ previous_head_commit.summary();
310319
std::cout << previous_head_message << std::endl;
311320
}
312321
}
@@ -321,10 +330,9 @@ void checkout_subcommand::update_head(
321330
std::cout << std::endl;
322331

323332
// TODO: add to the following when the switch subcommand is implemented:
324-
// std::cout << "If you want to create a new branch to retain commits you create, you may" << std::endl;
325-
// std::cout << "do so (now or later) by using -c with the switch command. Example:" << std::endl;
326-
// std::cout << " git switch -c <new-branch-name>" << std::endl;
327-
// std::cout << std::endl;
333+
// std::cout << "If you want to create a new branch to retain commits you create, you may" <<
334+
// std::endl; std::cout << "do so (now or later) by using -c with the switch command. Example:" <<
335+
// std::endl; std::cout << " git switch -c <new-branch-name>" << std::endl; std::cout << std::endl;
328336
// std::cout << "Or undo this operation with:" << std::endl;
329337
// std::cout << std::endl;
330338
// std::cout << " git switch -" << std::endl;

0 commit comments

Comments
 (0)