Skip to content

Commit 6908990

Browse files
author
Sebastian Schleemilch
committed
Including merge info
1 parent 65cb8e8 commit 6908990

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
lines changed

include/git_repo.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class GitRepo {
2323

2424
std::string repo_root;
2525

26+
bool in_merge;
27+
2628
private:
2729
static bool init(git_repository*, std::string);
2830
git_repository* repo;

include/unicode_symbols.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class UnicodeSymbols {
2626
TRIANGLE_RIGHT,
2727
QUADRANT_UPPER_LEFT,
2828
QUADRANT_LOWER_RIGHT,
29-
SQUARE
29+
SQUARE,
30+
BRANCH,
31+
RECYCLE
3032
};
3133
static std::string getString(SYMBOL);
3234
};

src/git_repo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "git_repo.hpp"
22
#include <iostream>
3+
#include <sys/stat.h>
34

45
GitRepo::GitRepo() {
56
git_libgit2_init();
@@ -9,6 +10,7 @@ GitRepo::GitRepo() {
910
wt_changes = 0;
1011
wt_added = 0;
1112
repo_root = "";
13+
in_merge = false;
1214
}
1315
GitRepo::~GitRepo() {}
1416

@@ -48,6 +50,12 @@ void GitRepo::set_head_infos() {
4850
} else {
4951
commit_id = "UNKNOWN";
5052
}
53+
54+
const std::string merge_head_file = repo_root + "MERGE_HEAD";
55+
struct stat buffer;
56+
if (stat (merge_head_file.c_str(), &buffer) == 0) {
57+
in_merge = true;
58+
}
5159
}
5260

5361
void GitRepo::set_remote_infos() {

src/help_functions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "help_functions.hpp"
22
#include <sstream>
33
#include <iostream>
4+
45
std::string get_cwd_string(std::string cwd, std::string home) {
56
std::string pathString = cwd;
67

src/main.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ void print_head_infos(GitRepo& repo, bool show_status) {
4747
if (!show_status) {
4848
bg_color = BashColor::COLOR::YELLOW;
4949
to_print += UnicodeSymbols::getString(UnicodeSymbols::SYMBOL::DELTA) + "?" + " ";
50-
}
51-
if (repo.index_changes > 0 || repo.wt_changes > 0 || repo.wt_added > 0) {
50+
} else if (repo.index_changes > 0 || repo.wt_changes > 0 || repo.wt_added > 0) {
5251
bg_color = BashColor::COLOR::YELLOW;
5352
to_print += UnicodeSymbols::getString(UnicodeSymbols::SYMBOL::DELTA) + " ";
53+
} else {
54+
to_print += UnicodeSymbols::getString(UnicodeSymbols::SYMBOL::SUN) + " ";
5455
}
5556
to_print += repo.branch + " ";
5657
to_print += "(" + repo.commit_id + ") ";
@@ -134,6 +135,18 @@ void print_status_infos(GitRepo& repo){
134135
}
135136
}
136137

138+
void print_merge_info(GitRepo& repo) {
139+
if (repo.in_merge) {
140+
std::string to_print = " ";
141+
to_print += UnicodeSymbols::getString(UnicodeSymbols::SYMBOL::RECYCLE);
142+
to_print += " MERGE ";
143+
BashColor::print(to_print,
144+
BashColor::COLOR::BLACK,
145+
BashColor::COLOR::PINK,
146+
false);
147+
}
148+
}
149+
137150
int main(int argc, char** argv) {
138151
bool show_status = true;
139152
std::string no_status_flag = "--no-status";
@@ -163,6 +176,7 @@ int main(int argc, char** argv) {
163176
print_status_infos(repo);
164177
}
165178
print_remote_infos(repo);
179+
print_merge_info(repo);
166180
}
167181
int lastCommandState = 0;
168182
try {

src/unicode_symbols.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ std::string UnicodeSymbols::getString(SYMBOL s) {
4747
return "\\u259F";
4848
case SYMBOL::SQUARE:
4949
return "\\u25AA";
50+
case SYMBOL::BRANCH:
51+
return "\\u2442";
52+
case SYMBOL::RECYCLE:
53+
return "\\u267A";
5054
}
5155
return std::string();
5256
}

0 commit comments

Comments
 (0)