Skip to content

Commit

Permalink
status: fix null termination with "-b"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King committed May 8, 2012
1 parent 3207a3a commit a598523
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions t/t7508-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ test_expect_success 'status -s -b' '
'

test_expect_success 'status -s -z -b' '
tr "\\n" Q <expect >expect.q &&
mv expect.q expect &&
git status -s -z -b >output &&
nul_to_q <output >output.q &&
mv output.q output &&
test_cmp expect output
'

test_expect_success 'setup dir3' '
mkdir dir3 &&
: >dir3/untracked1 &&
Expand Down
7 changes: 4 additions & 3 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
if (s->is_initial)
color_fprintf(s->fp, header_color, _("Initial commit on "));
if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
color_fprintf_ln(s->fp, branch_color_local,
"%s", branch_name);
color_fprintf(s->fp, branch_color_local, "%s", branch_name);
fputc(s->null_termination ? '\0' : '\n', s->fp);
return;
}

Expand All @@ -914,7 +914,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
}

color_fprintf_ln(s->fp, header_color, "]");
color_fprintf(s->fp, header_color, "]");
fputc(s->null_termination ? '\0' : '\n', s->fp);
}

void wt_shortstatus_print(struct wt_status *s, int show_branch)
Expand Down

0 comments on commit a598523

Please sign in to comment.