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>
This commit is contained in:
Johannes Schindelin 2016-10-07 18:09:00 +02:00 committed by Junio C Hamano
parent 41a5dd6d86
commit d8cc92ab13
3 changed files with 14 additions and 11 deletions

View File

@ -810,7 +810,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
if (!autostash) if (!autostash)
require_clean_work_tree(N_("pull with rebase"), require_clean_work_tree(N_("pull with rebase"),
_("please commit or stash them."), 0); _("please commit or stash them."), 1, 0);
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs)) if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
hashclr(rebase_fork_point); hashclr(rebase_fork_point);

View File

@ -2214,13 +2214,14 @@ void wt_status_print(struct wt_status *s)
/** /**
* Returns 1 if there are unstaged changes, 0 otherwise. * Returns 1 if there are unstaged changes, 0 otherwise.
*/ */
int has_unstaged_changes(void) int has_unstaged_changes(int ignore_submodules)
{ {
struct rev_info rev_info; struct rev_info rev_info;
int result; int result;
init_revisions(&rev_info, NULL); init_revisions(&rev_info, NULL);
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES); if (ignore_submodules)
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
DIFF_OPT_SET(&rev_info.diffopt, QUICK); DIFF_OPT_SET(&rev_info.diffopt, QUICK);
diff_setup_done(&rev_info.diffopt); diff_setup_done(&rev_info.diffopt);
result = run_diff_files(&rev_info, 0); result = run_diff_files(&rev_info, 0);
@ -2230,7 +2231,7 @@ int has_unstaged_changes(void)
/** /**
* Returns 1 if there are uncommitted changes, 0 otherwise. * Returns 1 if there are uncommitted changes, 0 otherwise.
*/ */
int has_uncommitted_changes(void) int has_uncommitted_changes(int ignore_submodules)
{ {
struct rev_info rev_info; struct rev_info rev_info;
int result; int result;
@ -2239,7 +2240,8 @@ int has_uncommitted_changes(void)
return 0; return 0;
init_revisions(&rev_info, NULL); init_revisions(&rev_info, NULL);
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES); if (ignore_submodules)
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
DIFF_OPT_SET(&rev_info.diffopt, QUICK); DIFF_OPT_SET(&rev_info.diffopt, QUICK);
add_head_to_pending(&rev_info); add_head_to_pending(&rev_info);
diff_setup_done(&rev_info.diffopt); diff_setup_done(&rev_info.diffopt);
@ -2251,7 +2253,7 @@ int has_uncommitted_changes(void)
* If the work tree has unstaged or uncommitted changes, dies with the * If the work tree has unstaged or uncommitted changes, dies with the
* appropriate message. * appropriate message.
*/ */
int require_clean_work_tree(const char *action, const char *hint, int gently) int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently)
{ {
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file)); struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
int err = 0; int err = 0;
@ -2261,13 +2263,13 @@ int require_clean_work_tree(const char *action, const char *hint, int gently)
update_index_if_able(&the_index, lock_file); update_index_if_able(&the_index, lock_file);
rollback_lock_file(lock_file); rollback_lock_file(lock_file);
if (has_unstaged_changes()) { if (has_unstaged_changes(ignore_submodules)) {
/* TRANSLATORS: the action is e.g. "pull with rebase" */ /* TRANSLATORS: the action is e.g. "pull with rebase" */
error(_("Cannot %s: You have unstaged changes."), _(action)); error(_("Cannot %s: You have unstaged changes."), _(action));
err = 1; err = 1;
} }
if (has_uncommitted_changes()) { if (has_uncommitted_changes(ignore_submodules)) {
if (err) if (err)
error(_("Additionally, your index contains uncommitted changes.")); error(_("Additionally, your index contains uncommitted changes."));
else else

View File

@ -129,8 +129,9 @@ __attribute__((format (printf, 3, 4)))
void status_printf(struct wt_status *s, const char *color, const char *fmt, ...); void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
/* The following functions expect that the caller took care of reading the index. */ /* The following functions expect that the caller took care of reading the index. */
int has_unstaged_changes(void); int has_unstaged_changes(int ignore_submodules);
int has_uncommitted_changes(void); int has_uncommitted_changes(int ignore_submodules);
int require_clean_work_tree(const char *action, const char *hint, int gently); int require_clean_work_tree(const char *action, const char *hint,
int ignore_submodules, int gently);
#endif /* STATUS_H */ #endif /* STATUS_H */