summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgit-submodule.sh13
-rwxr-xr-xt/t7401-submodule-summary.sh12
-rw-r--r--wt-status.c27
3 files changed, 32 insertions, 20 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 2979197087..c17bef1062 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -1149,18 +1149,7 @@ cmd_summary() {
echo
fi
echo
- done |
- if test -n "$for_status"; then
- if [ -n "$files" ]; then
- gettextln "Submodules changed but not updated:" | git stripspace -c
- else
- gettextln "Submodule changes to be committed:" | git stripspace -c
- fi
- printf "\n" | git stripspace -c
- git stripspace -c
- else
- cat
- fi
+ done
}
#
# List all submodules, prefixed with:
diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh
index ac2434c0db..5a6d6d62eb 100755
--- a/t/t7401-submodule-summary.sh
+++ b/t/t7401-submodule-summary.sh
@@ -265,13 +265,11 @@ EOF
test_expect_success '--for-status' "
git submodule summary --for-status HEAD^ >actual &&
test_i18ncmp actual - <<EOF
-# Submodule changes to be committed:
-#
-# * sm1 $head6...0000000:
-#
-# * sm2 0000000...$head7 (2):
-# > Add foo9
-#
+* sm1 $head6...0000000:
+
+* sm2 0000000...$head7 (2):
+ > Add foo9
+
EOF
"
diff --git a/wt-status.c b/wt-status.c
index 958a53c9cb..853813f560 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -665,6 +665,10 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
char index[PATH_MAX];
const char *env[] = { NULL, NULL };
struct argv_array argv = ARGV_ARRAY_INIT;
+ struct strbuf cmd_stdout = STRBUF_INIT;
+ struct strbuf summary = STRBUF_INIT;
+ char *summary_content;
+ size_t len;
sprintf(summary_limit, "%d", s->submodule_summary);
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
sm_summary.git_cmd = 1;
sm_summary.no_stdin = 1;
fflush(s->fp);
- sm_summary.out = dup(fileno(s->fp)); /* run_command closes it */
+ sm_summary.out = -1;
+
run_command(&sm_summary);
argv_array_clear(&argv);
+
+ len = strbuf_read(&cmd_stdout, sm_summary.out, 1024);
+
+ /* prepend header, only if there's an actual output */
+ if (len) {
+ if (uncommitted)
+ strbuf_addstr(&summary, _("Submodules changed but not updated:"));
+ else
+ strbuf_addstr(&summary, _("Submodule changes to be committed:"));
+ strbuf_addstr(&summary, "\n\n");
+ }
+ strbuf_addbuf(&summary, &cmd_stdout);
+ strbuf_release(&cmd_stdout);
+
+ summary_content = strbuf_detach(&summary, &len);
+ strbuf_add_commented_lines(&summary, summary_content, len);
+ free(summary_content);
+
+ fputs(summary.buf, s->fp);
+ strbuf_release(&summary);
}
static void wt_status_print_other(struct wt_status *s,