1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
56
test_description='git-checkout tests.'
78
. ./test-lib.sh
910
fill () {
11for i
12do
13echo "$i"
14done
15}
1617
18
test_expect_success setup '
1920
fill 1 2 3 4 5 6 7 8 >one &&
21fill a b c d e >two &&
22git add one two &&
23git commit -m "Initial A one, A two" &&
2425
git checkout -b renamer &&
26rm -f one &&
27fill 1 3 4 5 6 7 8 >uno &&
28git add uno &&
29fill a b c d e f >two &&
30git commit -a -m "Renamer R one->uno, M two" &&
3132
git checkout -b side master &&
33fill 1 2 3 4 5 6 7 >one &&
34fill A B C D E >three &&
35rm -f two &&
36git update-index --add --remove one two three &&
37git commit -m "Side M one, D two, A three" &&
3839
git checkout master
40'
4142
test_expect_success "checkout from non-existing branch" '
4344
git checkout -b delete-me master &&
45rm .git/refs/heads/delete-me &&
46test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
47git checkout master &&
48test refs/heads/master = "$(git symbolic-ref HEAD)"
49'
5051
test_expect_success "checkout with dirty tree without -m" '
5253
fill 0 1 2 3 4 5 6 7 8 >one &&
54if git checkout side
55then
56echo Not happy
57false
58else
59echo "happy - failed correctly"
60fi
6162
'
6364
test_expect_success "checkout -m with dirty tree" '
6566
git checkout -f master &&
67git clean &&
6869
fill 0 1 2 3 4 5 6 7 8 >one &&
70git checkout -m side &&
7172
test "$(git symbolic-ref HEAD)" = "refs/heads/side" &&
7374
fill "M one" "A three" "D two" >expect.master &&
75git diff --name-status master >current.master &&
76diff expect.master current.master &&
7778
fill "M one" >expect.side &&
79git diff --name-status side >current.side &&
80diff expect.side current.side &&
8182
: >expect.index &&
83git diff --cached >current.index &&
84diff expect.index current.index
85'
8687
test_expect_success "checkout -m with dirty tree, renamed" '
8889
git checkout -f master && git clean &&
9091
fill 1 2 3 4 5 7 8 >one &&
92if git checkout renamer
93then
94echo Not happy
95false
96else
97echo "happy - failed correctly"
98fi &&
99100
git checkout -m renamer &&
101fill 1 3 4 5 7 8 >expect &&
102diff expect uno &&
103! test -f one &&
104git diff --cached >current &&
105! test -s current
106107
'
108109
test_expect_success 'checkout -m with merge conflict' '
110111
git checkout -f master && git clean &&
112113
fill 1 T 3 4 5 6 S 8 >one &&
114if git checkout renamer
115then
116echo Not happy
117false
118else
119echo "happy - failed correctly"
120fi &&
121122
git checkout -m renamer &&
123124
git diff master:one :3:uno |
125sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current &&
126fill d2 aT d7 aS >expect &&
127diff current expect &&
128git diff --cached two >current &&
129! test -s current
130'
131132
test_done