aboutsummaryrefslogtreecommitdiffstats
path: root/git-access.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-13 18:31:27 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-13 18:36:08 -0700
commite6dce94088ded1174af6e4a1bb498e2944ee0aff (patch)
tree62c3650fb34f24009a5e8453bdd458f9fadbaa8e /git-access.c
parentef85875cd006db61679b95e62fd70101c9014799 (diff)
downloadsubsurface-e6dce94088ded1174af6e4a1bb498e2944ee0aff.tar.gz
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>
Diffstat (limited to 'git-access.c')
-rw-r--r--git-access.c22
1 files 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)