remote: improve error message if no URL is set The current error message when connecting to a remote when no URL is set is missing information on whether it is missing a fetch or push URL. Furthermore, it results in undefined behavior when using a remote without name. Fix both issues.
diff --git a/src/remote.c b/src/remote.c
index bd8b3cf..bbca7ae 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -674,7 +674,9 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
url = git_remote__urlfordirection(remote, direction);
if (url == NULL) {
giterr_set(GITERR_INVALID,
- "Malformed remote '%s' - missing URL", remote->name);
+ "Malformed remote '%s' - missing %s URL",
+ remote->name ? remote->name : "(anonymous)",
+ direction == GIT_DIRECTION_FETCH ? "fetch" : "push");
return -1;
}