Skip to content

Commit a5e91c7

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e2b6aa5 commit a5e91c7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

branch.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
199199

200200
static const char upstream_not_branch[] =
201201
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");
202204

203205
void create_branch(const char *head,
204206
const char *name, const char *start_name,
@@ -227,8 +229,11 @@ void create_branch(const char *head,
227229
}
228230

229231
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));
231235
die("Not a valid object name: '%s'.", start_name);
236+
}
232237

233238
switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
234239
case 0:

0 commit comments

Comments
 (0)