-
Notifications
You must be signed in to change notification settings - Fork 3
Improve status output #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ianthomas23
merged 3 commits into
QuantStack:main
from
SandrineP:status_nothing_to_commit
Nov 10, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,16 +26,18 @@ status_subcommand::status_subcommand(const libgit2_object&, CLI::App& app) | |
| sub->callback([this]() { this->run(); }); | ||
| }; | ||
|
|
||
| const std::string untracked_header = "Untracked files:\n"; | ||
| // "Untracked files:\n (use \"git add <file>...\" to include in what will be committed)"; | ||
| const std::string untracked_header = "Untracked files:\n (use \"git add <file>...\" to include in what will be committed)\n"; | ||
| const std::string tobecommited_header = "Changes to be committed:\n"; | ||
| // "Changes to be committed:\n (use \"git reset HEAD <file>...\" to unstage)"; | ||
| const std::string ignored_header = "Ignored files:\n"; | ||
| // "Ignored files:\n (use \"git add -f <file>...\" to include in what will be committed)" | ||
| const std::string notstagged_header = "Changes not staged for commit:\n"; | ||
| // "Changes not staged for commit:\n (use \"git add%s <file>...\" to update what will be committed)\n (use \"git checkout -- <file>...\" to discard changes in working directory)" | ||
| const std::string nothingtocommit_message = "No changes added to commit"; | ||
| // "No changes added to commit (use \"git add\" and/or \"git commit -a\")" | ||
| // (use \"git restore --staged <file>...\" to unstage)\n | ||
| // (use \"git reset HEAD <file>...\" to unstage)\n"; | ||
| const std::string ignored_header = "Ignored files:\n Ignored files:\n (use \"git add -f <file>...\" to include in what will be committed)\n"; | ||
| const std::string notstagged_header = "Changes not staged for commit:\n (use \"git add <file>...\" to update what will be committed)\n"; | ||
| // (use \"git restore <file>...\" to discard changes in working directory)\n | ||
| // (use \"git checkout -- <file>...\" to discard changes in working directory)\n" | ||
| const std::string nothingtocommit_msg = "No changes added to commit (use \"git add\" and/or \"git commit -a\")"; | ||
| const std::string uptodate_msg = "Nothing to commit, working tree clean."; | ||
| const std::string nothingtocommit_untrackedfiles_msg = "Nothing added to commit but untracked files present (use \"git add\" to track)"; | ||
| // no changes added to commit (use "git add" and/or "git commit -a") | ||
|
|
||
| struct status_messages | ||
| { | ||
|
|
@@ -51,7 +53,7 @@ const std::map<git_status_t, status_messages> status_msg_map = //TODO : check | |
| { GIT_STATUS_INDEX_DELETED, {"D ", "\tdeleted:"} }, | ||
| { GIT_STATUS_INDEX_RENAMED, {"R ", "\trenamed:"} }, | ||
| { GIT_STATUS_INDEX_TYPECHANGE, {"T ", "\ttypechange:"} }, | ||
| { GIT_STATUS_WT_NEW, {"?? ", ""} }, | ||
| { GIT_STATUS_WT_NEW, {"?? ", " "} }, | ||
| { GIT_STATUS_WT_MODIFIED, {" M " , "\tmodified:"} }, | ||
| { GIT_STATUS_WT_DELETED, {" D ", "\tdeleted:"} }, | ||
| { GIT_STATUS_WT_TYPECHANGE, {" T ", "\ttypechange:"} }, | ||
|
|
@@ -79,7 +81,14 @@ std::string get_print_status(git_status_t status, output_format of) | |
| std::string entry_status; | ||
| if ((of == output_format::DEFAULT) || (of == output_format::LONG)) | ||
| { | ||
| entry_status = status_msg_map.at(status).long_mod + " "; | ||
| if (status == GIT_STATUS_WT_NEW) | ||
| { | ||
| entry_status = status_msg_map.at(status).long_mod + "\t"; | ||
| } | ||
| else | ||
| { | ||
| entry_status = status_msg_map.at(status).long_mod + " "; | ||
| } | ||
| } | ||
| else if (of == output_format::SHORT) | ||
| { | ||
|
|
@@ -88,14 +97,14 @@ std::string get_print_status(git_status_t status, output_format of) | |
| return entry_status; | ||
| } | ||
|
|
||
| void update_tracked_dir_set(const char* old_path, const char* new_path, std::set<std::string>* tracked_dir_set = nullptr) | ||
| void update_tracked_dir_set(const char* path, std::set<std::string>* tracked_dir_set = nullptr) | ||
| { | ||
| if (tracked_dir_set) | ||
| { | ||
| const size_t first_slash_idx = std::string_view(old_path).find('/'); | ||
| const size_t first_slash_idx = std::string_view(path).find('/'); | ||
| if (std::string::npos != first_slash_idx) | ||
| { | ||
| auto directory = std::string_view(old_path).substr(0, first_slash_idx); | ||
| auto directory = std::string_view(path).substr(0, first_slash_idx); | ||
| tracked_dir_set->insert(std::string(directory)); | ||
| } | ||
| } | ||
|
|
@@ -131,7 +140,7 @@ std::vector<print_entry> get_entries_to_print(git_status_t status, status_list_w | |
| const char* old_path = diff_delta->old_file.path; | ||
| const char* new_path = diff_delta->new_file.path; | ||
|
|
||
| update_tracked_dir_set(old_path, new_path, tracked_dir_set); | ||
| update_tracked_dir_set(old_path, tracked_dir_set); | ||
|
|
||
| print_entry e = { get_print_status(status, of), get_print_item(old_path, new_path)}; | ||
|
|
||
|
|
@@ -164,7 +173,8 @@ void print_not_tracked(const std::vector<print_entry>& entries_to_print, const s | |
| const size_t first_slash_idx = e.item.find('/'); | ||
| if (std::string::npos != first_slash_idx) | ||
| { | ||
| auto directory = "\t" + e.item.substr(0, first_slash_idx) + "/"; | ||
| auto directory = e.item.substr(0, first_slash_idx); | ||
| auto directory_print = e.item.substr(0, first_slash_idx) + "/"; | ||
| if (tracked_dir_set.contains(directory)) | ||
| { | ||
| not_tracked_entries_to_print.push_back(e); | ||
|
|
@@ -175,7 +185,7 @@ void print_not_tracked(const std::vector<print_entry>& entries_to_print, const s | |
| {} | ||
| else | ||
| { | ||
| not_tracked_entries_to_print.push_back({e.status, directory}); | ||
| not_tracked_entries_to_print.push_back({e.status, directory_print}); | ||
| untracked_dir_set.insert(std::string(directory)); | ||
| } | ||
| } | ||
|
|
@@ -290,4 +300,21 @@ void status_subcommand::run() | |
| // std::cout << std::endl; | ||
| // } | ||
| // } | ||
|
|
||
| if (!sl.has_tobecommited_header() & (sl.has_notstagged_header() | sl.has_untracked_header())) | ||
|
||
| { | ||
| if (sl.has_untracked_header()) | ||
| { | ||
| std::cout << nothingtocommit_untrackedfiles_msg << std::endl; | ||
| } | ||
| else | ||
| { | ||
| std::cout << nothingtocommit_msg << std::endl; | ||
| } | ||
| } | ||
|
|
||
| if (!sl.has_notstagged_header() & !sl.has_untracked_header()) | ||
|
||
| { | ||
| std::cout << uptodate_msg << std::endl; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the repeat of
"Ignored files:\n"intended here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'll remove one. I'll also comment it as it's not used so far.