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
Next Next commit
address review comments
  • Loading branch information
SandrineP committed Feb 6, 2026
commit 5879159e7e4d51fb95de79285141c4bc6c6652a1
2 changes: 1 addition & 1 deletion src/subcommand/checkout_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void checkout_subcommand::run()

if (repo.state() != GIT_REPOSITORY_STATE_NONE)
{
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
54 changes: 40 additions & 14 deletions src/subcommand/diff_subcommand.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <git2.h>
#include <git2/buffer.h>
#include <git2/diff.h>
#include <optional>
#include <termcolor/termcolor.hpp>

Expand Down Expand Up @@ -61,17 +59,38 @@ void diff_subcommand::print_stats(const diff_wrapper& diff, bool use_colour)
git_diff_stats_format_t format;
if (m_stat_flag)
{
format = GIT_DIFF_STATS_FULL;
if (m_shortstat_flag || m_numstat_flag || m_summary_flag)
{
throw git_exception("Only one of --stat, --shortstat, --numstat and --summary should be provided.", git2cpp_error_code::BAD_ARGUMENT);
}
else
{
format = GIT_DIFF_STATS_FULL;
}
}
if (m_shortstat_flag)
else if (m_shortstat_flag)
{
format = GIT_DIFF_STATS_SHORT;
if (m_numstat_flag || m_summary_flag)
{
throw git_exception("Only one of --stat, --shortstat, --numstat and --summary should be provided.", git2cpp_error_code::BAD_ARGUMENT);
}
else
{
format = GIT_DIFF_STATS_SHORT;
}
}
if (m_numstat_flag)
else if (m_numstat_flag)
{
format = GIT_DIFF_STATS_NUMBER;
if (m_summary_flag)
{
throw git_exception("Only one of --stat, --shortstat, --numstat and --summary should be provided.", git2cpp_error_code::BAD_ARGUMENT);
}
else
{
format = GIT_DIFF_STATS_NUMBER;
}
}
if (m_summary_flag)
else if (m_summary_flag)
{
format = GIT_DIFF_STATS_INCLUDE_SUMMARY;
}
Comment thread
JohanMabille marked this conversation as resolved.
Expand Down Expand Up @@ -120,15 +139,15 @@ void diff_subcommand::print_stats(const diff_wrapper& diff, bool use_colour)

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)
{
bool* use_colour = reinterpret_cast<bool*>(payload);
bool use_colour = reinterpret_cast<bool*>(payload);
Comment thread
SandrineP marked this conversation as resolved.
Outdated

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

if (*use_colour)
if (use_colour)
{
switch (line->origin) {
case GIT_DIFF_LINE_ADDITION: std::cout << termcolor::green; break;
Expand Down Expand Up @@ -245,13 +264,20 @@ void diff_subcommand::run()
git_diff_options_init(&diffopts, GIT_DIFF_OPTIONS_VERSION);

bool use_colour = false;
if (m_colour_flag)
if (m_no_colour_flag)
{
use_colour = true;
if (m_colour_flag)
{
throw git_exception("Only one of --color and --no-color should be provided.", git2cpp_error_code::BAD_ARGUMENT);
}
else
{
use_colour = false;
}
}
if (m_no_colour_flag)
else if (m_colour_flag)
{
use_colour = false;
use_colour = true;
}
Comment thread
JohanMabille marked this conversation as resolved.

if (m_no_index_flag)
Expand Down
3 changes: 1 addition & 2 deletions src/utils/common.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <filesystem>
#include <iostream>
#include <fstream>
#include <sstream>
#include <unistd.h>
#include <map>

#include <git2.h>

#include "common.hpp"
#include "git_exception.hpp"

Expand Down
1 change: 0 additions & 1 deletion src/wrapper/repository_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <algorithm>
#include <fstream>
#include <git2/diff.h>
#include <iostream>

#include "../utils/git_exception.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/wrapper/repository_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <concepts>
#include <git2/types.h>
#include <optional>
#include <string_view>

Expand Down