Commit 6a5675cb authored by Guido Günther's avatar Guido Günther

GitRepository: Use C locale when building error messages

If we use stderr to build the error message we need to use the C locale
when invoking git commands since otherwise we might end up with non
ascii characters. Leading to errors like:

 gbp:debug: ['git', 'describe', '--match', 'upstream/*', '--abbrev=0',
 u'99b4406e2c43ed1e011239e07f2f809dad4803c0']
 Traceback (most recent call last):
   File "/usr/bin/gbp", line 9, in <module>
     load_entry_point('gbp==0.6.31', 'console_scripts', 'gbp')()
   File "/usr/lib/python2.7/dist-packages/gbp/scripts/supercommand.py",
   line 136, in supercommand
     return module.main(args)
   File "/usr/lib/python2.7/dist-packages/gbp/scripts/dch.py", line
   480, in main
     options.upstream_branch, cp)
   File "/usr/lib/python2.7/dist-packages/gbp/scripts/dch.py", line 48,
   in guess_version_from_upstream
     epoch=cp.epoch)
   File "/usr/lib/python2.7/dist-packages/gbp/deb/git.py", line 83, in
   debian_version_from_upstream
     tag = self.find_branch_tag(commit, upstream_branch,
     pattern=pattern)
   File "/usr/lib/python2.7/dist-packages/gbp/git/repository.py", line
   729, in find_branch_tag
     return self.describe(base_commit, pattern, abbrev=0)
   File "/usr/lib/python2.7/dist-packages/gbp/git/repository.py", line
   700, in describe
     (commitish, err.strip()))
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
 19: ordinal not in range(128)
parent 21eaad96
......@@ -420,7 +420,10 @@ class GitRepository(object):
args = GitArgs()
args.add(commit1)
args.add(commit2)
sha1, stderr, ret = self._git_inout('merge-base', args.args, capture_stderr=True)
sha1, stderr, ret = self._git_inout('merge-base',
args.args,
extra_env={'LC_ALL': 'C'},
capture_stderr=True)
if not ret:
return self.strip_sha1(sha1).decode('utf-8')
else:
......@@ -577,6 +580,7 @@ class GitRepository(object):
dummy, err, ret = self._git_inout('branch',
args,
extra_env={'LC_ALL': 'C'},
capture_stderr=True)
if ret:
raise GitRepositoryError(
......@@ -694,10 +698,11 @@ class GitRepository(object):
args.add(commitish)
tag, err, ret = self._git_inout('describe', args.args,
extra_env={'LC_ALL': 'C'},
capture_stderr=True)
if ret:
raise GitRepositoryError("Can't describe %s. Git error: %s" % \
(commitish, err.strip()))
raise GitRepositoryError("Can't describe %s. Git error: %s" %
(commitish, err.strip()))
return tag.strip()
def find_tag(self, commit, pattern=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment