@matheusbsbs / matheus-bagliano / commits / aeb80c70ec
Fork 0

Suggest use of "git add file1 file2" when there is nothing to commit.

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 (<200612132237.10051.andyparkins@gmail.com>). Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Dec 15, 2006 at 21:53 UTC aeb80c70ec2baebbf107de0ea5293984798ddd24
2 files changed +7 -6
git-commit.sh
+1 -1
@@ -520,7 +520,7 @@ then
520 current="$(git-rev-parse --verify HEAD)"
521 else
522 if [ -z "$(git-ls-files)" ]; then
523 - echo >&2 Nothing to commit
523 + echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
524 exit 1
525 fi
526 PARENTS=""
wt-status.c
+6 -5
@@ -15,6 +15,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
15 "\033[31m", /* WT_STATUS_CHANGED: red */
16 "\033[31m", /* WT_STATUS_UNTRACKED: red */
17 };
18 +static const char* use_add_msg = "use \"git add file1 file2\" to include for commit";
19
20 static int parse_status_slot(const char *var, int offset)
21 {
@@ -162,8 +163,7 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
163 {
164 int i;
165 if (q->nr)
165 - wt_status_print_header("Changed but not updated",
166 - "use git-add on files to include for commit");
166 + wt_status_print_header("Changed but not updated", use_add_msg);
167 for (i = 0; i < q->nr; i++)
168 wt_status_print_filepair(WT_STATUS_CHANGED, q->queue[i]);
169 if (q->nr)
@@ -249,8 +249,7 @@ static void wt_status_print_untracked(const struct wt_status *s)
249 continue;
250 }
251 if (!shown_header) {
252 - wt_status_print_header("Untracked files",
253 - "use \"git add\" to add to commit");
252 + wt_status_print_header("Untracked files", use_add_msg);
253 shown_header = 1;
254 }
255 color_printf(color(WT_STATUS_HEADER), "#\t");
@@ -292,7 +291,9 @@ void wt_status_print(struct wt_status *s)
291 if (s->verbose && !s->is_initial)
292 wt_status_print_verbose(s);
293 if (!s->commitable)
295 - printf("%s\n", s->amend ? "# No changes" : "nothing to commit");
294 + printf("%s (%s)\n",
295 + s->amend ? "# No changes" : "nothing to commit",
296 + use_add_msg);
297 }
298
299 int git_status_config(const char *k, const char *v)