| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Simple test cases for "stg reset"' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | # Ignore our own output files. |
| 8 | cat > .git/info/exclude <<EOF |
| 9 | /expected.txt |
| 10 | EOF |
| 11 | |
| 12 | test_expect_success 'Initialize StGit stack with three patches' ' |
| 13 | stg init && |
| 14 | echo 000 >> a && |
| 15 | git add a && |
| 16 | git commit -m a && |
| 17 | echo 111 >> a && |
| 18 | git commit -a -m p1 && |
| 19 | echo 222 >> a && |
| 20 | git commit -a -m p2 && |
| 21 | echo 333 >> a && |
| 22 | git commit -a -m p3 && |
| 23 | stg uncommit -n 3 && |
| 24 | stg pop |
| 25 | ' |
| 26 | |
| 27 | cat > expected.txt <<EOF |
| 28 | 000 |
| 29 | 111 |
| 30 | EOF |
| 31 | test_expect_success 'Pop one patch ...' ' |
| 32 | stg pop && |
| 33 | test "$(echo $(stg series --all))" = "> p1 - p2 - p3" && |
| 34 | test_cmp expected.txt a |
| 35 | ' |
| 36 | |
| 37 | cat > expected.txt <<EOF |
| 38 | 000 |
| 39 | 111 |
| 40 | 222 |
| 41 | EOF |
| 42 | test_expect_success '... and undo it' ' |
| 43 | stg reset master.stgit^~1 && |
| 44 | test "$(echo $(stg series --all))" = "+ p1 > p2 - p3" && |
| 45 | test_cmp expected.txt a |
| 46 | ' |
| 47 | |
| 48 | cat > expected.txt <<EOF |
| 49 | 000 |
| 50 | 111 |
| 51 | 222 |
| 52 | 333 |
| 53 | EOF |
| 54 | test_expect_success 'Push one patch ...' ' |
| 55 | stg push && |
| 56 | test "$(echo $(stg series --all))" = "+ p1 + p2 > p3" && |
| 57 | test_cmp expected.txt a |
| 58 | ' |
| 59 | |
| 60 | cat > expected.txt <<EOF |
| 61 | 000 |
| 62 | 111 |
| 63 | 222 |
| 64 | EOF |
| 65 | test_expect_success '... and undo it' ' |
| 66 | stg reset master.stgit^~1 && |
| 67 | test "$(echo $(stg series --all))" = "+ p1 > p2 - p3" && |
| 68 | test_cmp expected.txt a |
| 69 | ' |
| 70 | |
| 71 | test_expect_success 'Commit one patch ...' ' |
| 72 | stg commit && |
| 73 | test "$(echo $(stg series --all))" = "> p2 - p3" |
| 74 | ' |
| 75 | |
| 76 | test_expect_success '... and undo it' ' |
| 77 | stg reset master.stgit^~1 && |
| 78 | test "$(echo $(stg series --all))" = "+ p1 > p2 - p3" |
| 79 | ' |
| 80 | |
| 81 | test_expect_success 'Hide a patch ...' ' |
| 82 | stg hide p3 && |
| 83 | test "$(echo $(stg series --all))" = "+ p1 > p2 ! p3" |
| 84 | ' |
| 85 | |
| 86 | test_expect_success '... undo the hiding ...' ' |
| 87 | stg reset master.stgit^~1 && |
| 88 | test "$(echo $(stg series --all))" = "+ p1 > p2 - p3" |
| 89 | ' |
| 90 | |
| 91 | test_expect_success '... unhide the patch ...' ' |
| 92 | stg hide p3 && stg unhide p3 && |
| 93 | test "$(echo $(stg series --all))" = "+ p1 > p2 - p3" |
| 94 | ' |
| 95 | |
| 96 | test_expect_success '... and undo the unhiding' ' |
| 97 | stg reset master.stgit^~1 && |
| 98 | test "$(echo $(stg series --all))" = "+ p1 > p2 ! p3" && |
| 99 | stg unhide p3 |
| 100 | ' |
| 101 | |
| 102 | cat > expected.txt <<EOF |
| 103 | 000 |
| 104 | 111 |
| 105 | EOF |
| 106 | test_expect_success 'Delete two patches ...' ' |
| 107 | stg delete p2 p3 && |
| 108 | test "$(echo $(stg series --all))" = "> p1" && |
| 109 | test_cmp expected.txt a |
| 110 | ' |
| 111 | |
| 112 | test_expect_success '... and undo one of the deletions ...' ' |
| 113 | stg reset master.stgit^~1 p3 && |
| 114 | test "$(echo $(stg series --all))" = "> p1 - p3" && |
| 115 | test_cmp expected.txt a |
| 116 | ' |
| 117 | |
| 118 | test_expect_success '... then undo the first undo ...' ' |
| 119 | stg reset master.stgit^~1 && |
| 120 | test "$(echo $(stg series --all))" = "> p1" && |
| 121 | test_cmp expected.txt a |
| 122 | ' |
| 123 | |
| 124 | cat > expected.txt <<EOF |
| 125 | 000 |
| 126 | 111 |
| 127 | 222 |
| 128 | EOF |
| 129 | test_expect_success '... and undo the other deletion' ' |
| 130 | stg reset master.stgit^~3 p2 && |
| 131 | stg push p2 && |
| 132 | test "$(echo $(stg series --all))" = "+ p1 > p2" && |
| 133 | test_cmp expected.txt a |
| 134 | ' |
| 135 | |
| 136 | cat > expected.txt <<EOF |
| 137 | 000 |
| 138 | 111 |
| 139 | 222 |
| 140 | ggg |
| 141 | EOF |
| 142 | test_expect_success 'Refresh a patch ...' ' |
| 143 | echo ggg >> a && |
| 144 | stg refresh && |
| 145 | test "$(echo $(stg series --all))" = "+ p1 > p2" && |
| 146 | test_cmp expected.txt a |
| 147 | ' |
| 148 | |
| 149 | cat > expected.txt <<EOF |
| 150 | 000 |
| 151 | 111 |
| 152 | 222 |
| 153 | EOF |
| 154 | test_expect_success '... and undo the refresh' ' |
| 155 | stg reset master.stgit^~2 && |
| 156 | test "$(echo $(stg series --all))" = "+ p1 > p2" && |
| 157 | test_cmp expected.txt a |
| 158 | ' |
| 159 | |
| 160 | test_done |