/* this should correctly initialize both the local and remote * repository for the Subsurface cloud storage */ static git_repository *create_and_push_remote(const char *localdir, const char *remote, const char *branch) { git_repository *repo; git_config *conf; int len; char *variable_name, *merge_head; /* first make sure the directory for the local cache exists */ subsurface_mkdir(localdir); /* set up the origin to point to our remote */ git_repository_init_options init_opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; init_opts.origin_url = remote; /* now initialize the repository with */ git_repository_init_ext(&repo, localdir, &init_opts); /* create a config so we can set the remote tracking branch */ git_repository_config(&conf, repo); len = sizeof("branch..remote") + strlen(branch); variable_name = malloc(len); snprintf(variable_name, len, "branch.%s.remote", branch); git_config_set_string(conf, variable_name, "origin"); /* we know this is shorter than the previous one, so we reuse the variable*/ snprintf(variable_name, len, "branch.%s.merge", branch); len = sizeof("refs/heads/") + strlen(branch); merge_head = malloc(len); snprintf(merge_head, len, "refs/heads/%s", branch); git_config_set_string(conf, variable_name, merge_head); /* finally create an empty commit and push it to the remote */ if (do_git_save(repo, branch, remote, false, true)) return NULL; return(repo); }
/* this should correctly initialize both the local and remote * repository for the Subsurface cloud storage */ static git_repository *create_and_push_remote(const char *localdir, const char *remote, const char *branch) { git_repository *repo; git_config *conf; char *variable_name, *merge_head; if (verbose) fprintf(stderr, "git storage: create and push remote\n"); /* first make sure the directory for the local cache exists */ subsurface_mkdir(localdir); /* set up the origin to point to our remote */ git_repository_init_options init_opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; init_opts.origin_url = remote; /* now initialize the repository with */ git_repository_init_ext(&repo, localdir, &init_opts); /* create a config so we can set the remote tracking branch */ git_repository_config(&conf, repo); variable_name = format_string("branch.%s.remote", branch); git_config_set_string(conf, variable_name, "origin"); free(variable_name); variable_name = format_string("branch.%s.merge", branch); merge_head = format_string("refs/heads/%s", branch); git_config_set_string(conf, variable_name, merge_head); free(merge_head); free(variable_name); /* finally create an empty commit and push it to the remote */ if (do_git_save(repo, branch, remote, false, true)) return NULL; return repo; }