status: fix null termination with "-b"

When the "-z" option is given to status, we are supposed to NUL-terminate each record. However, the "-b" code to show the tracking branch did not respect this, and always ended with a newline. Signed-off-by: Jeff King <peff@peff.net>

Jeff King committed May 7, 2012 at 17:02 UTC a5985237878481af5fbca349d0d1ad7d6b2d2bcb
2 files changed +13 -3
t/t7508-status.sh
+9
@@ -271,6 +271,15 @@ test_expect_success 'status -s -b' '
271
272 '
273
274 +test_expect_success 'status -s -z -b' '
275 + tr "\\n" Q <expect >expect.q &&
276 + mv expect.q expect &&
277 + git status -s -z -b >output &&
278 + nul_to_q <output >output.q &&
279 + mv output.q output &&
280 + test_cmp expect output
281 +'
282 +
283 test_expect_success 'setup dir3' '
284 mkdir dir3 &&
285 : >dir3/untracked1 &&
wt-status.c
+4 -3
@@ -889,8 +889,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
889 if (s->is_initial)
890 color_fprintf(s->fp, header_color, _("Initial commit on "));
891 if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
892 - color_fprintf_ln(s->fp, branch_color_local,
893 - "%s", branch_name);
892 + color_fprintf(s->fp, branch_color_local, "%s", branch_name);
893 + fputc(s->null_termination ? '\0' : '\n', s->fp);
894 return;
895 }
896
@@ -914,7 +914,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
914 color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
915 }
916
917 - color_fprintf_ln(s->fp, header_color, "]");
917 + color_fprintf(s->fp, header_color, "]");
918 + fputc(s->null_termination ? '\0' : '\n', s->fp);
919 }
920
921 void wt_shortstatus_print(struct wt_status *s, int show_branch)