Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_cherrypick_basic {
20 local testroot=`test_init cherrypick_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 (cd $testroot/repo && git checkout -q -b newbranch)
30 echo "modified delta on branch" > $testroot/repo/gamma/delta
31 git_commit $testroot/repo -m "committing to delta on newbranch"
33 echo "modified alpha on branch" > $testroot/repo/alpha
34 (cd $testroot/repo && git rm -q beta)
35 echo "new file on branch" > $testroot/repo/epsilon/new
36 (cd $testroot/repo && git add epsilon/new)
37 git_commit $testroot/repo -m "committing more changes on newbranch"
39 local branch_rev=`git_show_head $testroot/repo`
41 (cd $testroot/wt && got cherrypick $branch_rev > $testroot/stdout)
43 echo "G alpha" > $testroot/stdout.expected
44 echo "D beta" >> $testroot/stdout.expected
45 echo "A epsilon/new" >> $testroot/stdout.expected
46 echo "Merged commit $branch_rev" >> $testroot/stdout.expected
48 cmp -s $testroot/stdout.expected $testroot/stdout
49 ret="$?"
50 if [ "$ret" != "0" ]; then
51 diff -u $testroot/stdout.expected $testroot/stdout
52 test_done "$testroot" "$ret"
53 return 1
54 fi
56 echo "modified alpha on branch" > $testroot/content.expected
57 cat $testroot/wt/alpha > $testroot/content
58 cmp -s $testroot/content.expected $testroot/content
59 ret="$?"
60 if [ "$ret" != "0" ]; then
61 diff -u $testroot/content.expected $testroot/content
62 test_done "$testroot" "$ret"
63 return 1
64 fi
66 if [ -e $testroot/wt/beta ]; then
67 echo "removed file beta still exists on disk" >&2
68 test_done "$testroot" "1"
69 return 1
70 fi
72 echo "new file on branch" > $testroot/content.expected
73 cat $testroot/wt/epsilon/new > $testroot/content
74 cmp -s $testroot/content.expected $testroot/content
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/content.expected $testroot/content
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 echo 'M alpha' > $testroot/stdout.expected
83 echo 'D beta' >> $testroot/stdout.expected
84 echo 'A epsilon/new' >> $testroot/stdout.expected
86 (cd $testroot/wt && got status > $testroot/stdout)
88 cmp -s $testroot/stdout.expected $testroot/stdout
89 ret="$?"
90 if [ "$ret" != "0" ]; then
91 diff -u $testroot/stdout.expected $testroot/stdout
92 fi
93 test_done "$testroot" "$ret"
94 }
96 function test_cherrypick_root_commit {
97 local testroot=`test_init cherrypick_root_commit`
99 got checkout $testroot/repo $testroot/wt > /dev/null
100 ret="$?"
101 if [ "$ret" != "0" ]; then
102 test_done "$testroot" "$ret"
103 return 1
104 fi
106 (cd $testroot/repo && git checkout -q -b newbranch)
107 (cd $testroot/repo && git rm -q alpha)
108 (cd $testroot/repo && git rm -q beta)
109 (cd $testroot/repo && git rm -q epsilon/zeta)
110 (cd $testroot/repo && git rm -q gamma/delta)
111 mkdir -p $testroot/repo/epsilon
112 echo "new file on branch" > $testroot/repo/epsilon/new
113 (cd $testroot/repo && git add epsilon/new)
114 git_commit $testroot/repo -m "committing on newbranch"
116 echo "modified new file on branch" >> $testroot/repo/epsilon/new
117 git_commit $testroot/repo -m "committing on newbranch again"
119 tree=`git_show_tree $testroot/repo`
120 root_commit=`git_commit_tree $testroot/repo "new root commit" $tree`
122 (cd $testroot/wt && got cherrypick $root_commit > $testroot/stdout)
124 echo "A epsilon/new" > $testroot/stdout.expected
125 echo "Merged commit $root_commit" >> $testroot/stdout.expected
127 cmp -s $testroot/stdout.expected $testroot/stdout
128 ret="$?"
129 if [ "$ret" != "0" ]; then
130 diff -u $testroot/stdout.expected $testroot/stdout
131 test_done "$testroot" "$ret"
132 return 1
133 fi
135 echo "new file on branch" > $testroot/content.expected
136 echo "modified new file on branch" >> $testroot/content.expected
137 cat $testroot/wt/epsilon/new > $testroot/content
138 cmp -s $testroot/content.expected $testroot/content
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 diff -u $testroot/content.expected $testroot/content
142 test_done "$testroot" "$ret"
143 return 1
144 fi
146 echo 'A epsilon/new' > $testroot/stdout.expected
148 (cd $testroot/wt && got status > $testroot/stdout)
150 cmp -s $testroot/stdout.expected $testroot/stdout
151 ret="$?"
152 if [ "$ret" != "0" ]; then
153 diff -u $testroot/stdout.expected $testroot/stdout
154 fi
155 test_done "$testroot" "$ret"
158 run_test test_cherrypick_basic
159 run_test test_cherrypick_root_commit