Cloud storage: if there is no remote tracking branch, create it

When we first store things to the remote there won't be a matching branch
for it. And even if for some silly reason the remote branch got lost -
what's the point of telling the user that there is no remote branch? What
are they supposed to do about it. Let's just fix the problem and move on.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-06-13 18:31:27 -07:00
parent ef85875cd0
commit e6dce94088

View file

@ -205,13 +205,25 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c
return report_error("Git cache branch %s no longer exists", branch);
if (git_branch_upstream(&remote_ref, local_ref)) {
git_reference_free(local_ref);
return report_error("Git cache branch %s no longer has an upstream branch", branch);
/* so there is no upstream branch for our branch; that's a problem.
/* let's push our branch */
git_strarray refspec;
git_reference_list(&refspec, repo);
#if USE_LIBGIT23_API
git_push_options opts = GIT_PUSH_OPTIONS_INIT;
if (rt == RT_SSH)
opts.callbacks.credentials = credential_ssh_cb;
else if (rt == RT_HTTPS)
opts.callbacks.credentials = credential_https_cb;
git_remote_push(origin, &refspec, &opts);
#else
git_remote_push(origin, &refspec, NULL);
#endif
} else {
try_to_update(repo, origin, local_ref, remote_ref, rt);
git_reference_free(remote_ref);
}
try_to_update(repo, origin, local_ref, remote_ref, rt);
git_reference_free(local_ref);
git_reference_free(remote_ref);
}
int sync_with_remote(git_repository *repo, const char *remote, const char *branch, enum remote_transport rt)