Test commit
[cogito/jonas.git] / t / t9300-seek.sh
blob95ae9169cfa78d6534ba748e5491eae36841feb3
1 #!/usr/bin/env bash
3 # Copyright (c) 2005 Petr Baudis
5 test_description="Tests basic cg-seek functionality
7 Generate two commits, and test if the seek works properly. That includes the
8 basic tree changes, keeping of local changes, and removing of directories that
9 should be gone."
11 . ./test-lib.sh
13 echo "identical" >identical
14 echo "v1" >different
16 test_expect_success 'initialize repo' \
17 "(cg-add identical different && cg-commit -C -m\"Initial commit\")"
18 commit1=$(cg-object-id -c)
20 echo "v2" >different
21 cg-add different # FIXME: race
22 mkdir newdir
23 echo "v2" >newdir/newfile
24 test_expect_success 'record second commit' \
25 "(cg-add newdir/newfile && cg-commit -m\"Second commit\")"
26 commit2=$(cg-object-id -c)
28 test_expect_success 'seeking to the first commit' \
29 "cg-seek $commit1"
30 test_expect_success 'we should have .git/head-name == master' \
31 "[ $(cat .git/head-name) = master ]"
32 test_expect_success 'current branch should be cg-seek-point' \
33 "[ $(basename $(git-symbolic-ref HEAD)) = cg-seek-point ]"
34 test_expect_success 'current commit should be commit1' \
35 "[ $(cg-object-id -c) = $commit1 ]"
37 test_expect_success 'newfile should be gone' \
38 "[ ! -e newdir/newfile ]"
39 test_expect_success 'newdir should be gone' \
40 "[ ! -e newdir ]"
41 test_expect_success 'different should be v1' \
42 "[ $(cat different) = v1 ]"
43 test_expect_success 'identical should be identical' \
44 "[ $(cat identical) = identical ]"
46 test_expect_success 'seeking to the second commit' \
47 "cg-seek $commit2"
48 test_expect_success 'we should not unseeked properly' \
49 "([ -e .git/head-name ] &&
50 [ $(basename $(git-symbolic-ref HEAD)) = cg-seek-point ])"
51 test_expect_success 'current commit should be commit2' \
52 "[ $(cg-object-id -c) = $commit2 ]"
54 test_expect_success 'seeking to the last (well, still second) commit' \
55 "cg-seek master"
56 test_expect_success 'we should be unseeked properly' \
57 "([ ! -e .git/head-name ] &&
58 [ $(basename $(git-symbolic-ref HEAD)) = master ])"
59 test_expect_success 'current commit should be commit2' \
60 "[ $(cg-object-id -c) = $commit2 ]"
62 test_expect_success 'newdir/newfile should be back' \
63 "[ $(cat newdir/newfile) = v2 ]"
64 test_expect_success 'different should be v2' \
65 "[ $(cat different) = v2 ]"
66 test_expect_success 'identical should be identical' \
67 "[ $(cat identical) = identical ]"
69 test_expect_success 'local change to identical (non-conflicting)' \
70 "echo nonconflicting >identical"
71 test_expect_success 'local change to newdir/newfile (conflicting)' \
72 "echo conflicting >newdir/newfile"
74 test_expect_success 'seeking to the first commit' \
75 "cg-seek $commit1"
76 test_expect_success 'current commit should be commit1' \
77 "[ $(cg-object-id -c) = $commit1 ]"
79 test_expect_success 'newdir should not be gone' \
80 "[ -d newdir ]"
81 test_expect_success 'newfile should be almost-gone' \
82 "[ ! -e newdir/newfile ] && [ -e newdir/newfile~original ] && [ -e newdir/newfile~local ]"
83 test_expect_success 'different should be v1' \
84 "[ $(cat different) = v1 ]"
85 test_expect_success 'identical should be nonconflicting' \
86 "[ $(cat identical) = nonconflicting ]"
88 test_expect_success 'unseeking' \
89 "cg-seek"
90 test_expect_success 'we should be unseeked properly' \
91 "([ ! -e .git/head-name ] &&
92 [ $(basename $(git-symbolic-ref HEAD)) = master ])"
93 test_expect_success 'current commit should be commit2' \
94 "[ $(cg-object-id -c) = $commit2 ]"
97 test_done