download: unify error handling with sub git calls

We gracefully handle cherry-pick errors, but none of the others
which means people get confusing Python tracebacks.  Move the
main logic in a single GitError try block so we can show pretty
error messages for all of them.

Change-Id: I52cdf6468d21a98de7f65b86d5267b3caabd5af8
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/259854
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2020-03-22 13:36:27 -04:00
parent 915fda130e
commit 05097c6222

View File

@ -109,18 +109,28 @@ If no project is specified try to use current directory as a project.
file=sys.stderr) file=sys.stderr)
for c in dl.commits: for c in dl.commits:
print(' %s' % (c), file=sys.stderr) print(' %s' % (c), file=sys.stderr)
if opt.cherrypick: if opt.cherrypick:
try: mode = 'cherry-pick'
elif opt.revert:
mode = 'revert'
elif opt.ffonly:
mode = 'fast-forward merge'
else:
mode = 'checkout'
try:
if opt.cherrypick:
project._CherryPick(dl.commit, ffonly=opt.ffonly, project._CherryPick(dl.commit, ffonly=opt.ffonly,
record_origin=opt.record_origin) record_origin=opt.record_origin)
except GitError: elif opt.revert:
print('[%s] Could not complete the cherry-pick of %s' project._Revert(dl.commit)
% (project.name, dl.commit), file=sys.stderr) elif opt.ffonly:
sys.exit(1) project._FastForward(dl.commit, ffonly=True)
else:
project._Checkout(dl.commit)
elif opt.revert: except GitError:
project._Revert(dl.commit) print('[%s] Could not complete the %s of %s'
elif opt.ffonly: % (project.name, mode, dl.commit), file=sys.stderr)
project._FastForward(dl.commit, ffonly=True) sys.exit(1)
else:
project._Checkout(dl.commit)