summaryrefslogtreecommitdiffstats
path: root/t/t3200-branch.sh
diff options
context:
space:
mode:
authorGlen Choo <chooglen@google.com>2022-01-29 01:04:42 +0100
committerJunio C Hamano <gitster@pobox.com>2022-02-01 23:18:49 +0100
commitbc0893cf3b0ee376ef5b6ed293b1525480a9d720 (patch)
tree4bb458d2053d0a84494e0417dbd156e421314893 /t/t3200-branch.sh
parentbranch: move --set-upstream-to behavior to dwim_and_setup_tracking() (diff)
downloadgit-bc0893cf3b0ee376ef5b6ed293b1525480a9d720.tar.xz
git-bc0893cf3b0ee376ef5b6ed293b1525480a9d720.zip
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>
Diffstat (limited to 't/t3200-branch.sh')
-rwxr-xr-xt/t3200-branch.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 09ab132377..71a72efcb2 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -42,6 +42,23 @@ test_expect_success 'git branch abc should create a branch' '
git branch abc && test_path_is_file .git/refs/heads/abc
'
+test_expect_success 'git branch abc should fail when abc exists' '
+ test_must_fail git branch abc
+'
+
+test_expect_success 'git branch --force abc should fail when abc is checked out' '
+ test_when_finished git switch main &&
+ git switch abc &&
+ test_must_fail git branch --force abc HEAD~1
+'
+
+test_expect_success 'git branch --force abc should succeed when abc exists' '
+ git rev-parse HEAD~1 >expect &&
+ git branch --force abc HEAD~1 &&
+ git rev-parse abc >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'git branch a/b/c should create a branch' '
git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
'