Skip to content

Commit 5879159

Browse files
committed
address review comments
1 parent be2f309 commit 5879159

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

src/subcommand/checkout_subcommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void checkout_subcommand::run()
2424

2525
if (repo.state() != GIT_REPOSITORY_STATE_NONE)
2626
{
27-
std::runtime_error("Cannot checkout, repository is in unexpected state");
27+
throw std::runtime_error("Cannot checkout, repository is in unexpected state");
2828
}
2929

3030
git_checkout_options options;

src/subcommand/diff_subcommand.cpp

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include <git2.h>
2-
#include <git2/buffer.h>
3-
#include <git2/diff.h>
42
#include <optional>
53
#include <termcolor/termcolor.hpp>
64

@@ -61,17 +59,38 @@ void diff_subcommand::print_stats(const diff_wrapper& diff, bool use_colour)
6159
git_diff_stats_format_t format;
6260
if (m_stat_flag)
6361
{
64-
format = GIT_DIFF_STATS_FULL;
62+
if (m_shortstat_flag || m_numstat_flag || m_summary_flag)
63+
{
64+
throw git_exception("Only one of --stat, --shortstat, --numstat and --summary should be provided.", git2cpp_error_code::BAD_ARGUMENT);
65+
}
66+
else
67+
{
68+
format = GIT_DIFF_STATS_FULL;
69+
}
6570
}
66-
if (m_shortstat_flag)
71+
else if (m_shortstat_flag)
6772
{
68-
format = GIT_DIFF_STATS_SHORT;
73+
if (m_numstat_flag || m_summary_flag)
74+
{
75+
throw git_exception("Only one of --stat, --shortstat, --numstat and --summary should be provided.", git2cpp_error_code::BAD_ARGUMENT);
76+
}
77+
else
78+
{
79+
format = GIT_DIFF_STATS_SHORT;
80+
}
6981
}
70-
if (m_numstat_flag)
82+
else if (m_numstat_flag)
7183
{
72-
format = GIT_DIFF_STATS_NUMBER;
84+
if (m_summary_flag)
85+
{
86+
throw git_exception("Only one of --stat, --shortstat, --numstat and --summary should be provided.", git2cpp_error_code::BAD_ARGUMENT);
87+
}
88+
else
89+
{
90+
format = GIT_DIFF_STATS_NUMBER;
91+
}
7392
}
74-
if (m_summary_flag)
93+
else if (m_summary_flag)
7594
{
7695
format = GIT_DIFF_STATS_INCLUDE_SUMMARY;
7796
}
@@ -120,15 +139,15 @@ void diff_subcommand::print_stats(const diff_wrapper& diff, bool use_colour)
120139

121140
static int colour_printer([[maybe_unused]] const git_diff_delta* delta, [[maybe_unused]] const git_diff_hunk* hunk, const git_diff_line* line, void* payload)
122141
{
123-
bool* use_colour = reinterpret_cast<bool*>(payload);
142+
bool use_colour = reinterpret_cast<bool*>(payload);
124143

125144
// Only print origin for context/addition/deletion lines
126145
// For other line types, content already includes everything
127146
bool print_origin = (line->origin == GIT_DIFF_LINE_CONTEXT ||
128147
line->origin == GIT_DIFF_LINE_ADDITION ||
129148
line->origin == GIT_DIFF_LINE_DELETION);
130149

131-
if (*use_colour)
150+
if (use_colour)
132151
{
133152
switch (line->origin) {
134153
case GIT_DIFF_LINE_ADDITION: std::cout << termcolor::green; break;
@@ -245,13 +264,20 @@ void diff_subcommand::run()
245264
git_diff_options_init(&diffopts, GIT_DIFF_OPTIONS_VERSION);
246265

247266
bool use_colour = false;
248-
if (m_colour_flag)
267+
if (m_no_colour_flag)
249268
{
250-
use_colour = true;
269+
if (m_colour_flag)
270+
{
271+
throw git_exception("Only one of --color and --no-color should be provided.", git2cpp_error_code::BAD_ARGUMENT);
272+
}
273+
else
274+
{
275+
use_colour = false;
276+
}
251277
}
252-
if (m_no_colour_flag)
278+
else if (m_colour_flag)
253279
{
254-
use_colour = false;
280+
use_colour = true;
255281
}
256282

257283
if (m_no_index_flag)

src/utils/common.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#include <filesystem>
22
#include <iostream>
33
#include <fstream>
4+
#include <sstream>
45
#include <unistd.h>
56
#include <map>
67

7-
#include <git2.h>
8-
98
#include "common.hpp"
109
#include "git_exception.hpp"
1110

src/wrapper/repository_wrapper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <algorithm>
22
#include <fstream>
3-
#include <git2/diff.h>
43
#include <iostream>
54

65
#include "../utils/git_exception.hpp"

src/wrapper/repository_wrapper.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <concepts>
4-
#include <git2/types.h>
54
#include <optional>
65
#include <string_view>
76

0 commit comments

Comments
 (0)