Skip to contentSkip to conversation

New "git status" format with --alternate

PATCH New Nguyễn Thái Ngọc Duy 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 New "git status" format with --alternate

Another UI experiment, thrown at git@vger to see if it sticks. I've been using this for a week and it feels good in general. But it may be too specific to my taste to be useful for more people.

This format utilizes the screen estate as much as possible. It relies on colors, so monochrome users are stuck with default format. In short, it's a "GNU ls"-like output with footnotes:

- entries of all kinds (untracked, modified, cached...) are sorted in a single list, laid out in columns
- different kinds of files have different colors, more on this later
- square brackets around a tracked file means differences between index and HEAD (aka "git diff --cached").
- square brackets on untracked file means ignored file
- more information such as renames, unmerged tyes... is added in form of footnotes

On a clean repository, "git status" prints nothing. Branch state (rebasing/am-ing/....) is also printed.

This format is denser than the default format and easier to read (to me) as there is only one table. Colors and brackets are the visual clues. All the use of colors and brackets are explained in footnotes, so new users should have no problems with it (provided that they know basic concepts).

About colors, untracked files have no colors. Tracked files always do (to catch your eyes). Added/Removed/Modified/Unmerged have different colors. Text color reflects the changes between worktree and index (aka "git diff"). Bracket color reflects changes between index and HEAD (aka "git diff --cached").

If you see all magenta (modified) text without brackets, "git commit -a" is your friend. If you see all yellow text (unmodified worktree) and magenta brackets, "git commit" to go. A mix of magenta text and brackets mean you need to do "git diff --cached" and "git diff" to know what changes you are going to commit.

The merge of untracked/tracked files could be annoying if you don't keep your repository clean, though. Not sure if mering is a good idea, or just split them into two tables.

Final note: messy and incomplete implementation.

---
 builtin/commit.c |  11 ++
 wt-status.c      | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 wt-status.h      |   1 +
 3 files changed, 338 insertions(+), 13 deletions(-)
builtin/commit.c +11 -0
index a17a5df..758cf11 100644
@@ -114,6 +114,7 @@ static struct strbuf message = STRBUF_INIT;
 static enum {
 	STATUS_FORMAT_LONG,
 	STATUS_FORMAT_SHORT,
+	STATUS_FORMAT_ALTERNATE,
 	STATUS_FORMAT_PORCELAIN
 } status_format = STATUS_FORMAT_LONG;
 
@@ -451,6 +452,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 	case STATUS_FORMAT_SHORT:
 		wt_shortstatus_print(s);
 		break;
+	case STATUS_FORMAT_ALTERNATE:
+		wt_altstatus_print(s);
+		break;
 	case STATUS_FORMAT_PORCELAIN:
 		wt_porcelain_print(s);
 		break;
@@ -1154,6 +1158,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		OPT__VERBOSE(&verbose, N_("be verbose")),
 		OPT_SET_INT('s', "short", &status_format,
 			    N_("show status concisely"), STATUS_FORMAT_SHORT),
+		OPT_SET_INT(0, "alternate", &status_format,
+			    N_("show status concisely"), STATUS_FORMAT_ALTERNATE),
 		OPT_BOOLEAN('b', "branch", &s.show_branch,
 			    N_("show branch information")),
 		OPT_SET_INT(0, "porcelain", &status_format,
@@ -1188,6 +1194,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
 	if (s.null_termination && status_format == STATUS_FORMAT_LONG)
 		status_format = STATUS_FORMAT_PORCELAIN;
+	if (s.null_termination && status_format == STATUS_FORMAT_ALTERNATE)
+		die(_("--alternate does not work with -z"));
 
 	handle_untracked_files_arg(&s);
 	if (show_ignored_in_status)
@@ -1213,6 +1221,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	case STATUS_FORMAT_SHORT:
 		wt_shortstatus_print(&s);
 		break;
+	case STATUS_FORMAT_ALTERNATE:
+		wt_altstatus_print(&s);
+		break;
 	case STATUS_FORMAT_PORCELAIN:
 		wt_porcelain_print(&s);
 		break;
wt-status.c +326 -13

366 lines not on this page · raw message

wt-status.h +1 -0
index 236b41f..8804400 100644
@@ -86,6 +86,7 @@ void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
 
 void wt_shortstatus_print(struct wt_status *s);
+void wt_altstatus_print(struct wt_status *s);
 void wt_porcelain_print(struct wt_status *s);
 
 void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)
Signature · 1 line
1.8.0.rc2.25.gf0e8e5d