remote: remove rename code for anonymous remotes We don't allow renames of anonymous remotes, so there's no need to handle them. A remote is always associated with a repository, so there's no need to check for that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/src/remote.c b/src/remote.c
index 0d1a88e..dd88cf9 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1442,10 +1442,8 @@ static int rename_fetch_refspecs(
if (spec->push)
continue;
- /* Every refspec is a problem refspec for an anonymous remote, OR */
/* Does the dst part of the refspec follow the expected format? */
- if (!remote->name ||
- strcmp(git_buf_cstr(&base), spec->string)) {
+ if (strcmp(git_buf_cstr(&base), spec->string)) {
if ((error = callback(spec->string, payload)) != 0) {
giterr_set_after_callback(error);
@@ -1497,49 +1495,20 @@ int git_remote_rename(
if ((error = ensure_remote_name_is_valid(new_name)) < 0)
return error;
- if (remote->repo) {
- if ((error = ensure_remote_doesnot_exist(remote->repo, new_name)) < 0)
- return error;
+ if ((error = ensure_remote_doesnot_exist(remote->repo, new_name)) < 0)
+ return error;
- if (!remote->name) {
- if ((error = rename_fetch_refspecs(
- remote,
- new_name,
- callback,
- payload)) < 0)
- return error;
+ if ((error = rename_remote_config_section(remote->repo, remote->name, new_name)) < 0)
+ return error;
- remote->name = git__strdup(new_name);
- GITERR_CHECK_ALLOC(remote->name);
+ if ((error = update_branch_remote_config_entry(remote->repo, remote->name, new_name)) < 0)
+ return error;
- return git_remote_save(remote);
- }
+ if ((error = rename_remote_references(remote->repo, remote->name, new_name)) < 0)
+ return error;
- if ((error = rename_remote_config_section(
- remote->repo,
- remote->name,
- new_name)) < 0)
- return error;
-
- if ((error = update_branch_remote_config_entry(
- remote->repo,
- remote->name,
- new_name)) < 0)
- return error;
-
- if ((error = rename_remote_references(
- remote->repo,
- remote->name,
- new_name)) < 0)
- return error;
-
- if ((error = rename_fetch_refspecs(
- remote,
- new_name,
- callback,
- payload)) < 0)
- return error;
- }
+ if ((error = rename_fetch_refspecs(remote, new_name, callback, payload)) < 0)
+ return error;
git__free(remote->name);