Skip to content

Commit 3ba7407

Browse files
moygitster
authored andcommitted
submodule summary: ignore --for-status option
The --for-status option was an undocumented option used only by wt-status.c, which inserted a header and commented out the output. We can achieve the same result within wt-status.c, without polluting the submodule command-line options. This will make it easier to disable the comments from wt-status.c later. The --for-status is kept so that another topic in flight (bc/submodule-status-ignored) can continue relying on it, although it is currently a no-op. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb7e32e commit 3ba7407

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

git-submodule.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,18 +1149,7 @@ cmd_summary() {
11491149
echo
11501150
fi
11511151
echo
1152-
done |
1153-
if test -n "$for_status"; then
1154-
if [ -n "$files" ]; then
1155-
gettextln "Submodules changed but not updated:" | git stripspace -c
1156-
else
1157-
gettextln "Submodule changes to be committed:" | git stripspace -c
1158-
fi
1159-
printf "\n" | git stripspace -c
1160-
git stripspace -c
1161-
else
1162-
cat
1163-
fi
1152+
done
11641153
}
11651154
#
11661155
# List all submodules, prefixed with:

t/t7401-submodule-summary.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,11 @@ EOF
265265
test_expect_success '--for-status' "
266266
git submodule summary --for-status HEAD^ >actual &&
267267
test_i18ncmp actual - <<EOF
268-
# Submodule changes to be committed:
269-
#
270-
# * sm1 $head6...0000000:
271-
#
272-
# * sm2 0000000...$head7 (2):
273-
# > Add foo9
274-
#
268+
* sm1 $head6...0000000:
269+
270+
* sm2 0000000...$head7 (2):
271+
> Add foo9
272+
275273
EOF
276274
"
277275

wt-status.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,10 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
665665
char index[PATH_MAX];
666666
const char *env[] = { NULL, NULL };
667667
struct argv_array argv = ARGV_ARRAY_INIT;
668+
struct strbuf cmd_stdout = STRBUF_INIT;
669+
struct strbuf summary = STRBUF_INIT;
670+
char *summary_content;
671+
size_t len;
668672

669673
sprintf(summary_limit, "%d", s->submodule_summary);
670674
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
@@ -685,9 +689,30 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
685689
sm_summary.git_cmd = 1;
686690
sm_summary.no_stdin = 1;
687691
fflush(s->fp);
688-
sm_summary.out = dup(fileno(s->fp)); /* run_command closes it */
692+
sm_summary.out = -1;
693+
689694
run_command(&sm_summary);
690695
argv_array_clear(&argv);
696+
697+
len = strbuf_read(&cmd_stdout, sm_summary.out, 1024);
698+
699+
/* prepend header, only if there's an actual output */
700+
if (len) {
701+
if (uncommitted)
702+
strbuf_addstr(&summary, _("Submodules changed but not updated:"));
703+
else
704+
strbuf_addstr(&summary, _("Submodule changes to be committed:"));
705+
strbuf_addstr(&summary, "\n\n");
706+
}
707+
strbuf_addbuf(&summary, &cmd_stdout);
708+
strbuf_release(&cmd_stdout);
709+
710+
summary_content = strbuf_detach(&summary, &len);
711+
strbuf_add_commented_lines(&summary, summary_content, len);
712+
free(summary_content);
713+
714+
fputs(summary.buf, s->fp);
715+
strbuf_release(&summary);
691716
}
692717

693718
static void wt_status_print_other(struct wt_status *s,

0 commit comments

Comments
 (0)