[PATCH 1/2] Suggest use of "git add file1 file2" when there is nothing to commit.

Subsystems: the rest

DORMANTno replies

5 messages, 3 authors, 2016-08-11 · open the first message on its own page

[PATCH 1/2] Suggest use of "git add file1 file2" when there is nothing to commit.

From: Shawn O. Pearce <hidden>
Date: 2016-08-11 20:03:57

If a user modifies files and runs 'git commit' (without the very
useful -a option) and they have not yet updated the index they
are probably coming from another SCM-like tool which would perform
the same as 'git commit -a' in this case.  Showing the user their
current status and a final line of "nothing to commit" is not very
reassuring, as the user might believe that Git did not recognize
their files were modified.

Instead we can suggest as part of the 'nothing to commit' message
that the user invoke 'git add' to add files to their next commit.

Suggested by Andy Parkins' Git 'niggles' list
([off-list ref]).

Signed-off-by: Shawn O. Pearce <redacted>
---
 git-commit.sh |    2 +-
 wt-status.c   |   11 ++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/git-commit.sh b/git-commit.sh
index 05828bb..2672def 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -515,7 +515,7 @@ then
 	current="$(git-rev-parse --verify HEAD)"
 else
 	if [ -z "$(git-ls-files)" ]; then
-		echo >&2 Nothing to commit
+		echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
 		exit 1
 	fi
 	PARENTS=""
diff --git a/wt-status.c b/wt-status.c
index 6e9414d..2173d4f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -15,6 +15,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
 	"\033[31m", /* WT_STATUS_CHANGED: red */
 	"\033[31m", /* WT_STATUS_UNTRACKED: red */
 };
+static const char* use_add_msg = "use \"git add file1 file2\" to include for commit";
 
 static int parse_status_slot(const char *var, int offset)
 {
@@ -162,8 +163,7 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
 {
 	int i;
 	if (q->nr)
-		wt_status_print_header("Changed but not updated",
-				"use git-add on files to include for commit");
+		wt_status_print_header("Changed but not updated", use_add_msg);
 	for (i = 0; i < q->nr; i++)
 		wt_status_print_filepair(WT_STATUS_CHANGED, q->queue[i]);
 	if (q->nr)
@@ -249,8 +249,7 @@ static void wt_status_print_untracked(const struct wt_status *s)
 				continue;
 		}
 		if (!shown_header) {
-			wt_status_print_header("Untracked files",
-				"use \"git add\" to add to commit");
+			wt_status_print_header("Untracked files", use_add_msg);
 			shown_header = 1;
 		}
 		color_printf(color(WT_STATUS_HEADER), "#\t");
@@ -292,7 +291,9 @@ void wt_status_print(struct wt_status *s)
 	if (s->verbose && !s->is_initial)
 		wt_status_print_verbose(s);
 	if (!s->commitable)
-		printf("%s\n", s->amend ? "# No changes" : "nothing to commit");
+		printf("%s (%s)\n",
+			s->amend ? "# No changes" : "nothing to commit",
+			use_add_msg);
 }
 
 int git_status_config(const char *k, const char *v)
-- 
1.4.4.2.g053a

Re: [PATCH 1/2] Suggest use of "git add file1 file2" when there is nothing to commit.

From: Michael Loeffler <hidden>
Date: 2016-06-15 22:42:47

Hi,

Am Freitag, den 15.12.2006, 21:53 -0500 schrieb Shawn O. Pearce:
...
quoted hunk
@@ -292,7 +291,9 @@ void wt_status_print(struct wt_status *s)
 	if (s->verbose && !s->is_initial)
 		wt_status_print_verbose(s);
 	if (!s->commitable)
-		printf("%s\n", s->amend ? "# No changes" : "nothing to commit");
+		printf("%s (%s)\n",
+			s->amend ? "# No changes" : "nothing to commit",
+			use_add_msg);
 }
I don't like the new 'nothing to commit (use "git add ... message")'
message. I use git status very often to see if there is something to
commit, but now there is always this annoying "use git add ..." message.
I just want to see on what the branch is and if there is something to
commit.

If there is something to commit I get the list of untracked or modified
files with the use_add_msg and if I try to commit an empty tree as
initial commit I get the message from git-commit.sh.


bye

Re: [PATCH 1/2] Suggest use of "git add file1 file2" when there is nothing to commit.

From: Juergen Ruehle <hidden>
Date: 2016-06-15 22:42:48

Michael Loeffler writes:
 > Hi,
 > 
 > Am Freitag, den 15.12.2006, 21:53 -0500 schrieb Shawn O. Pearce:
 > ...
 > > @@ -292,7 +291,9 @@ void wt_status_print(struct wt_status *s)
 > >  	if (s->verbose && !s->is_initial)
 > >  		wt_status_print_verbose(s);
 > >  	if (!s->commitable)
 > > -		printf("%s\n", s->amend ? "# No changes" : "nothing to commit");
 > > +		printf("%s (%s)\n",
 > > +			s->amend ? "# No changes" : "nothing to commit",
 > > +			use_add_msg);
 > >  }
 > I don't like the new 'nothing to commit (use "git add ... message")'
 > message. I use git status very often to see if there is something to
 > commit, but now there is always this annoying "use git add ..." message.
 > I just want to see on what the branch is and if there is something to
 > commit.
 > 
 > If there is something to commit I get the list of untracked or modified
 > files with the use_add_msg and if I try to commit an empty tree as
 > initial commit I get the message from git-commit.sh.

I'd appreciate feedback on my series from the 2nd of January,
especially part 3/4 (Subject: [PATCH 3/4] Improve "nothing to commit"
part of status output). This is already part of next.

It removes the message if there really is nothing to commit and
replaces it by a generic pointer to git add and git commit if there
are pending changes in the working directory.

Re: [PATCH 1/2] Suggest use of "git add file1 file2" when there is nothing to commit.

From: Michael Loeffler <hidden>
Date: 2016-06-15 22:42:48

hi,

Am Samstag, den 06.01.2007, 15:02 +0100 schrieb Juergen Ruehle:
...
I'd appreciate feedback on my series from the 2nd of January,
especially part 3/4 (Subject: [PATCH 3/4] Improve "nothing to commit"
part of status output). This is already part of next.
A very positive feedback from me, I like this and it is much better then
just removing this "use git add"-message. ;)

bye michael

Re: [PATCH 1/2] Suggest use of "git add file1 file2" when there is nothing to commit.

From: Juergen Ruehle <hidden>
Date: 2016-06-15 22:42:48

Michael Loeffler writes:
 > hi,
 > 
 > Am Samstag, den 06.01.2007, 15:02 +0100 schrieb Juergen Ruehle:
 > ...
 > > I'd appreciate feedback on my series from the 2nd of January,
 > > especially part 3/4 (Subject: [PATCH 3/4] Improve "nothing to commit"
 > > part of status output). This is already part of next.
 > A very positive feedback from me, I like this and it is much better then
 > just removing this "use git add"-message. ;)

How about Junio's case where there are only untracked files in the
working directory? I tend to send a patch that either just prints
"nothing to commit" (simpler) or provides a different message that
just advertises git-add.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help