@matheusbsbs / matheus-bagliano / commits / d7eed8cbef
Fork 0

t7111: check that reset options work as described in the tables

Some previous patches added some tables to the "git reset" documentation. These tables describe the behavior of "git reset" depending on the option it is passed and the state of the files in the working tree, the index, HEAD and the target commit. This patch adds some tests to make sure that the tables describe the behavior of "git reset". Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jan 8, 2010 at 05:45 UTC d7eed8cbef2d15e87e9002f5e3ce08830b40b292
1 file changed +113
t/t7111-reset-table.sh new
+113
@@ -0,0 +1,113 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Christian Couder
4 +#
5 +
6 +test_description='Tests to check that "reset" options follow a known table'
7 +
8 +. ./test-lib.sh
9 +
10 +
11 +test_expect_success 'creating initial commits' '
12 + test_commit E file1 &&
13 + test_commit D file1 &&
14 + test_commit C file1
15 +'
16 +
17 +while read W1 I1 H1 T opt W2 I2 H2
18 +do
19 + test_expect_success "check: $W1 $I1 $H1 $T --$opt $W2 $I2 $H2" '
20 + git reset --hard C &&
21 + if test "$I1" != "$H1"
22 + then
23 + echo "$I1" >file1 &&
24 + git add file1
25 + fi &&
26 + if test "$W1" != "$I1"
27 + then
28 + echo "$W1" >file1
29 + fi &&
30 + if test "$W2" != "XXXXX"
31 + then
32 + git reset --$opt $T &&
33 + test "$(cat file1)" = "$W2" &&
34 + git checkout-index -f -- file1 &&
35 + test "$(cat file1)" = "$I2" &&
36 + git checkout -f HEAD -- file1 &&
37 + test "$(cat file1)" = "$H2"
38 + else
39 + test_must_fail git reset --$opt $T
40 + fi
41 + '
42 +done <<\EOF
43 +A B C D soft A B D
44 +A B C D mixed A D D
45 +A B C D hard D D D
46 +A B C D merge XXXXX
47 +A B C C soft A B C
48 +A B C C mixed A C C
49 +A B C C hard C C C
50 +A B C C merge XXXXX
51 +B B C D soft B B D
52 +B B C D mixed B D D
53 +B B C D hard D D D
54 +B B C D merge D D D
55 +B B C C soft B B C
56 +B B C C mixed B C C
57 +B B C C hard C C C
58 +B B C C merge C C C
59 +B C C D soft B C D
60 +B C C D mixed B D D
61 +B C C D hard D D D
62 +B C C D merge XXXXX
63 +B C C C soft B C C
64 +B C C C mixed B C C
65 +B C C C hard C C C
66 +B C C C merge B C C
67 +EOF
68 +
69 +test_expect_success 'setting up branches to test with unmerged entries' '
70 + git reset --hard C &&
71 + git branch branch1 &&
72 + git branch branch2 &&
73 + git checkout branch1 &&
74 + test_commit B1 file1 &&
75 + git checkout branch2 &&
76 + test_commit B2 file1
77 +'
78 +
79 +while read W1 I1 H1 T opt W2 I2 H2
80 +do
81 + test_expect_success "check: $W1 $I1 $H1 $T --$opt $W2 $I2 $H2" '
82 + git reset --hard B2 &&
83 + test_must_fail git merge branch1 &&
84 + cat file1 >X_file1 &&
85 + if test "$W2" != "XXXXX"
86 + then
87 + git reset --$opt $T &&
88 + if test "$W2" = "X"
89 + then
90 + test_cmp file1 X_file1
91 + else
92 + test "$(cat file1)" = "$W2"
93 + fi &&
94 + git checkout-index -f -- file1 &&
95 + test "$(cat file1)" = "$I2" &&
96 + git checkout -f HEAD -- file1 &&
97 + test "$(cat file1)" = "$H2"
98 + else
99 + test_must_fail git reset --$opt $T
100 + fi
101 + '
102 +done <<\EOF
103 +X U C D soft XXXXX
104 +X U C D mixed X D D
105 +X U C D hard D D D
106 +X U C D merge D D D
107 +X U C C soft XXXXX
108 +X U C C mixed X C C
109 +X U C C hard C C C
110 +X U C C merge C C C
111 +EOF
112 +
113 +test_done