|
1 | 1 | #include <git2.h> |
2 | | -#include <git2/buffer.h> |
3 | | -#include <git2/diff.h> |
4 | 2 | #include <optional> |
5 | 3 | #include <termcolor/termcolor.hpp> |
6 | 4 |
|
@@ -61,17 +59,38 @@ void diff_subcommand::print_stats(const diff_wrapper& diff, bool use_colour) |
61 | 59 | git_diff_stats_format_t format; |
62 | 60 | if (m_stat_flag) |
63 | 61 | { |
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 | + } |
65 | 70 | } |
66 | | - if (m_shortstat_flag) |
| 71 | + else if (m_shortstat_flag) |
67 | 72 | { |
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 | + } |
69 | 81 | } |
70 | | - if (m_numstat_flag) |
| 82 | + else if (m_numstat_flag) |
71 | 83 | { |
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 | + } |
73 | 92 | } |
74 | | - if (m_summary_flag) |
| 93 | + else if (m_summary_flag) |
75 | 94 | { |
76 | 95 | format = GIT_DIFF_STATS_INCLUDE_SUMMARY; |
77 | 96 | } |
@@ -120,15 +139,15 @@ void diff_subcommand::print_stats(const diff_wrapper& diff, bool use_colour) |
120 | 139 |
|
121 | 140 | 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) |
122 | 141 | { |
123 | | - bool* use_colour = reinterpret_cast<bool*>(payload); |
| 142 | + bool use_colour = reinterpret_cast<bool*>(payload); |
124 | 143 |
|
125 | 144 | // Only print origin for context/addition/deletion lines |
126 | 145 | // For other line types, content already includes everything |
127 | 146 | bool print_origin = (line->origin == GIT_DIFF_LINE_CONTEXT || |
128 | 147 | line->origin == GIT_DIFF_LINE_ADDITION || |
129 | 148 | line->origin == GIT_DIFF_LINE_DELETION); |
130 | 149 |
|
131 | | - if (*use_colour) |
| 150 | + if (use_colour) |
132 | 151 | { |
133 | 152 | switch (line->origin) { |
134 | 153 | case GIT_DIFF_LINE_ADDITION: std::cout << termcolor::green; break; |
@@ -245,13 +264,20 @@ void diff_subcommand::run() |
245 | 264 | git_diff_options_init(&diffopts, GIT_DIFF_OPTIONS_VERSION); |
246 | 265 |
|
247 | 266 | bool use_colour = false; |
248 | | - if (m_colour_flag) |
| 267 | + if (m_no_colour_flag) |
249 | 268 | { |
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 | + } |
251 | 277 | } |
252 | | - if (m_no_colour_flag) |
| 278 | + else if (m_colour_flag) |
253 | 279 | { |
254 | | - use_colour = false; |
| 280 | + use_colour = true; |
255 | 281 | } |
256 | 282 |
|
257 | 283 | if (m_no_index_flag) |
|
0 commit comments