From e76f527fe53063663bdf1f71ca870e7009743f25 Mon Sep 17 00:00:00 2001 From: Jan Mulder Date: Sat, 29 Jul 2017 09:39:49 +0200 Subject: Correctly create cloud account from mobile The creation of a cloud account from mobile was broken. This fixes it. Basically, we need to go online for a moment, and setup a correct local and remote repo for the cloud storage. Tested for the following scenarios: 1) inital account creation including PIN handling from mobile, from a clean install . 2) open an already validated cloud account from a clean install. 3) open no-cloud style local account. 4) Switch between 2 already validated could accounts. 5) Try to create a cloud account without data connection. Notice that scenario 4) does not work perfectly. A restart of the app is needed to see the new logbook. So that is to be fixed. Scenario 5) seems a non realistic corner case. This does not work in a gracefull way. The user needs to remove the app, install it again, and retry with data connection. Further notice this is backgroud/core processing only. So no QML UI changes as proposed (for example) bij Davide. Signed-off-by: Jan Mulder --- core/git-access.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/core/git-access.c b/core/git-access.c index fc2c1223a..05b3d02fd 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -736,7 +736,9 @@ static git_repository *create_local_repo(const char *localdir, const char *remot if (verbose > 1) fprintf(stderr, "git storage: returned from git_clone() with error %d\n", error); if (error) { - char *msg = giterr_last()->message; + char *msg = ""; + if (giterr_last()) + msg = giterr_last()->message; int len = sizeof("reference 'refs/remotes/origin/' not found") + strlen(branch); char *pattern = malloc(len); snprintf(pattern, len, "reference 'refs/remotes/origin/%s' not found", branch); @@ -784,12 +786,23 @@ static struct git_repository *get_remote_repo(const char *localdir, const char * return NULL; } return update_local_repo(localdir, remote, branch, rt); + } else { + /* we have no local cache yet */ + if (is_subsurface_cloud) { + /* and take us temporarly online to create a local and + * remote cloud repo. + */ + git_repository *ret; + bool glo = prefs.git_local_only; + prefs.git_local_only = false; + ret = create_local_repo(localdir, remote, branch, rt); + prefs.git_local_only = glo; + return ret; + } } - if (!prefs.git_local_only) - return create_local_repo(localdir, remote, branch, rt); - else - return 0; + /* all normal cases are handled above */ + return 0; } /* -- cgit v1.2.3-70-g09d2