From 7cf3ebc2f7b65f6cb422b063e614cda6bfb472ac Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 17 Jun 2015 09:45:39 -0700 Subject: 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 --- save-git.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'save-git.c') 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) { -- cgit v1.2.3-70-g09d2