Skip to content

Commit

Permalink
scalar: avoid segfault in reconfigure --all
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <stolee@gmail.com>
  • Loading branch information
derrickstolee committed Apr 30, 2024
1 parent b68812e commit 89145b5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -1048,6 +1047,8 @@ static int cmd_reconfigure(int argc, const char **argv)

for (i = 0; i < scalar_repos.nr; i++) {
int succeeded = 0;
struct repository *old_repo;
struct repository r = { NULL };
const char *dir = scalar_repos.items[i].string;

strbuf_reset(&commondir);
Expand Down Expand Up @@ -1095,16 +1096,21 @@ 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)
succeeded = 1;

if (toggle_maintenance(1) >= 0)
succeeded = 1;

the_repository = old_repo;
repo_clear(&r);

loop_end:
if (!succeeded) {
res = -1;
Expand Down

0 comments on commit 89145b5

Please sign in to comment.