Handle version format errors more gracefully
authorGuido Günther <agx@sigxcpu.org>
Wed, 7 May 2014 18:35:48 +0000 (20:35 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 7 May 2014 18:35:48 +0000 (20:35 +0200)
So far if a package claimed to be non native but the version number
didn't contain a '-' we failed like:

  Traceback (most recent call last):
    File "/usr/bin/gbp", line 9, in <module>
      load_entry_point('gbp==0.6.13', 'console_scripts', 'gbp')()
    File "/usr/lib/python2.7/dist-packages/gbp/scripts/supercommand.py", line 82, in supercommand
      return module.main(args)
    File "/usr/lib/python2.7/dist-packages/gbp/scripts/buildpackage.py", line 541, in main
      output_dir)
    File "/usr/lib/python2.7/dist-packages/gbp/scripts/buildpackage.py", line 96, in prepare_upstream_tarball
      upstream_tree = git_archive_build_orig(repo, cp, output_dir, options)
    File "/usr/lib/python2.7/dist-packages/gbp/scripts/buildpackage.py", line 270, in git_archive_build_orig
      upstream_tree = get_upstream_tree(repo, cp, options)
    File "/usr/lib/python2.7/dist-packages/gbp/scripts/buildpackage.py", line 245, in get_upstream_tree
      cp['Upstream-Version'])
    File "/usr/lib/python2.7/dist-packages/gbp/deb/git.py", line 107, in version_to_tag
      return format % dict(version=DebianGitRepository._sanitize_version(version))
    File "/usr/lib/python2.7/dist-packages/gbp/deb/git.py", line 122, in _sanitize_version
      return version.replace('~', '_').replace(':', '%')

It shouldn't be like that.

gbp/scripts/buildpackage.py

index c077b9e68435c273e976b2eeb7f01307196683a8..77a5b969688b2b6b66436e5ea77c88a63a4022a3 100755 (executable)
@@ -1,6 +1,6 @@
 # vim: set fileencoding=utf-8 :
 #
-# (C) 2006-2013 Guido Günther <agx@sigxcpu.org>
+# (C) 2006-2014 Guido Günther <agx@sigxcpu.org>
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
 #    the Free Software Foundation; either version 2 of the License, or
@@ -241,6 +241,8 @@ def pristine_tar_build_orig(repo, cp, output_dir, options):
 def get_upstream_tree(repo, cp, options):
     """Determine the upstream tree from the given options"""
     if options.upstream_tree.upper() == 'TAG':
+        if cp['Upstream-Version'] is None:
+            raise GitRepositoryError("Can't determine upstream version from changelog")
         upstream_tree = repo.version_to_tag(options.upstream_tag,
                                             cp['Upstream-Version'])
     elif options.upstream_tree.upper() == 'BRANCH':