gbp_retag_commit.sh: use the default values of gbp-buildpackage for TAG
[debian/scripts.git] / gbp_retag_commit.sh
1 #!/bin/sh
2 #
3 # gbp_retag_commit - retag a revision of a debian package, gbp style
4 #
5 # Copyright (C) 2015  Antonio Ospite <ao2@ao2.it>
6 #
7 # This program is free software. It comes without any warranty, to
8 # the extent permitted by applicable law. You can redistribute it
9 # and/or modify it under the terms of the Do What The Fuck You Want
10 # To Public License, Version 2, as published by Sam Hocevar. See
11 # http://sam.zoy.org/wtfpl/COPYING for more details.
12
13 set -e
14
15 usage() {
16   echo "usage: $(basename $0) <COMMIT_ID>";
17 }
18
19 HASH="$1"
20
21 git cat-file -e "${HASH}^{commit}" || { usage 1>&2; exit 1; }
22
23 CHANGELOG_HEADER="$(git show $HASH:debian/changelog | head -1)"
24
25 # TODO: give a warning or an error if this is is an UNRELEASED version?
26
27 PACKAGE=$(echo "$CHANGELOG_HEADER" | cut -d ' ' -f 1)
28 VERSION=$(echo "$CHANGELOG_HEADER" | cut -d '(' -f 2 | cut -d ')' -f 1 )
29
30 # Use the same default values of gbp-buildpackage
31 TAG="debian/$VERSION"
32 TAG_MESSAGE="$PACKAGE Debian release $VERSION"
33
34 # TODO: maybe drop the older $TAG if it exists?
35
36 GIT_COMMITTER_DATE="$(git show --format=%aD $HASH | head -1)" \
37   git tag -a "$TAG" $HASH -m "$TAG_MESSAGE"