| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Simple test cases for "stg undo"' |
| 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))" = "> 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 undo && |
| 44 | test "$(echo $(stg series))" = "+ p1 > p2 - p3" && |
| 45 | test_cmp expected.txt a |
| 46 | ' |
| 47 | |
| 48 | cat > expected.txt <<EOF |
| 49 | 000 |
| 50 | EOF |
| 51 | test_expect_success 'Pop two patches ...' ' |
| 52 | stg pop && |
| 53 | stg pop && |
| 54 | test "$(echo $(stg series))" = "- p1 - p2 - p3" && |
| 55 | test_cmp expected.txt a |
| 56 | ' |
| 57 | |
| 58 | cat > expected.txt <<EOF |
| 59 | 000 |
| 60 | 111 |
| 61 | 222 |
| 62 | EOF |
| 63 | test_expect_success '... and undo it' ' |
| 64 | stg undo && |
| 65 | stg undo && |
| 66 | test "$(echo $(stg series))" = "+ p1 > p2 - p3" && |
| 67 | test_cmp expected.txt a |
| 68 | ' |
| 69 | |
| 70 | cat > expected.txt <<EOF |
| 71 | 000 |
| 72 | 111 |
| 73 | 222 |
| 74 | EOF |
| 75 | test_expect_success 'Undo past end of history' ' |
| 76 | command_error stg undo -n 100 && |
| 77 | test "$(echo $(stg series))" = "+ p1 > p2 - p3" && |
| 78 | test_cmp expected.txt a |
| 79 | ' |
| 80 | |
| 81 | test_done |