1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2010 Erick Mattos
4
+#
5
+
6
+test_description='git checkout --orphan
7
+
8
+Main Tests for --orphan functionality.'
9
+
10
+. ./test-lib.sh
11
+
12
+TEST_FILE=foo
13
+
14
+test_expect_success 'Setup' '
15
+ echo "Initial" >"$TEST_FILE" &&
16
+ git add "$TEST_FILE" &&
17
+ git commit -m "First Commit"
18
+ test_tick &&
19
+ echo "State 1" >>"$TEST_FILE" &&
20
+ git add "$TEST_FILE" &&
21
+ test_tick &&
22
+ git commit -m "Second Commit"
23
+'
24
+
25
+test_expect_success '--orphan creates a new orphan branch from HEAD' '
26
+ git checkout --orphan alpha &&
27
+ test_must_fail git rev-parse --verify HEAD &&
28
+ test "refs/heads/alpha" = "$(git symbolic-ref HEAD)" &&
29
+ test_tick &&
30
+ git commit -m "Third Commit" &&
31
+ test_must_fail git rev-parse --verify HEAD^ &&
32
+ git diff-tree --quiet master alpha
33
+'
34
+
35
+test_expect_success '--orphan creates a new orphan branch from <start_point>' '
36
+ git checkout master &&
37
+ git checkout --orphan beta master^ &&
38
+ test_must_fail git rev-parse --verify HEAD &&
39
+ test "refs/heads/beta" = "$(git symbolic-ref HEAD)" &&
40
+ test_tick &&
41
+ git commit -m "Fourth Commit" &&
42
+ test_must_fail git rev-parse --verify HEAD^ &&
43
+ git diff-tree --quiet master^ beta
44
+'
45
+
46
+test_expect_success '--orphan must be rejected with -b' '
47
+ git checkout master &&
48
+ test_must_fail git checkout --orphan new -b newer &&
49
+ test refs/heads/master = "$(git symbolic-ref HEAD)"
50
+'
51
+
52
+test_expect_success '--orphan is rejected with an existing name' '
53
+ git checkout master &&
54
+ test_must_fail git checkout --orphan master &&
55
+ test refs/heads/master = "$(git symbolic-ref HEAD)"
56
+'
57
+
58
+test_expect_success '--orphan refuses to switch if a merge is needed' '
59
+ git checkout master &&
60
+ git reset --hard &&
61
+ echo local >>"$TEST_FILE" &&
62
+ cat "$TEST_FILE" >"$TEST_FILE.saved" &&
63
+ test_must_fail git checkout --orphan gamma master^ &&
64
+ test refs/heads/master = "$(git symbolic-ref HEAD)" &&
65
+ test_cmp "$TEST_FILE" "$TEST_FILE.saved" &&
66
+ git diff-index --quiet --cached HEAD &&
67
+ git reset --hard
68
+'
69
+
70
+test_expect_success '--orphan does not mix well with -t' '
71
+ git checkout master &&
72
+ test_must_fail git checkout -t master --orphan gamma &&
73
+ test refs/heads/master = "$(git symbolic-ref HEAD)"
74
+'
75
+
76
+test_expect_success '--orphan ignores branch.autosetupmerge' '
77
+ git checkout -f master &&
78
+ git config branch.autosetupmerge always &&
79
+ git checkout --orphan delta &&
80
+ test -z "$(git config branch.delta.merge)" &&
81
+ test refs/heads/delta = "$(git symbolic-ref HEAD)" &&
82
+ test_must_fail git rev-parse --verify HEAD^
83
+'
84
+
85
+test_expect_success '--orphan does not mix well with -l' '
86
+ git checkout -f master &&
87
+ test_must_fail git checkout -l --orphan gamma
88
+'
89
+
90
+test_done