| 1 | #!/bin/sh |
| 2 | # Copyright (c) 2006 Karl Hasselström |
| 3 | test_description='Test the delete command (deleting one patch at a time).' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | test_expect_success \ |
| 7 | 'Initialize the StGIT repository' \ |
| 8 | 'stg init' |
| 9 | |
| 10 | test_expect_success \ |
| 11 | 'Create a patch' \ |
| 12 | ' |
| 13 | stg new foo -m foo && |
| 14 | echo foo > foo.txt && |
| 15 | stg add foo.txt && |
| 16 | stg refresh |
| 17 | ' |
| 18 | |
| 19 | test_expect_success \ |
| 20 | 'Try to delete a non-existing patch' \ |
| 21 | ' |
| 22 | [ $(stg applied | wc -l) -eq 1 ] && |
| 23 | ! stg delete bar && |
| 24 | [ $(stg applied | wc -l) -eq 1 ] |
| 25 | ' |
| 26 | |
| 27 | test_expect_success \ |
| 28 | 'Try to delete the topmost patch while dirty' \ |
| 29 | ' |
| 30 | echo dirty >> foo.txt && |
| 31 | [ $(stg applied | wc -l) -eq 1 ] && |
| 32 | ! stg delete foo && |
| 33 | [ $(stg applied | wc -l) -eq 1 ] && |
| 34 | git reset --hard |
| 35 | ' |
| 36 | |
| 37 | test_expect_success \ |
| 38 | 'Delete the topmost patch' \ |
| 39 | ' |
| 40 | [ $(stg applied | wc -l) -eq 1 ] && |
| 41 | stg delete foo && |
| 42 | [ $(stg applied | wc -l) -eq 0 ] |
| 43 | ' |
| 44 | |
| 45 | test_expect_success \ |
| 46 | 'Create an unapplied patch' \ |
| 47 | ' |
| 48 | stg new foo -m foo && |
| 49 | echo foo > foo.txt && |
| 50 | stg add foo.txt && |
| 51 | stg refresh && |
| 52 | stg pop |
| 53 | ' |
| 54 | |
| 55 | test_expect_success \ |
| 56 | 'Delete an unapplied patch' \ |
| 57 | ' |
| 58 | [ $(stg unapplied | wc -l) -eq 1 ] && |
| 59 | stg delete foo && |
| 60 | [ $(stg unapplied | wc -l) -eq 0 ] |
| 61 | ' |
| 62 | |
| 63 | test_expect_success \ |
| 64 | 'Create two patches' \ |
| 65 | ' |
| 66 | stg new foo -m foo && |
| 67 | echo foo > foo.txt && |
| 68 | stg add foo.txt && |
| 69 | stg refresh && |
| 70 | stg new bar -m bar && |
| 71 | echo bar > bar.txt && |
| 72 | stg add bar.txt && |
| 73 | stg refresh |
| 74 | ' |
| 75 | |
| 76 | test_expect_success \ |
| 77 | 'Try to delete a non-topmost applied patch' \ |
| 78 | ' |
| 79 | [ $(stg applied | wc -l) -eq 2 ] && |
| 80 | ! stg delete foo && |
| 81 | [ $(stg applied | wc -l) -eq 2 ] |
| 82 | ' |
| 83 | |
| 84 | test_expect_success \ |
| 85 | 'Create another branch, and put one patch in each branch' \ |
| 86 | ' |
| 87 | stg branch --create br && |
| 88 | stg new baz -m baz && |
| 89 | echo baz > baz.txt && |
| 90 | stg add baz.txt && |
| 91 | stg refresh && |
| 92 | stg branch master && |
| 93 | stg new baz -m baz && |
| 94 | echo baz > baz.txt && |
| 95 | stg add baz.txt && |
| 96 | stg refresh |
| 97 | ' |
| 98 | |
| 99 | test_expect_success \ |
| 100 | 'Delete a patch in another branch' \ |
| 101 | ' |
| 102 | [ $(stg applied | wc -l) -eq 3 ] && |
| 103 | [ $(stg applied -b br | wc -l) -eq 1 ] && |
| 104 | stg delete -b br baz && |
| 105 | [ $(stg applied | wc -l) -eq 3 ] && |
| 106 | [ $(stg applied -b br | wc -l) -eq 0 ] |
| 107 | ' |
| 108 | |
| 109 | test_done |