-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautodch
executable file
·38 lines (32 loc) · 1.24 KB
/
autodch
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
#!/bin/bash
# Automatically write changelog entries from Git commits
# Inspired by "gbp dch" but with more straightforward support for monorepos (packages as subdirectories)
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
package="$1"
release="${2:-UNRELEASED}"
if [[ -z "$package" ]]; then
echo "Usage: $0 <package> [release]"
exit 1
fi
# https://git-scm.com/docs/pretty-formats#Documentation/pretty-formats.txt-emHem
GIT_TO_CHANGELOG_FORMAT='%aN|[%h] %s'
PKG_VERSION="$(date +%Y.%m.%d)"
changelog_fname="$package/debian/changelog"
last_changelog_commit="$(git log --pretty=format:%H -n 1 -- "$changelog_fname")"
if [[ -z "$last_changelog_commit" ]]; then
echo "ERR: last commit not found for $changelog_fname"
exit 1
elif ! git diff --exit-code "$changelog_fname"; then
echo "ERR: $changelog_fname has unstaged changes"
exit 1
fi
set -e
pushd "$package"
dch -v "$PKG_VERSION" -m "" -D "$release" # create an empty changelog entry
while read -r line; do
echo "$line"
name="$(cut -d '|' -f 1 <<< "$line")"
commit_title="$(cut -d '|' -f 2- <<< "$line")"
echo "$commit_title"
DEBFULLNAME="$name" dch -a "$commit_title"
done < <( git log --pretty=format:"$GIT_TO_CHANGELOG_FORMAT" "${last_changelog_commit}~1"...HEAD "." )