From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: [PATCH 2/2 (v2)] reset: make the output more user-friendly.
Date: Fri, 7 Aug 2009 22:24:36 +0200 [thread overview]
Message-ID: <1249676676-5051-2-git-send-email-Matthieu.Moy@imag.fr> (raw)
In-Reply-To: <1249676676-5051-1-git-send-email-Matthieu.Moy@imag.fr>
git reset without argument displays a summary of the remaining
unstaged changes. The problem with these is that they look like an
error message, and the format is inconsistant with the format used in
other places like "git diff --name-status".
This patch mimics the output of "git diff --name-status", and adds a
header to make it clear the output is informative, and not an error.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
As noted by Junio, my previous version did actually display the header
unconditionnaly. This version displays it as the first change is found.
read-cache.c | 22 +++++++++++++++++-----
t/t7102-reset.sh | 3 ++-
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index f1aff81..4a4f4a5 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1065,6 +1065,15 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
return updated;
}
+static void show_file(const char * fmt, const char * name, int in_porcelain, int * first)
+{
+ if (in_porcelain && *first) {
+ printf("Unstaged changes after reset:\n");
+ *first=0;
+ }
+ printf(fmt, name);
+}
+
int refresh_index(struct index_state *istate, unsigned int flags, const char **pathspec, char *seen)
{
int i;
@@ -1074,11 +1083,14 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
int quiet = (flags & REFRESH_QUIET) != 0;
int not_new = (flags & REFRESH_IGNORE_MISSING) != 0;
int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
+ int first = 1;
+ int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
- const char *needs_update_message;
+ const char *needs_update_fmt;
+ const char *needs_merge_fmt;
- needs_update_message = ((flags & REFRESH_IN_PORCELAIN)
- ? "locally modified" : "needs update");
+ needs_update_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
+ needs_merge_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce, *new;
int cache_errno = 0;
@@ -1094,7 +1106,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
i--;
if (allow_unmerged)
continue;
- printf("%s: needs merge\n", ce->name);
+ show_file(needs_merge_fmt, ce->name, in_porcelain, &first);
has_errors = 1;
continue;
}
@@ -1117,7 +1129,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
}
if (quiet)
continue;
- printf("%s: %s\n", ce->name, needs_update_message);
+ show_file(needs_update_fmt, ce->name, in_porcelain, &first);
has_errors = 1;
continue;
}
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index e637c7d..e85ff02 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -419,7 +419,8 @@ test_expect_success 'resetting an unmodified path is a no-op' '
'
cat > expect << EOF
-file2: locally modified
+Unstaged changes after reset:
+M file2
EOF
test_expect_success '--mixed refreshes the index' '
--
1.6.4.62.g39c83.dirty
next prev parent reply other threads:[~2009-08-07 20:25 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-05 15:25 Message from git reset: confusing? Matthieu Moy
2009-08-05 17:21 ` Junio C Hamano
2009-08-05 17:42 ` Avery Pennarun
2009-08-05 18:07 ` John Tapsell
2009-08-05 18:25 ` Sverre Rabbelier
2009-08-06 9:42 ` Matthieu Moy
2009-08-06 19:21 ` Junio C Hamano
2009-08-07 20:24 ` [PATCH 1/2] Rename REFRESH_SAY_CHANGED to REFRESH_IN_PORCELAIN Matthieu Moy
2009-08-07 20:24 ` Matthieu Moy [this message]
2009-08-07 21:20 ` [PATCH 2/2 (v2)] reset: make the output more user-friendly Junio C Hamano
2009-08-08 7:44 ` Matthieu Moy
2009-08-17 17:31 ` Matthieu Moy
2009-08-17 19:50 ` Junio C Hamano
2009-08-21 8:57 ` [PATCH 1/2] Rename REFRESH_SAY_CHANGED to REFRESH_IN_PORCELAIN Matthieu Moy
2009-08-21 8:57 ` [PATCH 2/2 (v3)] reset: make the output more user-friendly Matthieu Moy
2009-08-22 5:44 ` Junio C Hamano
2009-08-22 7:52 ` Matthieu Moy
2009-08-23 2:33 ` Junio C Hamano
2009-08-23 10:42 ` Matthieu Moy
2009-08-23 11:45 ` Reece Dunn
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=1249676676-5051-2-git-send-email-Matthieu.Moy@imag.fr \
--to=matthieu.moy@imag.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).