-
Notifications
You must be signed in to change notification settings - Fork 5
update messages in status #99
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,10 @@ status_subcommand::status_subcommand(const libgit2_object&, CLI::App& app) | |
| 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 (use \"git reset HEAD <file>...\" to unstage)\n"; | ||
| const std::string ignored_header = "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"; | ||
| // "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)\n" | ||
| const std::string notstagged_header = "Changes not staged for commit:\n (use \"git add <file>...\" to update what will be committed)\n"; | ||
| // TODO: add the following ot notstagged_header after "checkout <file>" is implemented: (use \"git checkout -- <file>...\" to discard changes in working directory)\n"; | ||
| const std::string unmerged_header = "Unmerged paths:\n (use \"git add <file>...\" to mark resolution)\n"; | ||
| // const std::string nothingtocommit_message = "No changes added to commit (use \"git add\" and/or \"git commit -a\")"; | ||
| const std::string nothingtocommit_message = "no changes added to commit (use \"git add\" and/or \"git commit -a\")"; | ||
| const std::string treeclean_message = "Nothing to commit, working tree clean"; | ||
|
|
||
| enum class output_format | ||
|
|
@@ -172,6 +172,7 @@ void status_run(status_subcommand_options options) | |
| auto repo = repository_wrapper::open(directory); | ||
| auto sl = status_list_wrapper::status_list(repo); | ||
| auto branch_name = repo.head_short_name(); | ||
| auto tracking_info = repo.get_tracking_info(); | ||
|
|
||
| std::set<std::string> tracked_dir_set{}; | ||
| std::set<std::string> untracked_dir_set{}; | ||
|
|
@@ -196,11 +197,44 @@ void status_run(status_subcommand_options options) | |
| is_long = ((of == output_format::DEFAULT) || (of == output_format::LONG)); | ||
| if (is_long) | ||
| { | ||
| std::cout << "On branch " << branch_name << "\n" << std::endl; | ||
| std::cout << "On branch " << branch_name << std::endl; | ||
|
|
||
| if (tracking_info.has_upstream) | ||
| { | ||
| if(tracking_info.ahead > 0 && tracking_info.behind == 0) | ||
| { | ||
| std::cout << "Your branch is ahead of '" << tracking_info.upstream_name << "' by " | ||
| << tracking_info.ahead << " commit" | ||
| << (tracking_info.ahead > 1 ? "s" : "") << "." << std::endl; | ||
| std::cout << " (use \"git push\" to publish your local commits)" << std::endl; | ||
| } | ||
| else if (tracking_info.ahead == 0 && tracking_info.behind > 0) | ||
| { | ||
| std::cout << "Your branch is behind '" << tracking_info.upstream_name << "' by " | ||
| << tracking_info.behind << " commit" | ||
| << (tracking_info.behind > 1 ? "s" : "") << "." << std::endl; | ||
| std::cout << " (use \"git pull\" to update your local branch)" << std::endl; | ||
| } | ||
| else if (tracking_info.ahead > 0 && tracking_info.behind > 0) | ||
| { | ||
| std::cout << "Your branch and '" << tracking_info.upstream_name | ||
| << "' have diverged," << std::endl; | ||
| std::cout << "and have " << tracking_info.ahead << " and " | ||
| << tracking_info.behind << " different commit" | ||
| << ((tracking_info.ahead + tracking_info.behind) > 2 ? "s" : "") | ||
| << " each, respectively." << std::endl; | ||
| std::cout << " (use \"git pull\" to merge the remote branch into yours)" << std::endl; | ||
| } | ||
| else // ahead == 0 && behind == 0 | ||
| { | ||
| std::cout << "Your branch is up to date with '" << tracking_info.upstream_name << "'." << std::endl; | ||
| } | ||
| std::cout << std::endl; | ||
| } | ||
|
|
||
| if (repo.is_head_unborn()) | ||
| { | ||
| std::cout << "No commits yet\n" << std::endl; | ||
| std::cout << "No commit yet\n" << std::endl; | ||
| } | ||
|
|
||
| if (sl.has_unmerged_header()) | ||
|
|
@@ -214,6 +248,30 @@ void status_run(status_subcommand_options options) | |
| { | ||
| std::cout << "## " << branch_name << std::endl; | ||
| } | ||
|
|
||
| if (tracking_info.has_upstream) | ||
| { | ||
| std::cout << "..." << tracking_info.upstream_name; | ||
|
|
||
| if (tracking_info.ahead > 0 || tracking_info.behind > 0) | ||
| { | ||
| std::cout << " ["; | ||
| if (tracking_info.ahead > 0) | ||
| { | ||
| std::cout << "ahead " << tracking_info.ahead; | ||
| } | ||
| if (tracking_info.behind > 0) | ||
| { | ||
| if (tracking_info.ahead > 0) | ||
| { | ||
| std::cout << ", "; | ||
| } | ||
| std::cout << "behind " << tracking_info.behind; | ||
| } | ||
| std::cout << "]"; | ||
| } | ||
| std::cout << std::endl; | ||
| } | ||
| } | ||
|
|
||
| if (sl.has_tobecommited_header()) | ||
|
|
@@ -281,11 +339,13 @@ void status_run(status_subcommand_options options) | |
| } | ||
|
|
||
| // TODO: check if this message should be displayed even if there are untracked files | ||
| if (!(sl.has_tobecommited_header() | sl.has_notstagged_header() | sl.has_unmerged_header() | sl.has_untracked_header())) | ||
| if (is_long & (!(sl.has_tobecommited_header() | sl.has_notstagged_header() | sl.has_unmerged_header() | sl.has_untracked_header()))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use boolean operators (&&, ||) instead of bitwise operators here (&, |) toi avoid unecessary conversion to integers.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I published the review after the suggestion was applied, thus the outdated tag, but the comment is still relevant. |
||
| { | ||
| if (is_long) | ||
| { | ||
| std::cout << treeclean_message << std::endl; | ||
| } | ||
| std::cout << treeclean_message << std::endl; | ||
| } | ||
|
|
||
| if (is_long & !sl.has_tobecommited_header() & (sl.has_notstagged_header() | sl.has_untracked_header())) | ||
| { | ||
| std::cout << nothingtocommit_message << std::endl; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function is quite long, it would make it easier to read if it was split into logical smaller functions. |
||
| } | ||
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.