diff options
author | Gustav Hållberg <gustav@gmail.com> | 2012-04-07 21:25:41 +0200 |
---|---|---|
committer | Gustav Hållberg <gustav@gmail.com> | 2012-04-07 21:25:41 +0200 |
commit | 9a60c57ca3362f5e66646990ae9d8c8f3cd5320a (patch) | |
tree | e9cb1fa8ed1d4b17fb592c5499c0716de9c89cf1 | |
parent | 43f11d852843acde5e0470d28ce98eaa45ee879d (diff) | |
download | stgit-9a60c57ca3362f5e66646990ae9d8c8f3cd5320a.tar.gz |
ignore error return from git show-ref when reading ref cache
This makes stg produce a slightly better error message when run in a
newly initialized (empty) git tree.
Signed-off-by: Gustav Hållberg <gustav@gmail.com>
-rw-r--r-- | stgit/lib/git.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/stgit/lib/git.py b/stgit/lib/git.py index e7f095e..1d7ee46 100644 --- a/stgit/lib/git.py +++ b/stgit/lib/git.py @@ -445,7 +445,14 @@ class Refs(object): def __cache_refs(self): """(Re-)Build the cache of all refs in the repository.""" self.__refs = {} - for line in self.__repository.run(['git', 'show-ref']).output_lines(): + runner = self.__repository.run(['git', 'show-ref']) + try: + lines = runner.output_lines() + except run.RunException: + # as this happens both in non-git trees and empty git + # trees, we silently ignore this error + return + for line in lines: m = re.match(r'^([0-9a-f]{40})\s+(\S+)$', line) sha1, ref = m.groups() self.__refs[ref] = sha1 |