submodule--helper: return error from set-url when modifying failed

set-branch will return an error when setting the config fails so I don't see why set-url shouldn't. Also skip the sync in this case. Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jan Alexander Steffens (heftig) committed Oct 3, 2023 at 20:50 UTC 387c122131a9f8e4a67122d53955133d099b64a7
1 file changed +7 -5
builtin/submodule--helper.c
+7 -5
@@ -2889,7 +2889,7 @@ cleanup:
2889
2890 static int module_set_url(int argc, const char **argv, const char *prefix)
2891 {
2892 - int quiet = 0;
2892 + int quiet = 0, ret;
2893 const char *newurl;
2894 const char *path;
2895 char *config_name;
@@ -2915,13 +2915,15 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
2915 path);
2916
2917 config_name = xstrfmt("submodule.%s.url", sub->name);
2918 - config_set_in_gitmodules_file_gently(config_name, newurl);
2918 + ret = config_set_in_gitmodules_file_gently(config_name, newurl);
2919
2920 - repo_read_gitmodules (the_repository, 0);
2921 - sync_submodule(sub->path, prefix, NULL, quiet ? OPT_QUIET : 0);
2920 + if (!ret) {
2921 + repo_read_gitmodules(the_repository, 0);
2922 + sync_submodule(sub->path, prefix, NULL, quiet ? OPT_QUIET : 0);
2923 + }
2924
2925 free(config_name);
2924 - return 0;
2926 + return !!ret;
2927 }
2928
2929 static int module_set_branch(int argc, const char **argv, const char *prefix)