Skip to content

Instantly share code, notes, and snippets.

@nikicat
Last active August 29, 2021 12:00
Show Gist options
  • Save nikicat/4653121 to your computer and use it in GitHub Desktop.
Save nikicat/4653121 to your computer and use it in GitHub Desktop.
Shell script to regenerate debian changelog from git log
#!/bin/sh
sudo apt-get install -y moreutils git-buildpackage
>debian/changelog
prevtag=initial
pkgname=`cat debian/control | grep '^Package: ' | sed 's/^Package: //'`
git tag -l v* | sort -V | while read tag; do
(echo "$pkgname (${tag#v}) unstable; urgency=low\n"; git log --pretty=format:' * %s' $prevtag..$tag; git log --pretty='format:%n%n -- %aN <%aE> %aD%n%n' $tag^..$tag) | cat - debian/changelog | sponge debian/changelog
prevtag=$tag
done
tag=`git tag -l v* | sort -V | tail -1`
[ `git log --exit-code $tag..HEAD | wc -l` -ne 0 ] && git-dch -s $tag -S --no-multimaint --nmu --ignore-branch --snapshot-number="'{:%Y%m%d%H%M%S}'.format(__import__('datetime').datetime.fromtimestamp(`git log -1 --pretty=format:%at`))"
sed -i 's/UNRELEASED/unstable/' debian/changelog
git commit -a -m 'regenerated debian changelog'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment