branch: make create_branch() always create a branch

With the previous commit, there are no more invocations of
create_branch() that do not create a branch because:

* BRANCH_TRACK_OVERRIDE is no longer passed
* clobber_head_ok = true and force = false is never passed

Assert these situations, delete dead code and ensure that we're handling
clobber_head_ok and force correctly by introducing tests for `git branch
--force`. As a result, create_branch() now always creates a branch.

Helped-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Glen Choo
2022-01-28 16:04:42 -08:00
committed by Junio C Hamano
parent e89f151db1
commit bc0893cf3b
3 changed files with 45 additions and 31 deletions

View File

@ -52,8 +52,8 @@ void dwim_and_setup_tracking(struct repository *r, const char *new_ref,
*
* - force enables overwriting an existing (non-head) branch
*
* - clobber_head_ok allows the currently checked out (hence existing)
* branch to be overwritten; without 'force', it has no effect.
* - clobber_head_ok, when enabled with 'force', allows the currently
* checked out (head) branch to be overwritten
*
* - reflog creates a reflog for the branch
*