]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/fetch.c
fetch: use new branch_checked_out() and add tests
authorDerrick Stolee <derrickstolee@github.com>
Tue, 14 Jun 2022 19:27:31 +0000 (19:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Jun 2022 17:47:18 +0000 (10:47 -0700)
commit12d47e3b1fbdc3891ec9d2106a43809ce7fa1363
treee77641c24fa711a86d784688c057429089b69277
parentd2ba271aad0e7f90b475be6225c59cb4f1bfbe4f
fetch: use new branch_checked_out() and add tests

When fetching refs from a remote, it is possible that the refspec will
cause use to overwrite a ref that is checked out in a worktree. The
existing logic in builtin/fetch.c uses a possibly-slow mechanism. Update
those sections to use the new, more efficient branch_checked_out()
helper.

These uses were not previously tested, so add a test case that can be
used for these kinds of collisions. There is only one test now, but more
tests will be added as other consumers of branch_checked_out() are
added.

Note that there are two uses in builtin/fetch.c, but only one of the
messages is tested. This is because the tested check is run before
completing the fetch, and the untested check is not reachable without
concurrent updates to the filesystem. Thus, it is beneficial to keep
that extra check for the sake of defense-in-depth. However, we should
not attempt to test the check, as the effort required is too
complicated to be worth the effort. This use in update_local_ref()
also requires a change in the error message because we no longer have
access to the worktree struct, only the path of the worktree. This error
is so rare that making a distinction between the two is not critical.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
t/t2407-worktree-heads.sh