[PATCHv2 1/2] wt-status: better advices for git status

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch provides more information about your current state after a git status command (in the cases of conflicts, before and after they are resolved, a rebase or a bisect process).
This would help users to know what they are currently doing, in a more accurate way.

Signed-off-by: Kong Lucien <Lucien.Kong@xxxxxxxxxxxxxxx>
Signed-off-by: Duperray Valentin <Valentin.Duperray@xxxxxxxxxxxxxxx>
Signed-off-by: Jonas Franck <Franck.Jonas@xxxxxxxxxxxxxxx>
Signed-off-by: Nguy Thomas <Thomas.Nguy@xxxxxxxxxxxxxxx>
Signed-off-by: Nguyen Huynh Khoi Nguyen Lucien <Huynh-Khoi-Nguyen.Nguyen@xxxxxxxxxxxxxxx>
---
 wt-status.c |   89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.h |    1 +
 2 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index dd6d8c4..9839280 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -15,6 +15,7 @@
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
+	GIT_COLOR_NORMAL, /* WT_STATUS_IN_PROGRESS */
 	GIT_COLOR_GREEN,  /* WT_STATUS_UPDATED */
 	GIT_COLOR_RED,    /* WT_STATUS_CHANGED */
 	GIT_COLOR_RED,    /* WT_STATUS_UNTRACKED */
@@ -728,6 +729,92 @@ static void wt_status_print_tracking(struct wt_status *s)
 	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 }
 
+static void wt_status_print_in_progress(struct wt_status *s)
+{
+	int i;
+	const char *c = color(WT_STATUS_IN_PROGRESS, s);
+	const char *git_dir = getenv(GIT_DIR_ENVIRONMENT);
+	const char* path;
+	int unmerged_state = 0;
+	int rebase_state = 0;
+	int rebase_interactive_state = 0;
+	int am_state = 0;
+	int bisect_state = 0;
+	int conflict = 0;
+
+	for (i = 0; i < s->change.nr; i++) {
+		struct wt_status_change_data *d;
+		struct string_list_item *it;
+		it = &(s->change.items[i]);
+		d = it->util;
+		if (d->stagemask) {
+			conflict = 1;
+			continue;
+		}
+	}
+
+	path = mkpath("%s/MERGE_HEAD", git_dir);
+	if (!access(path, R_OK))
+		unmerged_state = 1;
+
+	path = mkpath("%s/rebase-apply", git_dir);
+	if (!access(path, R_OK)) {
+		path = mkpath("%s/rebase-apply/applying", git_dir);
+		if (!access(path, R_OK))
+			am_state = 1;
+		else
+			rebase_state = 1;
+	}
+	else {
+		path = mkpath("%s/rebase-merge", git_dir);
+		if (!access(path, R_OK)) {
+			path = mkpath("%s/rebase-merge/interactive", git_dir);
+			if (!access(path, R_OK))
+				rebase_interactive_state = 1;
+			else
+				rebase_state = 1;
+		}
+	}
+
+	path = mkpath("%s/BISECT_LOG", git_dir);
+	if (!access(path, R_OK))
+		bisect_state = 1;
+
+	if(bisect_state) {
+		status_printf_ln(s, c, _("You are currently bisecting."));
+		status_printf_ln(s, c, _("To get back to the original branch run \"git bisect reset\""));
+		wt_status_print_trailer(s);
+	}
+
+	if(unmerged_state) {
+		if (conflict)
+			status_printf_ln(s, c, _("You have unmerged paths: fix conflicts and then commit the result."));
+		else
+			status_printf_ln(s, c, _("You are still merging, run \"git commit\" to conclude merge."));
+		wt_status_print_trailer(s);
+	}
+
+	if(rebase_state || rebase_interactive_state) {
+		if (conflict) {
+			status_printf_ln(s, c, _("You are currently rebasing: fix conflicts and then run \"git rebase -- continue\"."));
+			status_printf_ln(s, c, _("If you would prefer to skip this patch, instead run \"git rebase --skip\"."));
+			status_printf_ln(s, c, _("To check out  the original branch and stop rebasing run \"git rebase --abort\"."));
+		}
+		else {
+			if (rebase_state)
+				status_printf_ln(s, c, _("You are currently rebasing: all conflicts fixed; run \"git rebase --continue\"."));
+			else {
+				status_printf_ln(s, c, _("You are currently editing in a rebase progress."));
+				status_printf_ln(s, c, _("You can amend the commit with"));
+				status_printf_ln(s, c, _("	git commit --amend"));
+				status_printf_ln(s, c, _("Once you are satisfied with your changes, run"));
+				status_printf_ln(s, c, _("	git rebase --continue"));
+			}
+		}
+		wt_status_print_trailer(s);
+	}
+}
+
 void wt_status_print(struct wt_status *s)
 {
 	const char *branch_color = color(WT_STATUS_ONBRANCH, s);
@@ -750,6 +837,8 @@ void wt_status_print(struct wt_status *s)
 			wt_status_print_tracking(s);
 	}
 
+	wt_status_print_in_progress(s);
+
 	if (s->is_initial) {
 		status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
 		status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit"));
diff --git a/wt-status.h b/wt-status.h
index 14aa9f7..3d86801 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -7,6 +7,7 @@
 
 enum color_wt_status {
 	WT_STATUS_HEADER = 0,
+	WT_STATUS_IN_PROGRESS,
 	WT_STATUS_UPDATED,
 	WT_STATUS_CHANGED,
 	WT_STATUS_UNTRACKED,
-- 
1.7.8

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]