Add support for merge-friendly branches
[stgit] / t / t4100-publish.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009 Catalin Marinas
4 #
5
6 test_description='Exercise the publish command.
7
8 Create/modify patches on the stack and publish them to a separate branch.'
9
10 . ./test-lib.sh
11
12 test_same_tree () {
13 stack_tree=$(git rev-parse master^{tree})
14 public_tree=$(git rev-parse master.public^{tree})
15 test "$stack_tree" = "$public_tree"
16 }
17
18 test_expect_success \
19 'Initialize the StGit repository' \
20 '
21 stg init
22 '
23
24 test_expect_success \
25 'Create some patches' \
26 '
27 stg new p1 -m p1 &&
28 echo foo1 > foo1.txt &&
29 git add foo1.txt &&
30 stg refresh &&
31 stg new p2 -m p2 &&
32 echo foo2 > foo2.txt &&
33 git add foo2.txt &&
34 stg refresh &&
35 stg new p3 -m p3 &&
36 echo foo3 > foo3.txt &&
37 git add foo3.txt &&
38 stg refresh
39 '
40
41 test_expect_success \
42 'Publish the stack for the first time' \
43 '
44 stg publish &&
45 test "$(stg id)" = "$(stg id master.public)"
46 '
47
48 test_expect_success \
49 'Modify a patch and publish the changes' \
50 '
51 stg pop &&
52 echo foo2 >> foo2.txt &&
53 stg refresh &&
54 stg push &&
55 old_public=$(stg id master.public) &&
56 stg publish -m "p2 updated" &&
57 test_same_tree &&
58 new_public=$(stg id master.public) &&
59 test "$(git rev-list $old_public..$new_public | wc -l)" = "1"
60 '
61
62 test_expect_success \
63 'Create new patches and publish them' \
64 '
65 stg new p4 -m p4 &&
66 echo foo4 > foo4.txt &&
67 git add foo4.txt &&
68 stg refresh &&
69 stg new p5 -m p5 &&
70 echo foo5 > foo5.txt &&
71 git add foo5.txt &&
72 stg refresh &&
73 stg new empty -m empty &&
74 old_public=$(stg id master.public) &&
75 stg publish -m "Ignored message" &&
76 test_same_tree &&
77 new_public=$(stg id master.public) &&
78 test "$(git rev-list $old_public..$new_public | wc -l)" = "2"
79 '
80
81 test_expect_success \
82 'Rebase the current stack and publish a merge' \
83 '
84 stg pop -a &&
85 echo foo0 > foo0.txt &&
86 git add foo0.txt &&
87 git commit -m "foo0.txt added" &&
88 stg push -a &&
89 old_public=$(stg id master.public) &&
90 stg publish -m "Merge with base" &&
91 test_same_tree &&
92 new_public=$(stg id master.public) &&
93 test "$(git rev-list $old_public..$new_public | wc -l)" = "2" &&
94 test "$(git merge-base master.public master)" = "$(stg id {base})"
95 '
96
97 test_expect_success \
98 'Re-publish without any changes' \
99 '
100 old_public=$(stg id master.public) &&
101 stg publish -m "Ignored message" &&
102 test_same_tree &&
103 new_public=$(stg id master.public) &&
104 test "$old_public" = "$new_public"
105 '
106
107 test_expect_success \
108 'Reorder patches and publish the changes' \
109 '
110 stg float p5 p4 p3 p2 p1 &&
111 old_public=$(stg id master.public) &&
112 stg publish -m "Ignored message" &&
113 test_same_tree &&
114 new_public=$(stg id master.public) &&
115 test "$old_public" = "$new_public"
116 '
117
118 test_expect_success \
119 'Pop a patch and publish the changes' \
120 '
121 stg pop p3 &&
122 old_public=$(stg id master.public) &&
123 stg publish -m "p3 removed" &&
124 test_same_tree &&
125 new_public=$(stg id master.public) &&
126 test "$(git rev-list $old_public..$new_public | wc -l)" = "1"
127 '
128
129 test_done