chiark / gitweb /
stgit.el: Add "d" for a few diff commands, similar to git.el
[stgit] / t / t1600-delete-one.sh
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     git add foo.txt &&
16     stg refresh
17     '
18
19 test_expect_success \
20     'Try to delete a non-existing patch' \
21     '
22     [ $(stg series --applied -c) -eq 1 ] &&
23     command_error stg delete bar &&
24     [ $(stg series --applied -c) -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 series --applied -c) -eq 1 ] &&
32     command_error stg delete foo &&
33     [ $(stg series --applied -c) -eq 1 ] &&
34     git reset --hard
35     '
36
37 test_expect_success \
38     'Delete the topmost patch' \
39     '
40     [ $(stg series --applied -c) -eq 1 ] &&
41     stg delete foo &&
42     [ $(stg series --applied -c) -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     git add foo.txt &&
51     stg refresh &&
52     stg pop
53     '
54
55 test_expect_success \
56     'Delete an unapplied patch' \
57     '
58     [ $(stg series --unapplied -c) -eq 1 ] &&
59     stg delete foo &&
60     [ $(stg series --unapplied -c) -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     git add foo.txt &&
69     stg refresh &&
70     stg new bar -m bar &&
71     echo bar > bar.txt &&
72     git add bar.txt &&
73     stg refresh
74     '
75
76 test_expect_success \
77     'Try to delete a non-topmost applied patch' \
78     '
79     [ $(stg series --applied -c) -eq 2 ] &&
80     stg delete foo &&
81     [ $(stg series --applied -c) -eq 1 ]
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     git add baz.txt &&
91     stg refresh &&
92     stg branch master &&
93     stg new baz -m baz &&
94     echo baz > baz.txt &&
95     git add baz.txt &&
96     stg refresh
97     '
98
99 test_expect_success \
100     'Delete a patch in another branch' \
101     '
102     [ $(stg series --applied -c) -eq 2 ] &&
103     [ $(stg series --applied -b br -c) -eq 1 ] &&
104     stg delete -b br baz &&
105     [ $(stg series --applied -c) -eq 2 ] &&
106     [ $(stg series --applied -b br -c) -eq 0 ]
107     '
108
109 test_done