summaryrefslogtreecommitdiff
path: root/tests/tests/gdr-subcommands
blob: 9dc99fae9e49e6921cc2c65113515af7e1f22971 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
set -e
. tests/lib

t-dependencies git-buildpackage libfile-fnmatch-perl faketime

t-setup-import gdr-convert-gbp

cd $p

t-dgit setup-mergechangelogs

mix-it () {
	t-git-next-date
	local m=$(git symbolic-ref HEAD)
	t-some-changes "subcommands $m 1"
	t-dgit -wgf quilt-fixup
	t-some-changes "subcommands $m 2"
}

git checkout -b stitched-laundered master
mix-it
t-git-debrebase quick
t-gdr-good stitched HEAD

git checkout -b stitched-mixed master
mix-it

git checkout -b unstitched-laundered master
mix-it
t-git-debrebase
t-gdr-good laundered

git checkout -b unstitched-mixed master
t-git-debrebase
mix-it

t-git-next-date

git show-ref 

subcmd () {
	local subcmd=$1
	shift
	for startbranch in {stitched,unstitched}-{laundered,mixed}; do
		work="work-$subcmd-$startbranch"

		: "---------- $subcmd $startbranch ----------"

		git for-each-ref "**/$startbranch"{,/**} \
			--format='create %(refname) %(objectname)' \
		| sed "s/$startbranch/$work/" \
		| git update-ref --stdin

		git checkout $work
		checkletters=$1; shift

		before=before-$work
		git branch $before

		case "$checkletters" in
		XX*)
			fail "$checkletters" # for debugging
			;;
		N*)
			t-expect-fail E:. \
			t-git-debrebase $subcmd
			t-git-debrebase --noop-ok $subcmd
			;;
		[EF]:*)
			t-expect-fail "$checkletters" \
			t-git-debrebase $subcmd
			continue
			;;
		*)
			t-git-debrebase $subcmd
			;;
		esac

		peel=peel-$subcmd-$startbranch
		git checkout -b $peel
		t-clean-on-branch $peel

		: "---------- $subcmd $startbranch $checkletters ----------"

		while [ "x$checkletters" != x ]; do
			: "---- $subcmd $startbranch ...$checkletters ----"
			make_check "$checkletters"
			checkletters="${checkletters#?}"
		done
	done

}

next_checkletter () {
	checkletters="${checkletters#?}"
}

make_check () {
	case "$1" in
	[Nn]*)
		t-refs-same-start
		t-refs-same refs/heads/$before refs/heads/$work
		;;
	U*)
		t-refs-same-start
		t-refs-same refs/heads/$before refs/ffq-prev/heads/$work
		make_check u
		;;
	u*)
		t-git-get-ref refs/ffq-prev/heads/$work
		t-refs-notexist refs/debrebase-last/heads/$work
		;;
	V*)
		t-refs-same-start
		t-refs-same refs/ffq-prev/heads/$work \
			refs/ffq-prev/heads/$startbranch
		t-refs-notexist refs/debrebase-last/heads/$work
		;;
	s*)
		t-refs-notexist refs/ffq-prev/heads/$work
		t-refs-same-start
		t-refs-same refs/debrebase-last/heads/$work \
			refs/debrebase-last/heads/$startbranch
		t-has-ancestor HEAD refs/debrebase-last/heads/$work
		;;
	S*)
		t-refs-notexist refs/ffq-prev/heads/$work
		t-refs-same-start refs/debrebase-last/heads/$work
		t-ref-head
		git diff --quiet HEAD^1
		git diff HEAD^2 | grep $startbranch
		git reset --hard HEAD^1
		;;
	P*)
		t-dgit -wgf --quilt=check quilt-fixup
		git diff HEAD~ debian/patches | egrep .
		git diff --quiet HEAD~ -- ':.' ':!debian/patches'
		git reset --hard HEAD~
		;;
	l*)
		git diff --quiet HEAD refs/heads/$before -- ':.' ':!debian/patches'
		t-gdr-good laundered
		;;
	t*)
		git diff --quiet HEAD refs/heads/$before
		;;
	f*)
		t-has-ancestor HEAD refs/heads/$before
		;;
	*)
		fail "$1"
		;;
	esac
}

Ec="F:No ongoing git-debrebase session"

# input state:
#  stitched?		st'd	st'd	unst'd	unst'd
#  laundered?		laund'd	mixed	laund'd	mixed
#
# "mixed" means an out of order branch
# containing mixed commits and patch additions,
# but which needs even more patches
#
subcmd	''		Ult	Ull	Vlt	Vl
subcmd	stitch		Ns	Nu	Sltf	Stf
subcmd	prepush		Ns	Nu	Sltf	Stf
subcmd	quick		ns	Sl	Sltf	Sl
subcmd	conclude	"$Ec"	"$Ec"	Sltf	Sl
#subcmd	make-patches	sPft	sPft	uPft	uPft
#subcmd	dgit-upload-hook Psft	Psft	SPft	SPft
#
# result codes, each one is a check:
#   E:$pat	} this is an error (must come first)
#   F:$pat	} arg is passed to expect-fail
#
#   N		this is a noop, error unless --noop-ok
#   n		this is a silent noop
# both of these imply tf; but, specify also one of   u s
#
# should normally specify one of these:
#   U		just unstiched: ffq-prev is exactly previous HEAD; implies u
#   u		result is unstitched
#   V		ffq-prev remains unchanged; implies also u
#   s		result is stitched, debrebase-last exists and is unchanged
#   S		result is stitch just made, remaining letters apply to result~
#
#   P		result is add-patches, remaining letters apply to result~
#
# should normally specify one or both of these:
#   l		result is laundered, tree is same as before minus d/patches
#   t		tree is exactly same as before
#
#   f		result is ff from previous HEAD

t-ok