Code

Suggest use of "git add file1 file2" when there is nothing to commit.
authorShawn O. Pearce <spearce@spearce.org>
Sat, 16 Dec 2006 02:53:09 +0000 (21:53 -0500)
committerJunio C Hamano <junkio@cox.net>
Sat, 16 Dec 2006 06:31:01 +0000 (22:31 -0800)
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>
git-commit.sh
wt-status.c

index a30bda19d526eba3b99aa803c838a41c2a017632..6bce41af4dc73d90028e76ba174e4e7795103d6c 100755 (executable)
@@ -520,7 +520,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=""
index 6e9414dbb07f1457eb436907a77d14476a6e6b1f..2173d4f66851e3286ef2fca48e8ae88da1d1db3a 100644 (file)
@@ -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)