Skip to content

Commit d8cc92a

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41a5dd6 commit d8cc92a

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

builtin/pull.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
810810

811811
if (!autostash)
812812
require_clean_work_tree(N_("pull with rebase"),
813-
_("please commit or stash them."), 0);
813+
_("please commit or stash them."), 1, 0);
814814

815815
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
816816
hashclr(rebase_fork_point);

wt-status.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -2214,13 +2214,14 @@ void wt_status_print(struct wt_status *s)
22142214
/**
22152215
* Returns 1 if there are unstaged changes, 0 otherwise.
22162216
*/
2217-
int has_unstaged_changes(void)
2217+
int has_unstaged_changes(int ignore_submodules)
22182218
{
22192219
struct rev_info rev_info;
22202220
int result;
22212221

22222222
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);
22242225
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
22252226
diff_setup_done(&rev_info.diffopt);
22262227
result = run_diff_files(&rev_info, 0);
@@ -2230,7 +2231,7 @@ int has_unstaged_changes(void)
22302231
/**
22312232
* Returns 1 if there are uncommitted changes, 0 otherwise.
22322233
*/
2233-
int has_uncommitted_changes(void)
2234+
int has_uncommitted_changes(int ignore_submodules)
22342235
{
22352236
struct rev_info rev_info;
22362237
int result;
@@ -2239,7 +2240,8 @@ int has_uncommitted_changes(void)
22392240
return 0;
22402241

22412242
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);
22432245
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
22442246
add_head_to_pending(&rev_info);
22452247
diff_setup_done(&rev_info.diffopt);
@@ -2251,7 +2253,7 @@ int has_uncommitted_changes(void)
22512253
* If the work tree has unstaged or uncommitted changes, dies with the
22522254
* appropriate message.
22532255
*/
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)
22552257
{
22562258
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
22572259
int err = 0;
@@ -2261,13 +2263,13 @@ int require_clean_work_tree(const char *action, const char *hint, int gently)
22612263
update_index_if_able(&the_index, lock_file);
22622264
rollback_lock_file(lock_file);
22632265

2264-
if (has_unstaged_changes()) {
2266+
if (has_unstaged_changes(ignore_submodules)) {
22652267
/* TRANSLATORS: the action is e.g. "pull with rebase" */
22662268
error(_("Cannot %s: You have unstaged changes."), _(action));
22672269
err = 1;
22682270
}
22692271

2270-
if (has_uncommitted_changes()) {
2272+
if (has_uncommitted_changes(ignore_submodules)) {
22712273
if (err)
22722274
error(_("Additionally, your index contains uncommitted changes."));
22732275
else

wt-status.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ __attribute__((format (printf, 3, 4)))
129129
void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
130130

131131
/* 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);
135136

136137
#endif /* STATUS_H */

0 commit comments

Comments
 (0)