Skip to content

Commit e4da5b0

Browse files
jeffhostetlerdscho
authored andcommitted
status: deserialize with -uno does not print correct hint
With the "--untracked-files=complete" option status computes a superset of the untracked files. We use this when writing the status cache. If subsequent deserialize commands ask for either the complete set or one of the "no", "normal", or "all" subsets, it can still use the cache file because of filtering in the deserialize parser. When running status with the "-uno" option, the long format status would print a "(use -u to show untracked files)" hint. When deserializing with the "-uno" option and using a cache computed with "-ucomplete", the "nothing to commit, working tree clean" message would be printed instead of the hint. It was easy to miss because the correct hint message was printed if the cache was rejected for any reason (and status did the full fallback). The "struct wt_status des" structure was initialized with the content of the status cache (and thus defaulted to "complete"). This change sets "des.show_untracked_files" to the requested subset from the command-line or config. This allows the long format to print the hint. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 6ca188e commit e4da5b0

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

t/t7522-serialized-status.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,59 @@ test_expect_success 'renames' '
345345
test_cmp output.1 output.2
346346
'
347347

348+
test_expect_success 'hint message when cached with u=complete' '
349+
git init -b main hint &&
350+
echo xxx >hint/xxx &&
351+
git -C hint add xxx &&
352+
git -C hint commit -m xxx &&
353+
354+
cat >expect.clean <<EOF &&
355+
On branch main
356+
nothing to commit, working tree clean
357+
EOF
358+
359+
cat >expect.use_u <<EOF &&
360+
On branch main
361+
nothing to commit (use -u to show untracked files)
362+
EOF
363+
364+
# Capture long format output from "no", "normal", and "all"
365+
# (without using status cache) and verify it matches expected
366+
# output.
367+
368+
git -C hint status --untracked-files=normal >hint.output_normal &&
369+
test_cmp expect.clean hint.output_normal &&
370+
371+
git -C hint status --untracked-files=all >hint.output_all &&
372+
test_cmp expect.clean hint.output_all &&
373+
374+
git -C hint status --untracked-files=no >hint.output_no &&
375+
test_cmp expect.use_u hint.output_no &&
376+
377+
# Create long format output for "complete" and create status cache.
378+
379+
git -C hint status --untracked-files=complete --ignored=matching --serialize=../hint.dat >hint.output_complete &&
380+
test_cmp expect.clean hint.output_complete &&
381+
382+
# Capture long format output using the status cache and verify
383+
# that the output matches the non-cached version. There are 2
384+
# ways to specify untracked-files, so do them both.
385+
386+
git -C hint status --deserialize=../hint.dat -unormal >hint.d1_normal &&
387+
test_cmp expect.clean hint.d1_normal &&
388+
git -C hint -c status.showuntrackedfiles=normal status --deserialize=../hint.dat >hint.d2_normal &&
389+
test_cmp expect.clean hint.d2_normal &&
390+
391+
git -C hint status --deserialize=../hint.dat -uall >hint.d1_all &&
392+
test_cmp expect.clean hint.d1_all &&
393+
git -C hint -c status.showuntrackedfiles=all status --deserialize=../hint.dat >hint.d2_all &&
394+
test_cmp expect.clean hint.d2_all &&
395+
396+
git -C hint status --deserialize=../hint.dat -uno >hint.d1_no &&
397+
test_cmp expect.use_u hint.d1_no &&
398+
git -C hint -c status.showuntrackedfiles=no status --deserialize=../hint.dat >hint.d2_no &&
399+
test_cmp expect.use_u hint.d2_no
400+
401+
'
402+
348403
test_done

wt-status-deserialize.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,20 +424,24 @@ static int wt_deserialize_v1_ignored_items(struct wt_status *s,
424424
}
425425

426426
static int validate_untracked_files_arg(enum untracked_status_type cmd,
427-
enum untracked_status_type des,
427+
enum untracked_status_type *des,
428428
enum deserialize_parse_strategy *strategy)
429429
{
430430
*strategy = DESERIALIZE_STRATEGY_AS_IS;
431431

432-
if (cmd == des) {
432+
if (cmd == *des) {
433433
*strategy = DESERIALIZE_STRATEGY_AS_IS;
434434
} else if (cmd == SHOW_NO_UNTRACKED_FILES) {
435435
*strategy = DESERIALIZE_STRATEGY_SKIP;
436-
} else if (des == SHOW_COMPLETE_UNTRACKED_FILES) {
437-
if (cmd == SHOW_ALL_UNTRACKED_FILES)
436+
*des = cmd;
437+
} else if (*des == SHOW_COMPLETE_UNTRACKED_FILES) {
438+
if (cmd == SHOW_ALL_UNTRACKED_FILES) {
438439
*strategy = DESERIALIZE_STRATEGY_ALL;
439-
else if (cmd == SHOW_NORMAL_UNTRACKED_FILES)
440+
*des = cmd;
441+
} else if (cmd == SHOW_NORMAL_UNTRACKED_FILES) {
440442
*strategy = DESERIALIZE_STRATEGY_NORMAL;
443+
*des = cmd;
444+
}
441445
} else {
442446
return DESERIALIZE_ERR;
443447
}
@@ -479,7 +483,7 @@ static int wt_deserialize_v1(const struct wt_status *cmd_s, struct wt_status *s,
479483
* We now have the header parsed. Look at the command args (as passed in), and see how to parse
480484
* the serialized data
481485
*/
482-
if (validate_untracked_files_arg(cmd_s->show_untracked_files, s->show_untracked_files, &untracked_strategy)) {
486+
if (validate_untracked_files_arg(cmd_s->show_untracked_files, &s->show_untracked_files, &untracked_strategy)) {
483487
trace_printf_key(&trace_deserialize, "reject: show_untracked_file: command: %d, serialized : %d",
484488
cmd_s->show_untracked_files,
485489
s->show_untracked_files);

0 commit comments

Comments
 (0)