Skip to content

Commit

Permalink
Teach ahead-behind and serialized status to play nicely together
Browse files Browse the repository at this point in the history
  • Loading branch information
jamill authored and vdye committed Jul 19, 2023
1 parent 6668a14 commit 1765859
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
34 changes: 33 additions & 1 deletion t/t7522-serialized-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ test_expect_success 'setup' '
git commit -m"Adding original file." &&
mkdir untracked &&
touch ignored.ign ignored_dir/ignored_2.txt \
untracked_1.txt untracked/untracked_2.txt untracked/untracked_3.txt
untracked_1.txt untracked/untracked_2.txt untracked/untracked_3.txt &&
test_oid_cache <<-EOF
branch_oid sha1:68d4a437ea4c2de65800f48c053d4d543b55c410
branch_oid sha256:6b95e4b1ea911dad213f2020840f5e92d3066cf9e38cf35f79412ec58d409ce4
EOF
'

test_expect_success 'verify untracked-files=complete with no conversion' '
Expand Down Expand Up @@ -138,4 +144,30 @@ test_expect_success 'verify serialized status handles path scopes' '
test_cmp expect output
'

test_expect_success 'verify no-ahead-behind and serialized status integration' '
test_when_finished "rm serialized_status.dat new_change.txt output" &&
cat >expect <<-EOF &&
# branch.oid $(test_oid branch_oid)
# branch.head alt_branch
# branch.upstream main
# branch.ab +1 -0
? expect
? serialized_status.dat
? untracked/
? untracked_1.txt
EOF
git checkout -b alt_branch main --track >/dev/null &&
touch alt_branch_changes.txt &&
git add alt_branch_changes.txt &&
test_tick &&
git commit -m"New commit on alt branch" &&
git status --untracked-files=complete --ignored=matching --serialize >serialized_status.dat &&
touch new_change.txt &&
git -c status.aheadBehind=false status --porcelain=v2 --branch --ahead-behind --deserialize=serialized_status.dat >output &&
test_cmp expect output
'

test_done
3 changes: 2 additions & 1 deletion wt-status-deserialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
/* show_branch */
/* show_stash */
/* hints */
/* ahead_behind_flags */
if (cmd_s->detect_rename != des_s->detect_rename) {
trace_printf_key(&trace_deserialize, "reject: detect_rename");
return DESERIALIZE_ERR;
Expand Down Expand Up @@ -555,6 +556,7 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
des_s->show_branch = cmd_s->show_branch;
des_s->show_stash = cmd_s->show_stash;
/* hints */
des_s->ahead_behind_flags = cmd_s->ahead_behind_flags;
des_s->status_format = cmd_s->status_format;
des_s->fp = cmd_s->fp;
if (cmd_s->prefix && *cmd_s->prefix)
Expand All @@ -563,7 +565,6 @@ static int wt_deserialize_fd(const struct wt_status *cmd_s, struct wt_status *de
return DESERIALIZE_OK;
}


/*
* Read raw serialized status data from the given file
*
Expand Down
1 change: 1 addition & 0 deletions wt-status-serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static void wt_serialize_v1_header(struct wt_status *s, int fd)
/* show_branch */
/* show_stash */
packet_write_fmt(fd, "hints %d\n", s->hints);
/* ahead_behind_flags */
packet_write_fmt(fd, "detect_rename %d\n", s->detect_rename);
packet_write_fmt(fd, "rename_score %d\n", s->rename_score);
packet_write_fmt(fd, "rename_limit %d\n", s->rename_limit);
Expand Down

0 comments on commit 1765859

Please sign in to comment.