Merge branch 'master' into lj/refs
[git/git.git] / t / t7201-co.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
5
6 test_description='git-checkout tests.'
7
8 . ./test-lib.sh
9
10 fill () {
11 for i
12 do
13 echo "$i"
14 done
15 }
16
17 test_expect_success setup '
18
19 fill 1 2 3 4 5 >one &&
20 fill a b c d e >two &&
21 git add one two &&
22 git commit -m "Initial A one, A two" &&
23
24 git checkout -b side &&
25 fill 1 2 3 >one &&
26 fill A B C D E >three &&
27 rm -f two &&
28 git update-index --add --remove one two three &&
29 git commit -m "Side M one, D two, A three" &&
30
31 git checkout master
32 '
33
34 test_expect_success "checkout from non-existing branch" '
35
36 git checkout -b delete-me master &&
37 rm .git/refs/heads/delete-me &&
38 test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
39 git checkout master &&
40 test refs/heads/master = "$(git symbolic-ref HEAD)"
41 '
42
43 test_expect_success "checkout with dirty tree without -m" '
44
45 fill 0 1 2 3 4 5 >one &&
46 if git checkout side
47 then
48 echo Not happy
49 false
50 else
51 echo "happy - failed correctly"
52 fi
53
54 '
55
56 test_expect_success "checkout -m with dirty tree" '
57
58 git checkout -f master &&
59 git clean &&
60
61 fill 0 1 2 3 4 5 >one &&
62 git checkout -m side &&
63
64 fill " master" "* side" >expect.branch &&
65 git branch >current.branch &&
66 diff expect.branch current.branch &&
67
68 fill "M one" "A three" "D two" >expect.master &&
69 git diff --name-status master >current.master &&
70 diff expect.master current.master &&
71
72 fill "M one" >expect.side &&
73 git diff --name-status side >current.side &&
74 diff expect.side current.side &&
75
76 : >expect.index &&
77 git diff --cached >current.index &&
78 diff expect.index current.index
79 '
80
81 test_done