From 3eb6e16892dd0ab6eafb55f938308da91830ae2c Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 27 Aug 2018 23:30:58 -0400 Subject: [PATCH] Add a __main__.py; fix GitPython remote fetch error message. --- CHANGELOG | 2 ++ gitup/__main__.py | 9 +++++++++ gitup/script.py | 4 +++- gitup/update.py | 12 ++++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 gitup/__main__.py diff --git a/CHANGELOG b/CHANGELOG index 716b0d1..6b62186 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,8 +8,10 @@ v0.5 (unreleased): old behavior. - `--depth 3` will look three levels deep. This is the new default. - `--depth -1` will recurse indefinitely. This is not recommended. +- Allow gitup to be run directly as a Python module (python -m gitup). - Fixed an error when updating branches if the upstream is completely unrelated from the local branch (no common ancestor). +- Fixed error message when fetching from a remote fails. v0.4.1 (released December 13, 2017): diff --git a/gitup/__main__.py b/gitup/__main__.py new file mode 100644 index 0000000..86df533 --- /dev/null +++ b/gitup/__main__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2011-2018 Ben Kurtovic +# Released under the terms of the MIT License. See LICENSE for details. + +from .script import run + +if __name__ == "__main__": + run() diff --git a/gitup/script.py b/gitup/script.py index b8dc344..38d7e3e 100644 --- a/gitup/script.py +++ b/gitup/script.py @@ -7,6 +7,7 @@ from __future__ import print_function import argparse import os +import platform import sys from colorama import init as color_init, Fore, Style @@ -84,7 +85,8 @@ def main(): '-h', '--help', action="help", help="show this help message and exit") group_m.add_argument( '-v', '--version', action="version", - version="gitup " + __version__) + version="gitup {0} (Python {1})".format( + __version__, platform.python_version())) # TODO: deprecated arguments, for removal in v1.0: parser.add_argument( diff --git a/gitup/update.py b/gitup/update.py index 5c73e68..051ef00 100644 --- a/gitup/update.py +++ b/gitup/update.py @@ -7,6 +7,8 @@ from __future__ import print_function from glob import glob import os +import pipes +import re import shlex from colorama import Fore, Style @@ -77,8 +79,14 @@ def _fetch_remotes(remotes, prune): try: results = remote.fetch(progress=_ProgressMonitor(), prune=prune) except exc.GitCommandError as err: - msg = err.command[0].replace("Error when fetching: ", "") - if not msg.endswith("."): + # We should have to do this ourselves, but GitPython doesn't give + # us a sensible way to get the raw stderr... + msg = re.sub(r"\s+", " ", err.stderr).strip() + msg = re.sub(r"^stderr: *'(fatal: *)?", "", msg).strip("'") + if not msg: + command = " ".join(pipes.quote(arg) for arg in err.command) + msg = "{0} failed with status {1}.".format(command, err.status) + elif not msg.endswith("."): msg += "." print(":", RED + "error:", msg) return