Fix deletion and move of a hidden patch (gna bug #9244).
[stgit] / t / t1600-delete-one.sh
CommitLineData
87bcf96e
KH
1#!/bin/sh
2# Copyright (c) 2006 Karl Hasselström
3test_description='Test the delete command (deleting one patch at a time).'
4. ./test-lib.sh
5
6test_expect_success \
7 'Initialize the StGIT repository' \
8 'stg init'
9
10test_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
19test_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
27test_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
37test_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
45test_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
55test_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
63test_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
76test_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
84test_expect_success \
dfb3bdde
YD
85 'Hide the topmost patch and try to delete it' \
86 '
87 [ $(stg applied | wc -l) -eq 2 ] &&
88 stg hide bar &&
89 stg delete bar &&
90 [ $(stg applied | wc -l) -eq 1 ]
91 '
92
93test_expect_success \
87bcf96e
KH
94 'Create another branch, and put one patch in each branch' \
95 '
96 stg branch --create br &&
97 stg new baz -m baz &&
98 echo baz > baz.txt &&
99 stg add baz.txt &&
100 stg refresh &&
101 stg branch master &&
102 stg new baz -m baz &&
103 echo baz > baz.txt &&
104 stg add baz.txt &&
105 stg refresh
106 '
107
108test_expect_success \
109 'Delete a patch in another branch' \
110 '
dfb3bdde 111 [ $(stg applied | wc -l) -eq 2 ] &&
87bcf96e
KH
112 [ $(stg applied -b br | wc -l) -eq 1 ] &&
113 stg delete -b br baz &&
dfb3bdde 114 [ $(stg applied | wc -l) -eq 2 ] &&
87bcf96e
KH
115 [ $(stg applied -b br | wc -l) -eq 0 ]
116 '
117
118test_done