diff --git a/scalar.c b/scalar.c index 611831e33fcc19..9cedb21bbc6438 100644 --- a/scalar.c +++ b/scalar.c @@ -1028,7 +1028,6 @@ static int cmd_reconfigure(int argc, const char **argv) }; struct string_list scalar_repos = STRING_LIST_INIT_DUP; int i, res = 0; - struct repository r = { NULL }; struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT; argc = parse_options(argc, argv, NULL, options, @@ -1048,6 +1047,7 @@ static int cmd_reconfigure(int argc, const char **argv) for (i = 0; i < scalar_repos.nr; i++) { int succeeded = 0; + struct repository *old_repo, r = { NULL }; const char *dir = scalar_repos.items[i].string; strbuf_reset(&commondir); @@ -1095,14 +1095,18 @@ static int cmd_reconfigure(int argc, const char **argv) git_config_clear(); + if (repo_init(&r, gitdir.buf, commondir.buf)) + goto loop_end; + + old_repo = the_repository; the_repository = &r; - r.commondir = commondir.buf; - r.gitdir = gitdir.buf; if (set_recommended_config(1) >= 0 && toggle_maintenance(1) >= 0) succeeded = 1; + the_repository = old_repo; + loop_end: if (!succeeded) { res = -1; diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index ac3b8b3a02bfdf..dcb80340e9e851 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -190,6 +190,44 @@ test_expect_success 'scalar reconfigure' ' test_subcommand git maintenance start