Gracefully handle cloud authentication failure in verbose mode

If the credential functions return GIT_EUSER, a call to git_remote_fetch
fails, but giterr_last() may return NULL. This led to a crash in
verbose mode.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2017-12-05 19:53:05 +01:00 committed by Dirk Hohndel
parent 4dbbf1ff27
commit d4cd4a96ea

View file

@ -607,7 +607,9 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc
else
report_error("Unable to fetch remote '%s'", remote);
if (verbose)
fprintf(stderr, "remote fetch failed (%s)\n", giterr_last()->message);
// If we returned GIT_EUSER during authentication, giterr_last() returns NULL
fprintf(stderr, "remote fetch failed (%s)\n",
giterr_last() ? giterr_last()->message : "authentication failed");
error = 0;
} else {
error = check_remote_status(repo, origin, remote, branch, rt);