summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2014-11-30 08:24:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-12-01 19:00:17 (GMT)
commit5883034c61c60e04db16520a759ec67a34ffaea3 (patch)
tree21ab4cc9c42663e5ae792a4ae07f53954550cbcf /t
parent23af91d102e1efaff33b77ab7746356835a3d600 (diff)
downloadgit-5883034c61c60e04db16520a759ec67a34ffaea3.zip
git-5883034c61c60e04db16520a759ec67a34ffaea3.tar.gz
git-5883034c61c60e04db16520a759ec67a34ffaea3.tar.bz2
checkout: reject if the branch is already checked out elsewhere
One branch obviously can't be checked out at two places (but detached heads are ok). Give the user a choice in this case: --detach, -b new-branch, switch branch in the other checkout first or simply 'cd' and continue to work there. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t2025-checkout-to.sh25
1 files changed, 20 insertions, 5 deletions
diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh
index 4963415..edd3404 100755
--- a/t/t2025-checkout-to.sh
+++ b/t/t2025-checkout-to.sh
@@ -18,13 +18,14 @@ test_expect_success 'checkout --to an existing worktree' '
'
test_expect_success 'checkout --to a new worktree' '
- git checkout --to here master &&
+ git rev-parse HEAD >expect &&
+ git checkout --detach --to here master &&
(
cd here &&
test_cmp ../init.t init.t &&
- git symbolic-ref HEAD >actual &&
- echo refs/heads/master >expect &&
- test_cmp expect actual &&
+ test_must_fail git symbolic-ref HEAD &&
+ git rev-parse HEAD >actual &&
+ test_cmp ../expect actual &&
git fsck
)
'
@@ -42,7 +43,7 @@ test_expect_success 'checkout --to a new worktree from a subdir' '
test_expect_success 'checkout --to from a linked checkout' '
(
cd here &&
- git checkout --to nested-here master &&
+ git checkout --detach --to nested-here master &&
cd nested-here &&
git fsck
)
@@ -60,4 +61,18 @@ test_expect_success 'checkout --to a new worktree creating new branch' '
)
'
+test_expect_success 'die the same branch is already checked out' '
+ (
+ cd here &&
+ test_must_fail git checkout newmaster
+ )
+'
+
+test_expect_success 'not die on re-checking out current branch' '
+ (
+ cd there &&
+ git checkout newmaster
+ )
+'
+
test_done