wt-status: teach has_{unstaged,uncommitted}_changes() about submodules

Sometimes we are *actually* interested in those changes... For example when an interactive rebase wants to continue with a staged submodule update. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 7, 2016 at 18:09 UTC d8cc92ab13e438f225770843868ae5a58c6bb357
3 files changed +14 -11
builtin/pull.c
+1 -1
@@ -810,7 +810,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
810
811 if (!autostash)
812 require_clean_work_tree(N_("pull with rebase"),
813 - _("please commit or stash them."), 0);
813 + _("please commit or stash them."), 1, 0);
814
815 if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
816 hashclr(rebase_fork_point);
wt-status.c
+9 -7
@@ -2214,13 +2214,14 @@ void wt_status_print(struct wt_status *s)
2214 /**
2215 * Returns 1 if there are unstaged changes, 0 otherwise.
2216 */
2217 -int has_unstaged_changes(void)
2217 +int has_unstaged_changes(int ignore_submodules)
2218 {
2219 struct rev_info rev_info;
2220 int result;
2221
2222 init_revisions(&rev_info, NULL);
2223 - DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
2223 + if (ignore_submodules)
2224 + DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
2225 DIFF_OPT_SET(&rev_info.diffopt, QUICK);
2226 diff_setup_done(&rev_info.diffopt);
2227 result = run_diff_files(&rev_info, 0);
@@ -2230,7 +2231,7 @@ int has_unstaged_changes(void)
2231 /**
2232 * Returns 1 if there are uncommitted changes, 0 otherwise.
2233 */
2233 -int has_uncommitted_changes(void)
2234 +int has_uncommitted_changes(int ignore_submodules)
2235 {
2236 struct rev_info rev_info;
2237 int result;
@@ -2239,7 +2240,8 @@ int has_uncommitted_changes(void)
2240 return 0;
2241
2242 init_revisions(&rev_info, NULL);
2242 - DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
2243 + if (ignore_submodules)
2244 + DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
2245 DIFF_OPT_SET(&rev_info.diffopt, QUICK);
2246 add_head_to_pending(&rev_info);
2247 diff_setup_done(&rev_info.diffopt);
@@ -2251,7 +2253,7 @@ int has_uncommitted_changes(void)
2253 * If the work tree has unstaged or uncommitted changes, dies with the
2254 * appropriate message.
2255 */
2254 -int require_clean_work_tree(const char *action, const char *hint, int gently)
2256 +int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently)
2257 {
2258 struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
2259 int err = 0;
@@ -2261,13 +2263,13 @@ int require_clean_work_tree(const char *action, const char *hint, int gently)
2263 update_index_if_able(&the_index, lock_file);
2264 rollback_lock_file(lock_file);
2265
2264 - if (has_unstaged_changes()) {
2266 + if (has_unstaged_changes(ignore_submodules)) {
2267 /* TRANSLATORS: the action is e.g. "pull with rebase" */
2268 error(_("Cannot %s: You have unstaged changes."), _(action));
2269 err = 1;
2270 }
2271
2270 - if (has_uncommitted_changes()) {
2272 + if (has_uncommitted_changes(ignore_submodules)) {
2273 if (err)
2274 error(_("Additionally, your index contains uncommitted changes."));
2275 else
wt-status.h
+4 -3
@@ -129,8 +129,9 @@ __attribute__((format (printf, 3, 4)))
129 void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
130
131 /* The following functions expect that the caller took care of reading the index. */
132 -int has_unstaged_changes(void);
133 -int has_uncommitted_changes(void);
134 -int require_clean_work_tree(const char *action, const char *hint, int gently);
132 +int has_unstaged_changes(int ignore_submodules);
133 +int has_uncommitted_changes(int ignore_submodules);
134 +int require_clean_work_tree(const char *action, const char *hint,
135 + int ignore_submodules, int gently);
136
137 #endif /* STATUS_H */