From e6dce94088ded1174af6e4a1bb498e2944ee0aff Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 13 Jun 2015 18:31:27 -0700 Subject: 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 --- git-access.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/git-access.c b/git-access.c index 85c6f8d3c..cb8a683be 100644 --- a/git-access.c +++ b/git-access.c @@ -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) -- cgit v1.2.3-70-g09d2