@matheusbsbs / matheus-bagliano / commits / 3deffc52d8
Fork 0

reset: make the reminder output consistent with "checkout"

git reset without argument displays a summary of the local modification, like this: $ git reset Makefile: locally modified Some people have problems with this; they look like an error message. This patch makes its output mimic how "git checkout $another_branch" reports the paths with local modifications. "git add --refresh --verbose" is changed in the same way. It also adds a header to make it clear that the output is informative, and not an error. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>

Matthieu Moy committed Aug 21, 2009 at 10:57 UTC 3deffc52d88df73af72a80a406eb863880bb4d2a
5 files changed +27 -11
builtin-add.c
+1 -1
@@ -106,7 +106,7 @@ static void refresh(int verbose, const char **pathspec)
106 /* nothing */;
107 seen = xcalloc(specs, 1);
108 refresh_index(&the_index, verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET,
109 - pathspec, seen);
109 + pathspec, seen, "Unstaged changes after refreshing the index:");
110 for (i = 0; i < specs; i++) {
111 if (!seen[i])
112 die("pathspec '%s' did not match any files", pathspec[i]);
builtin-reset.c
+2 -1
@@ -108,7 +108,8 @@ static int update_index_refresh(int fd, struct lock_file *index_lock, int flags)
108 if (read_cache() < 0)
109 return error("Could not read index");
110
111 - result = refresh_cache(flags) ? 1 : 0;
111 + result = refresh_index(&the_index, (flags), NULL, NULL,
112 + "Unstaged changes after reset:") ? 1 : 0;
113 if (write_cache(fd, active_cache, active_nr) ||
114 commit_locked_index(index_lock))
115 return error ("Could not refresh index");
cache.h
+2 -2
@@ -330,7 +330,7 @@ static inline void remove_name_hash(struct cache_entry *ce)
330 #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
331 #define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))
332 #define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))
333 -#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL)
333 +#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
334 #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
335 #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
336 #define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase))
@@ -477,7 +477,7 @@ extern int check_path(const char *path, int len, struct stat *st);
477 #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */
478 #define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */
479 #define REFRESH_IN_PORCELAIN 0x0020 /* user friendly output, not "needs update" */
480 -extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen);
480 +extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen, char *header_msg);
481
482 struct lock_file {
483 struct lock_file *next;
read-cache.c
+20 -6
@@ -1065,7 +1065,18 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1065 return updated;
1066 }
1067
1068 -int refresh_index(struct index_state *istate, unsigned int flags, const char **pathspec, char *seen)
1068 +static void show_file(const char * fmt, const char * name, int in_porcelain,
1069 + int * first, char *header_msg)
1070 +{
1071 + if (in_porcelain && *first && header_msg) {
1072 + printf("%s\n", header_msg);
1073 + *first=0;
1074 + }
1075 + printf(fmt, name);
1076 +}
1077 +
1078 +int refresh_index(struct index_state *istate, unsigned int flags, const char **pathspec,
1079 + char *seen, char *header_msg)
1080 {
1081 int i;
1082 int has_errors = 0;
@@ -1074,11 +1085,14 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1085 int quiet = (flags & REFRESH_QUIET) != 0;
1086 int not_new = (flags & REFRESH_IGNORE_MISSING) != 0;
1087 int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
1088 + int first = 1;
1089 + int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
1090 unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
1078 - const char *needs_update_message;
1091 + const char *needs_update_fmt;
1092 + const char *needs_merge_fmt;
1093
1080 - needs_update_message = ((flags & REFRESH_IN_PORCELAIN)
1081 - ? "locally modified" : "needs update");
1094 + needs_update_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
1095 + needs_merge_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
1096 for (i = 0; i < istate->cache_nr; i++) {
1097 struct cache_entry *ce, *new;
1098 int cache_errno = 0;
@@ -1094,7 +1108,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1108 i--;
1109 if (allow_unmerged)
1110 continue;
1097 - printf("%s: needs merge\n", ce->name);
1111 + show_file(needs_merge_fmt, ce->name, in_porcelain, &first, header_msg);
1112 has_errors = 1;
1113 continue;
1114 }
@@ -1117,7 +1131,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1131 }
1132 if (quiet)
1133 continue;
1120 - printf("%s: %s\n", ce->name, needs_update_message);
1134 + show_file(needs_update_fmt, ce->name, in_porcelain, &first, header_msg);
1135 has_errors = 1;
1136 continue;
1137 }
t/t7102-reset.sh
+2 -1
@@ -419,7 +419,8 @@ test_expect_success 'resetting an unmodified path is a no-op' '
419 '
420
421 cat > expect << EOF
422 -file2: locally modified
422 +Unstaged changes after reset:
423 +M file2
424 EOF
425
426 test_expect_success '--mixed refreshes the index' '