summaryrefslogtreecommitdiffstats
path: root/save-git.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-17 09:45:39 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-17 09:45:39 -0700
commit7cf3ebc2f7b65f6cb422b063e614cda6bfb472ac (patch)
tree32c6e94e4027549e6dcec97bab5e82fce92478be /save-git.c
parent5d09244c0f7dc2376d9d7eeff5fba5fde96cc6e1 (diff)
downloadsubsurface-7cf3ebc2f7b65f6cb422b063e614cda6bfb472ac.tar.gz
Git storage: only check git_id if saving to the same remote
If we switch to a different remote (let's say we opened a local git repo and want to save its content to the cloud storage) then don't check to make sure that the branch stayed unchanged (because, duh, it's a different remote, it will have changed). This fixes the problem where you could open an XML file and store it to cloud storage just fine, but opening a local git repository and then storing that to cloud storage failed. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-git.c')
-rw-r--r--save-git.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/save-git.c b/save-git.c
index 64e04823b..f76029f11 100644
--- a/save-git.c
+++ b/save-git.c
@@ -1004,7 +1004,7 @@ static void create_commit_message(struct membuffer *msg)
put_format(msg, "Created by subsurface %s\n", subsurface_version());
}
-static int create_new_commit(git_repository *repo, const char *branch, git_oid *tree_id)
+static int create_new_commit(git_repository *repo, const char *remote, const char *branch, git_oid *tree_id)
{
int ret;
git_reference *ref;
@@ -1029,8 +1029,12 @@ static int create_new_commit(git_repository *repo, const char *branch, git_oid *
return report_error("Unable to look up parent in branch '%s'", branch);
if (saved_git_id) {
+ if (existing_filename)
+ fprintf(stderr, "existing filename %s\n", existing_filename);
const git_oid *id = git_commit_id((const git_commit *) parent);
- if (git_oid_strcmp(id, saved_git_id))
+ /* if we are saving to the same git tree we got this from, let's make
+ * sure there is no confusion */
+ if (!strcmp(existing_filename, remote) && git_oid_strcmp(id, saved_git_id))
return report_error("The git branch does not match the git parent of the source");
}
@@ -1136,7 +1140,7 @@ int do_git_save(git_repository *repo, const char *branch, const char *remote, bo
return report_error("git tree write failed");
/* And save the tree! */
- if (create_new_commit(repo, branch, &id))
+ if (create_new_commit(repo, remote, branch, &id))
return report_error("creating commit failed");
if (remote && prefs.cloud_background_sync) {