t: add tests for switch
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 29, 2019 at 17:39 UTC
c479ea36c011d3a1f90e1377b979425c10c46765
1 file changed
+96
t/t2060-switch.sh
new
+96
@@ -0,0 +1,96 @@
1
+#!/bin/sh
2
+
3
+test_description='switch basic functionality'
4
+
5
+. ./test-lib.sh
6
+
7
+test_expect_success 'setup' '
8
+ test_commit first &&
9
+ git branch first-branch &&
10
+ test_commit second &&
11
+ test_commit third &&
12
+ git remote add origin nohost:/nopath &&
13
+ git update-ref refs/remotes/origin/foo first-branch
14
+'
15
+
16
+test_expect_success 'switch branch no arguments' '
17
+ test_must_fail git switch
18
+'
19
+
20
+test_expect_success 'switch branch' '
21
+ git switch first-branch &&
22
+ test_path_is_missing second.t
23
+'
24
+
25
+test_expect_success 'switch and detach' '
26
+ test_when_finished git switch master &&
27
+ test_must_fail git switch master^{commit} &&
28
+ git switch --detach master^{commit} &&
29
+ test_must_fail git symbolic-ref HEAD
30
+'
31
+
32
+test_expect_success 'switch and detach current branch' '
33
+ test_when_finished git switch master &&
34
+ git switch master &&
35
+ git switch --detach &&
36
+ test_must_fail git symbolic-ref HEAD
37
+'
38
+
39
+test_expect_success 'switch and create branch' '
40
+ test_when_finished git switch master &&
41
+ git switch -c temp master^ &&
42
+ test_cmp_rev master^ refs/heads/temp &&
43
+ echo refs/heads/temp >expected-branch &&
44
+ git symbolic-ref HEAD >actual-branch &&
45
+ test_cmp expected-branch actual-branch
46
+'
47
+
48
+test_expect_success 'force create branch from HEAD' '
49
+ test_when_finished git switch master &&
50
+ git switch --detach master &&
51
+ test_must_fail git switch -c temp &&
52
+ git switch -C temp &&
53
+ test_cmp_rev master refs/heads/temp &&
54
+ echo refs/heads/temp >expected-branch &&
55
+ git symbolic-ref HEAD >actual-branch &&
56
+ test_cmp expected-branch actual-branch
57
+'
58
+
59
+test_expect_success 'new orphan branch from empty' '
60
+ test_when_finished git switch master &&
61
+ test_must_fail git switch --orphan new-orphan HEAD &&
62
+ git switch --orphan new-orphan &&
63
+ test_commit orphan &&
64
+ git cat-file commit refs/heads/new-orphan >commit &&
65
+ ! grep ^parent commit &&
66
+ git ls-files >tracked-files &&
67
+ echo orphan.t >expected &&
68
+ test_cmp expected tracked-files
69
+'
70
+
71
+test_expect_success 'switching ignores file of same branch name' '
72
+ test_when_finished git switch master &&
73
+ : >first-branch &&
74
+ git switch first-branch &&
75
+ echo refs/heads/first-branch >expected &&
76
+ git symbolic-ref HEAD >actual &&
77
+ test_cmp expected actual
78
+'
79
+
80
+test_expect_success 'guess and create branch ' '
81
+ test_when_finished git switch master &&
82
+ test_must_fail git switch --no-guess foo &&
83
+ git switch foo &&
84
+ echo refs/heads/foo >expected &&
85
+ git symbolic-ref HEAD >actual &&
86
+ test_cmp expected actual
87
+'
88
+
89
+test_expect_success 'not switching when something is in progress' '
90
+ test_when_finished rm -f .git/MERGE_HEAD &&
91
+ # fake a merge-in-progress
92
+ cp .git/HEAD .git/MERGE_HEAD &&
93
+ test_must_fail git switch -d @^
94
+'
95
+
96
+test_done