branch: improve error message for missing --set-upstream-to ref
If we are trying to set the upstream config for a branch, the create_branch function will check both that the name resolves as a ref, and that it is either a local or remote-tracking branch. However, before we do so we run get_sha1 on it to find out whether it resolves at all (since the create_branch function is also used to create actual branches, it wants to know where to start the new branch). This means that if you feed a ref that does not exist to "branch --set-upstream-to", rather than getting a helpful message about tracking, you only get "not a valid object name". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Apr 2, 2013 at 15:04 UTC
a5e91c722cceb667ad05a13f9fde150cc1dbe9aa
1 file changed
+6
-1
branch.c
+6
-1
@@ -199,6 +199,8 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
199
200
static const char upstream_not_branch[] =
201
N_("Cannot setup tracking information; starting point is not a branch.");
202
+static const char upstream_missing[] =
203
+N_("Cannot setup tracking information; starting point does not exist");
204
205
void create_branch(const char *head,
206
const char *name, const char *start_name,
@@ -227,8 +229,11 @@ void create_branch(const char *head,
229
}
230
231
real_ref = NULL;
230
- if (get_sha1(start_name, sha1))
232
+ if (get_sha1(start_name, sha1)) {
233
+ if (explicit_tracking)
234
+ die(_(upstream_missing));
235
die("Not a valid object name: '%s'.", start_name);
236
+ }
237
238
switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
239
case 0: