checkout: add basic tests for detached-orphan warning
Commit 8e2dc6ac added a warning when we leave a detached HEAD whose commit is not reachable from any ref tip. Let's add a few basic tests to make sure it works. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Mar 20, 2011 at 05:04 UTC
493dd6ed5b46659d7e20aaef00f97e279ce1c4cb
1 file changed
+34
t/t2020-checkout-detach.sh
+34
@@ -11,6 +11,14 @@ check_not_detached () {
11
git symbolic-ref -q HEAD >/dev/null
12
}
13
14
+ORPHAN_WARNING='you are leaving .* commit.*behind'
15
+check_orphan_warning() {
16
+ grep "$ORPHAN_WARNING" "$1"
17
+}
18
+check_no_orphan_warning() {
19
+ ! grep "$ORPHAN_WARNING" "$1"
20
+}
21
+
22
reset () {
23
git checkout master &&
24
check_not_detached
@@ -19,6 +27,8 @@ reset () {
27
test_expect_success 'setup' '
28
test_commit one &&
29
test_commit two &&
30
+ test_commit three && git tag -d three &&
31
+ test_commit four && git tag -d four &&
32
git branch branch &&
33
git tag tag
34
'
@@ -92,4 +102,28 @@ test_expect_success 'checkout --detach moves HEAD' '
102
git diff --exit-code two
103
'
104
105
+test_expect_success 'checkout warns on orphan commits' '
106
+ reset &&
107
+ git checkout --detach two &&
108
+ echo content >orphan &&
109
+ git add orphan &&
110
+ git commit -a -m orphan &&
111
+ git checkout master 2>stderr &&
112
+ check_orphan_warning stderr
113
+'
114
+
115
+test_expect_success 'checkout does not warn leaving ref tip' '
116
+ reset &&
117
+ git checkout --detach two &&
118
+ git checkout master 2>stderr &&
119
+ check_no_orphan_warning stderr
120
+'
121
+
122
+test_expect_success 'checkout does not warn leaving reachable commit' '
123
+ reset &&
124
+ git checkout --detach HEAD^ &&
125
+ git checkout master 2>stderr &&
126
+ check_no_orphan_warning stderr
127
+'
128
+
129
test_done