Creating snapshots with increasing version numbers

The downside of the above methods is that you either have the version number of the last release in debian/changelog or that you have a changelog entry with UNRELEASED that has the same version number for all commits you do during the development cycle of your package. Although this is common practice in Debian™ it means that also all your test builds have the same version number which makes them hard to distinguish in e.g. continuous integration pipelines.

To address these shortcomings gbp dch has a --snapshot option that can be used to create (unreleased) snapshots for intermediate testing with a version number that is lower than the one of the final package:

gbp dch --snapshot

will generate a snapshot release with a specially crafted version number and a warning in the changelog that this is a snapshot release:

git-buildpackage (0.3.7~1.gbp470ce2) UNRELEASED; urgency=low

  ** SNAPSHOT build @470ce29ec7877705c844474a2fd89869aea0406d **

  * add support for automatic snapshot 

During subsequent calls with --snapshot, this version number will continue to increase. Since the snapshot banner contains the commit id of the current branch HEAD, gbp dch can figure out what to append to the changelog by itself (even without committing the changelog first):

gbp dch --snapshot

will fetch the commit id from debian/changelog and add changelog entries from that point to the current HEAD—again auto incrementing the version number. If you don't want to start at that commit id, you can specify any id or tag with:

gbp dch --since=e76a6a180a57701ae4ae381f74523cacb3152780 --snapshot

After testing, you can remove the snapshot header by a final gbp dch call:

gbp dch --release

This will pick new commit if present and remove the specially crafted version number and the snapshot header. If you want finer control of what is being added you can again use the --since.

Customizing snapshot numbers

If the auto incrementing of the snapshot number doesn't suite your needs, you can give any Python expression that evaluates to a positive integer to calculate the new snapshot number:

gbp dch -S -a --snapshot-number=1
gbp dch -S -a --snapshot-number='snapshot + 2'
gbp dch -S -a --snapshot-number='os.popen("git-log --pretty=oneline | wc -l").readlines()[0]'
gbp dch -S -a --snapshot-number=`git-log --pretty=oneline debian/0.3.3 | wc -l`

You can also add the snapshot-number calculation to gbp.conf:

[DEFAULT]
snapshot-number = os.popen("git-log --pretty=oneline | wc -l").readlines()[0]