summaryrefslogtreecommitdiffstats
path: root/bin/git-debian-changelog
blob: 2197979ae2cf0685489cdb3a678989dc09e9988e (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
#!/bin/sh

set -e

if [ ! -x "$(which gbp 2> /dev/null)" ]
then
	echo "gbp - command not found" >&2
	exit 1
fi

if [ ! -e debian/changelog ]
then
	echo "E: debian/changelog - no such file" >&2
	exit 1
fi

MODE="$(basename ${0} | sed -e 's|^git-||' -e 's|-changelog$||')"

WRAP_SCRIPT="/usr/share/doc/git-buildpackage/examples/wrap_cl.py"

if [ -e "/usr/share/doc/git-buildpackage/examples/wrap_cl.py" ]
then
	CUSTOMIZATION="--customization ${WRAP_SCRIPT}"
fi

ID="${1}"

if [ -z "${ID}" ]
then
	if [ -n "$(git log | grep -m1 'Adding version ')" ]
	then
		ID="$(git log | grep -B4 -m1 "Adding version " | awk '/^commit / { print $2 }')"
	fi

	if [ -z "${ID}" ] && [ -n "$(git log | grep -m1 'Releasing version ')" ]
	then
		ID="$(git log | grep -B4 -m1 "Releasing version " | awk '/^commit / { print $2 }')"
	fi

	if [ -z "${ID}" ] && [ -n "$(git log | grep -m1 "Releasing ${MODE} version ")" ]
	then
		ID="$(git log | grep -B4 -m1 "Releasing ${MODE} version " | awk '/^commit / { print $2 }')"
	fi

	if [ -z "${ID}" ] && [ -n "$(git log | grep -m1 "Adding ${MODE} version ")" ]
	then
		ID="$(git log | grep -B4 -m1 "Adding ${MODE} version " | awk '/^commit / { print $2 }')"
	fi
else
	shift
fi

if [ -e debian/gbp.conf ]
then
	TEMPFILE="$(mktemp -p . -u)"
	mv debian/gbp.conf "${TEMPFILE}"
fi

SOURCE="$(dpkg-parsechangelog -S Source)"
URGENCY="$(dpkg-parsechangelog -S Urgency)"

if grep -qs "git.*.progress-linux.org" .git/config && grep -qs maintainers@lists.progress-linux.org debian/control
then
	DIST="$(git config --get remote.origin.url | awk -F/ '{ print $(NF-1) }')"
	DISTRIBUTION="--distribution=${DIST}"

	VERSION="$(dpkg-parsechangelog -S Version)"

	case "${VERSION}" in
		*progress*)
			VERSION=""
			;;

		*)
			case "${DIST}" in
				engywuck)
					case "${VERSION}" in
						*-*)
							# non-native
							VERSION="--dch-opt=-b -N ${VERSION}progress5u1"
							;;

						*)
							# native
							VERSION="--dch-opt=-b -N ${VERSION}-0progress5u1"
							;;
					esac
					;;

				engywuck-backports)
					case "${VERSION}" in
						*-*)
							# non-native
							VERSION="--dch-opt=-b -N ${VERSION}~progress5+u1"
							;;

						*)
							# native
							VERSION="--dch-opt=-b -N ${VERSION}-0.0~progress5+u1"
							;;
					esac
					;;

				fuchur)
					case "${VERSION}" in
						*-*)
							# non-native
							VERSION="--dch-opt=-b -N ${VERSION}progress6u1"
							;;

						*)
							# native
							VERSION="--dch-opt=-b -N ${VERSION}-0progress6u1"
							;;
					esac
					;;

				fuchur-backports)
					case "${VERSION}" in
						*-*)
							# non-native
							VERSION="--dch-opt=-b -N ${VERSION}~progress6+u1"
							;;

						*)
							# native
							VERSION="--dch-opt=-b -N ${VERSION}-0.0~progress6+u1"
							;;
					esac
					;;
			esac
			;;
	esac
fi

if grep -qs "git.*.bfh.science" .git/config
then
	DIST="$(git config --get remote.origin.url | awk -F/ '{ print $(NF-1) }')"
	DISTRIBUTION="--distribution=${DIST}"

	case "${VERSION}" in
		*bfh*)
			VERSION=""
			;;

		*)
			case "${VERSION}" in
				*-*)
					# non-native
					VERSION="--dch-opt=-b -N ${VERSION}~bfh10+u1"
					;;

				*)
					# native
					VERSION="--dch-opt=-b -N ${VERSION}-0.0~bfh10+u1"
					;;
			esac
			;;
	esac
fi

if [ -n "${ID}" ]
then
	gbp dch --spawn-editor=never ${DISTRIBUTION} ${VERSION} --urgency ${URGENCY} --git-log="--no-show-signature" --debian-branch $(git branch --show-current) --git-author --release --since ${ID} ${CUSTOMIZATION} ${@}
else
	gbp dch --spawn-editor=never ${DISTRIBUTION} ${VERSION} --urgency ${URGENCY} --git-log="--no-show-signature" --auto --debian-branch $(git branch --show-current) --git-author --release ${CUSTOMIZATION} ${@}
fi

if [ -n "${DIST}" ]
then
	# derivatives
	if ! grep -qs "Initial upload to ${DIST}" debian/changelog
	then
		sed -i -e "0,/^$/s//\n  * Initial upload to ${DIST}./" debian/changelog
	else
		sed -i -e "0,/^$/s//\n  * Uploading to ${DIST}, remaining changes:/" debian/changelog
	fi
else
	# debian
	DIST="$(dpkg-parsechangelog -S Distribution)"
	sed -i -e "0,/^$/s//\n  * Uploading to ${DIST}./" debian/changelog

	if git log ${ID}..HEAD | grep -qs 'Merging upstream version '
	then
		VERSION_NEW="$(git log ${ID}..HEAD | awk '/Merging upstream version/ { print $4 }' | sed -e 's|.$||')"
		VERSION_OLD="$(dpkg-parsechangelog -S Version)"

		sed -i -e "s|^${SOURCE} (${VERSION_OLD}) ${DIST}; urgency=${URGENCY}|${SOURCE} (${VERSION_NEW}-1) ${DIST}; urgency=${URGENCY}|" debian/changelog
	fi
fi

if [ -e "${TEMPFILE}" ]
then
	mv "${TEMPFILE}" debian/gbp.conf
fi

vi debian/changelog