3 # git-debpush -- create & push a git tag with metadata for an ftp-master upload
5 # Copyright (C) 2019 Sean Whitton
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 set -e${DGIT_TEST_DEBPUSH_DEBUG-x}
25 # Principles of operation
27 # - do not invoke dgit, anything involving any tarballs, no network
30 # - do not look at the working tree, like `git push` `git tag`, and so
31 # we can later add functionality to debpush any branch
33 # - we are always in split brain mode, because this means the push won't
34 # fail because dgit needs to append commits
36 # - if there is no previous tag created by this script, require a quilt
37 # mode; if there is a previous tag, and no quilt mode provided, assume
40 # Other notes (which should be converted to a manpage/usage)
42 # - arguments after '--' passed to `git push`
44 # ---- Helper functions
47 if [ -d "$TEMP" ]; then
52 # ---- Parse command line
56 fail () { echo >&2 "$us: $*"; exit 127; }
57 badusage () { fail "bad usage: $*"; }
59 getopt=$(getopt -s bash -o 'nfu:' \
60 -l 'no-push,force,branch:,remote:,distro:,quilt:,gbp,dpm,baredebian,\
61 baredebian+git,baredebian+tarball,linear' \
64 set -e${DGIT_TEST_DEBPUSH_DEBUG-x}
79 git_tag_opts+=(-u "$2")
98 '--baredebian'|'--baredebian+git')
103 '--baredebian+tarball')
104 quilt_mode=baredebian+tarball
108 '--branch') branch=$2; shift 2; continue ;;
109 '--remote') remote=$2; shift 2; continue ;;
110 '--distro') distro=$2; shift 2; continue ;;
111 '--quilt') quilt_mode=$2; shift 2; continue ;;
117 badusage "unknown option $1"
123 if [ $# != 0 ]; then badusage 'no positional arguments allowed'; fi
125 case "$quilt_mode" in
126 'linear'|'auto'|'smash'|'nofix'|'gbp'|'dpm'|'unapplied'|'baredebian'|'baredebian+tarball')
129 quilt_mode="baredebian"
132 badusage " invalid quilt mode: $quilt_mode"
139 if [ ! "$branch" ]; then
141 branchref="$(git symbolic-ref -q HEAD || test $? = 1)"
144 b=${branchref#refs/heads/}
145 remoteconfigs+=( branch.$b.pushRemote branch.$b.remote )
151 remoteconfigs+=(remote.pushDefault)
153 if $pushing && [ ! "$remote" ]; then
154 for c in "${remoteconfigs[@]}"; do
155 remote=$(git config "$c" || test $? = 1)
156 if [ "x$remote" ]; then break; fi
158 if [ ! "$remote" ]; then
159 fail "pushing, but could not determine remote, so need --remote="
163 # ---- Gather source package information
168 git cat-file blob HEAD:debian/changelog >"$TEMP/debian/changelog"
169 version=$(cd $TEMP; dpkg-parsechangelog -SVersion)
170 source=$(cd $TEMP; dpkg-parsechangelog -SSource)
171 target=$(cd $TEMP; dpkg-parsechangelog -SDistribution)
175 # ---- Useful sanity checks
177 if [ "$force" != "yes" ]; then
179 if [ "$target" = "UNRELEASED" ]; then
180 fail "UNRELEASED changelog"
183 # TODO additional checks we might do:
185 # - are we uploading to a different suite from the last tag
186 # (e.g. unstable after experimental)? user should pass option to
189 # - walking backwards from $branch, if there is an archive/ strictly
190 # before we reach most recent debian/ tag, error, this might be a
191 # push of the dgit view to the maintainer branch
193 # - check for UNRELEASED changelog
197 # ---- Create the git tag
199 get_file_from_ref () {
201 if git ls-tree --name-only -r "$branch" \
202 | grep -Eq "^$path$"; then
203 git cat-file blob $branch:$path
207 format="$(get_file_from_ref debian/source/format)"
209 '3.0 (quilt)') upstream=true ;;
210 '3.0 (native)') upstream=false ;;
212 if get_file_from_ref debian/source/options | grep '^-sn *$'; then
214 elif get_file_from_ref debian/source/options | grep '^-sk *$'; then
217 fail 'xxxx see sn /sk docs'
221 fail "unsupported debian/source/format $format"
226 upstream_tag=$(git deborig --just-print --version="$version" \
228 upstream_committish=$(git rev-parse ${upstream_tag}^{})
229 upstream_info=" upstream-tag=$upstream_tag upstream=$upstream_committish"
232 # convert according to DEP-14 rules
233 git_version=$(echo $version | tr ':~' '%_' | sed 's/\.(?=\.|$|lock$)/.#/g')
235 debian_tag="$distro/$git_version"
237 if [ "x$quilt_mode" = "x" ] && [ "$format" = "3.0 (quilt)" ]; then
238 set +o pipefail # perl will SIGPIPE git-log here
239 tag=$(git log --pretty=format:'%D' --decorate=full "$branch" \
240 | perl -wne 'use Dpkg::Version;
241 @pieces = split /, /, $_;
242 @debian_tag_vs = sort {version_compare($b, $a)}
243 map { m|tag: refs/tags/debian/(.+)| ? $1 : () } @pieces;
244 if (@debian_tag_vs) { print "debian/$debian_tag_vs[0]\n"; exit }')
245 if [ "x$tag" != "x" ]; then
246 quilt_mode=$(git cat-file -p $(git rev-parse "$tag") \
248 'm/^\[dgit.*--quilt=([a-z+]+).*\]$/;
249 if ($1) { print "$1\n"; exit }')
255 if [ "$format" = "3.0 (quilt)" ]; then
256 if [ "x$quilt_mode" = "x" ]; then
257 echo >&2 "$us: could not determine the git branch layout"
258 echo >&2 "$us: please supply a --quilt= argument"
261 quilt_mode_text=" --quilt=$quilt_mode"
265 git tag "${git_tag_opts[@]}" -s -F- "$debian_tag" "$branch" <<EOF
266 $source release $version for $target
268 [dgit distro=$distro split$quilt_mode_text]
269 [dgit please-upload$upstream_info]
275 git push "$remote" "${push_branch[@]}" "$upstream_tag" "$debian_tag"