From: Jonathan Nieder <jrnieder@gmail.com>
To: Goswin von Brederlow <goswin-v-b@web.de>, 578764@bugs.debian.org
Cc: git@vger.kernel.org
Subject: Re: Please default to 'commit -a' when no changes were added
Date: Thu, 22 Apr 2010 10:58:07 -0500 [thread overview]
Message-ID: <20100422155806.GC4801@progeny.tock> (raw)
In-Reply-To: <20100422151037.2310.2429.reportbug@frosties.localdomain>
[topic: making ‘git commit’ more helpful when there are no changes
registered in the index]
Hi Goswin,
Goswin von Brederlow wrote:
> in most (all but git?) RCS a plain 'commit' without any arguments
> commits all changes (to registered files).
Yes, but they are wrong. :)
> no changes added to commit (use "git add" and/or "git commit -a")
[...]
> Imho in most cases where no changes
> were added people do want to commit all modified files. And if not
> then exiting the editor to abort is easy enough.
I absent-mindedly type ‘git commit’ having forgotten to update the
index with my changes fairly often. Then I add the appropriate
changes, which is almost never all of them. I don’t think this is so
unusual.
Starting out, I can see how it would be comforting to people if
‘git commit’ would default to -a behavior if they ignore the index.
That is logically a different operation, though, so it would also send
a wrong message and make it harder in the long run to get used to the
interface.
Instead, I think it would be better to focus on making the error
message more helpful. Right now there is a screen full of status
before the advice, which might make it easy to get scared before
reading it.
Here’s a very rough patch to suppress that screenful. What do you
think?
diff --git a/builtin/commit.c b/builtin/commit.c
index c5ab683..9cb5489 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -396,7 +396,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
}
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
- struct wt_status *s)
+ struct wt_status *s, int simple)
{
unsigned char sha1[20];
@@ -415,6 +415,13 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
wt_status_collect(s);
+ if (simple) {
+ if (s->commitable)
+ die("internal error: are there changes or not?");
+ wt_status_print_nochanges(s);
+ return 0;
+ }
+
switch (status_format) {
case STATUS_FORMAT_SHORT:
wt_shortstatus_print(s, null_termination);
@@ -670,7 +677,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
saved_color_setting = s->use_color;
s->use_color = 0;
- commitable = run_status(fp, index_file, prefix, 1, s);
+ commitable = run_status(fp, index_file, prefix, 1, s, 0);
s->use_color = saved_color_setting;
} else {
unsigned char sha1[20];
@@ -692,7 +699,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (!commitable && !in_merge && !allow_empty &&
!(amend && is_a_merge(head_sha1))) {
- run_status(stdout, index_file, prefix, 0, s);
+ run_status(stdout, index_file, prefix, 0, s, 1);
return 0;
}
@@ -946,7 +953,7 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix,
const char *index_file;
index_file = prepare_index(argc, argv, prefix, 1);
- commitable = run_status(stdout, index_file, prefix, 0, s);
+ commitable = run_status(stdout, index_file, prefix, 0, s, 0);
rollback_index_files();
return commitable ? 0 : 1;
diff --git a/wt-status.c b/wt-status.c
index 8ca59a2..b50bf71 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -589,6 +589,24 @@ static void wt_status_print_tracking(struct wt_status *s)
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
}
+void wt_status_print_nochanges(struct wt_status *s)
+{
+ if (s->amend)
+ fprintf(s->fp, "# No changes\n");
+ else if (s->nowarn)
+ ; /* nothing */
+ else if (s->workdir_dirty)
+ printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
+ else if (s->untracked.nr)
+ printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
+ else if (s->is_initial)
+ printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
+ else if (!s->show_untracked_files)
+ printf("nothing to commit (use -u to show untracked files)\n");
+ else
+ printf("nothing to commit (working directory clean)\n");
+}
+
void wt_status_print(struct wt_status *s)
{
const char *branch_color = color(WT_STATUS_HEADER, s);
@@ -629,22 +647,8 @@ void wt_status_print(struct wt_status *s)
if (s->verbose)
wt_status_print_verbose(s);
- if (!s->commitable) {
- if (s->amend)
- fprintf(s->fp, "# No changes\n");
- else if (s->nowarn)
- ; /* nothing */
- else if (s->workdir_dirty)
- printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
- else if (s->untracked.nr)
- printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
- else if (s->is_initial)
- printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
- else if (!s->show_untracked_files)
- printf("nothing to commit (use -u to show untracked files)\n");
- else
- printf("nothing to commit (working directory clean)\n");
- }
+ if (!s->commitable)
+ wt_status_print_nochanges(s);
}
static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it,
diff --git a/wt-status.h b/wt-status.h
index 9120673..f249955 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -59,6 +59,8 @@ void wt_status_prepare(struct wt_status *s);
void wt_status_print(struct wt_status *s);
void wt_status_collect(struct wt_status *s);
+void wt_status_print_nochanges(struct wt_status *s);
+
void wt_shortstatus_print(struct wt_status *s, int null_termination);
void wt_porcelain_print(struct wt_status *s, int null_termination);
next parent reply other threads:[~2010-04-22 15:57 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20100422151037.2310.2429.reportbug@frosties.localdomain>
2010-04-22 15:58 ` Jonathan Nieder [this message]
2010-04-22 18:37 ` Please default to 'commit -a' when no changes were added Goswin von Brederlow
2010-04-22 19:03 ` Nicolas Pitre
2010-04-22 19:08 ` Sverre Rabbelier
2010-04-22 20:37 ` Goswin von Brederlow
2010-04-22 21:25 ` Nicolas Pitre
2010-04-23 9:03 ` Goswin von Brederlow
2010-04-23 9:31 ` Miles Bader
2010-04-23 16:01 ` Wincent Colaiuta
2010-04-23 20:17 ` Goswin von Brederlow
2010-04-23 20:26 ` Michael Witten
2010-04-23 20:33 ` Daniel Grace
2010-04-23 21:01 ` Nicolas Pitre
2010-04-24 21:15 ` Goswin von Brederlow
2010-04-24 21:40 ` Jonathan Nieder
2010-04-24 22:08 ` Goswin von Brederlow
2010-04-24 22:42 ` Jonathan Nieder
2010-04-25 2:47 ` Miles Bader
2010-04-25 3:33 ` Jonathan Nieder
2010-04-23 22:35 ` Matthias Andree
2010-04-24 1:43 ` Junio C Hamano
2010-04-22 21:28 ` Junio C Hamano
2010-04-22 21:40 ` Matthieu Moy
2010-04-22 21:57 ` Michael Witten
2010-04-23 9:09 ` Goswin von Brederlow
2010-04-23 9:22 ` Tomas Carnecky
2010-04-23 17:00 ` Michael Witten
2010-04-23 9:27 ` Matthieu Moy
2010-04-23 9:35 ` Tor Arntsen
2010-04-22 21:48 ` Adam Brewster
2010-04-22 22:27 ` Jonathan Nieder
2010-04-23 9:15 ` Goswin von Brederlow
2010-04-23 10:39 ` The index (Re: Please default to 'commit -a' when no changes were added) Jonathan Nieder
2010-04-22 22:38 ` Please default to 'commit -a' when no changes were added Jon Seymour
2010-04-23 0:04 ` Adam Brewster
2010-04-23 9:25 ` Goswin von Brederlow
2010-04-23 9:14 ` Goswin von Brederlow
2010-04-23 9:39 ` Björn Steinbrink
2010-04-23 11:44 ` Sergei Organov
2010-04-23 11:57 ` Sverre Rabbelier
2010-04-23 12:20 ` Sergei Organov
2010-04-23 14:23 ` Goswin von Brederlow
2010-04-23 18:59 ` Matthias Andree
2010-04-23 19:34 ` Michael Witten
2010-04-23 22:18 ` Matthias Andree
2010-04-23 22:25 ` Eric Raymond
2010-04-23 23:38 ` Michael Witten
2010-04-24 4:38 ` Eric Raymond
2010-04-24 9:05 ` Michael Witten
2010-04-24 9:09 ` Eric Raymond
2010-04-23 23:26 ` Michael Witten
2010-04-24 13:26 ` Tor Arntsen
2010-04-24 9:40 ` 'commit -a' safety (was: Re: Please default to 'commit -a' when no changes were added) Jakub Narebski
2010-04-24 9:56 ` 'commit -a' safety Miles Bader
2010-04-24 10:05 ` Andreas Schwab
2010-04-24 10:26 ` Jakub Narebski
2010-04-24 13:29 ` Miles Bader
2010-04-24 18:23 ` Nicolas Pitre
2010-04-25 0:16 ` Jakub Narebski
2010-04-25 2:43 ` Miles Bader
2010-04-24 11:10 ` 'commit -a' safety (was: Re: Please default to 'commit -a' when no changes were added) Wincent Colaiuta
2010-04-24 11:48 ` 'commit -a' safety Jakub Narebski
2010-04-24 14:28 ` Joey Hess
2010-04-24 15:11 ` Mike Hommey
2010-04-24 16:42 ` 'commit -a' safety (was: Re: Please default to 'commit -a' when no changes were added) Petr Baudis
2010-04-24 16:59 ` Bug#578764: " Wincent Colaiuta
2010-04-24 17:47 ` Petr Baudis
2010-04-24 18:35 ` Nicolas Pitre
2010-04-24 18:54 ` Petr Baudis
2010-04-24 19:09 ` Nicolas Pitre
2010-04-24 19:35 ` Jacob Helwig
2010-04-24 19:44 ` Nicolas Pitre
2010-04-24 19:57 ` Jacob Helwig
2010-04-24 23:47 ` 'commit -a' safety Jakub Narebski
2010-04-25 1:13 ` Junio C Hamano
2010-04-25 8:01 ` Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100422155806.GC4801@progeny.tock \
--to=jrnieder@gmail.com \
--cc=578764@bugs.debian.org \
--cc=git@vger.kernel.org \
--cc=goswin-v-b@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).