Skip to content

Commit f7e56ef

Browse files
committed
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>
1 parent 835ee43 commit f7e56ef

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

builtin/pull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
777777
git_config_get_bool("rebase.autostash", &autostash);
778778
if (!autostash)
779779
require_clean_work_tree("pull with rebase",
780-
"Please commit or stash them.", 0);
780+
"Please commit or stash them.", 1, 0);
781781

782782
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
783783
hashclr(rebase_fork_point);

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ static int do_exec(const char *command_line)
15071507
status = run_command_v_opt(child_argv, RUN_USING_SHELL);
15081508

15091509
discard_cache(); /* force re-reading of the cache */
1510-
dirty = require_clean_work_tree("rebase", NULL, 1);
1510+
dirty = require_clean_work_tree("rebase", NULL, 1, 1);
15111511

15121512
if (status) {
15131513
warning("Execution failed: %s\n%s"

wt-status.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,13 +1736,14 @@ void wt_porcelain_print(struct wt_status *s)
17361736
/**
17371737
* Returns 1 if there are unstaged changes, 0 otherwise.
17381738
*/
1739-
int has_unstaged_changes()
1739+
int has_unstaged_changes(int ignore_submodules)
17401740
{
17411741
struct rev_info rev_info;
17421742
int result;
17431743

17441744
init_revisions(&rev_info, NULL);
1745-
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
1745+
if (ignore_submodules)
1746+
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
17461747
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
17471748
diff_setup_done(&rev_info.diffopt);
17481749
result = run_diff_files(&rev_info, 0);
@@ -1752,7 +1753,7 @@ int has_unstaged_changes()
17521753
/**
17531754
* Returns 1 if there are uncommitted changes, 0 otherwise.
17541755
*/
1755-
int has_uncommitted_changes()
1756+
int has_uncommitted_changes(int ignore_submodules)
17561757
{
17571758
struct rev_info rev_info;
17581759
int result;
@@ -1761,7 +1762,8 @@ int has_uncommitted_changes()
17611762
return 0;
17621763

17631764
init_revisions(&rev_info, NULL);
1764-
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
1765+
if (ignore_submodules)
1766+
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
17651767
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
17661768
add_head_to_pending(&rev_info);
17671769
diff_setup_done(&rev_info.diffopt);
@@ -1773,7 +1775,7 @@ int has_uncommitted_changes()
17731775
* If the work tree has unstaged or uncommitted changes, dies with the
17741776
* appropriate message.
17751777
*/
1776-
int require_clean_work_tree(const char *action, const char *hint, int gently)
1778+
int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently)
17771779
{
17781780
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
17791781
int err = 0;
@@ -1790,12 +1792,12 @@ int require_clean_work_tree(const char *action, const char *hint, int gently)
17901792
update_index_if_able(&the_index, lock_file);
17911793
rollback_lock_file(lock_file);
17921794

1793-
if (has_unstaged_changes()) {
1795+
if (has_unstaged_changes(ignore_submodules)) {
17941796
error(_("Cannot %s: You have unstaged changes."), action);
17951797
err = 1;
17961798
}
17971799

1798-
if (has_uncommitted_changes()) {
1800+
if (has_uncommitted_changes(ignore_submodules)) {
17991801
if (err)
18001802
error(_("Additionally, your index contains uncommitted changes."));
18011803
else

wt-status.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, .
109109
__attribute__((format (printf, 3, 4)))
110110
void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
111111

112-
int has_unstaged_changes();
113-
int has_uncommitted_changes();
114-
int require_clean_work_tree(const char *action, const char *hint, int gently);
112+
int has_unstaged_changes(int ignore_submodules);
113+
int has_uncommitted_changes(int ignore_submodules);
114+
int require_clean_work_tree(const char *action, const char *hint,
115+
int ignore_submodules, int gently);
115116

116117
#endif /* STATUS_H */

0 commit comments

Comments
 (0)