Merge branch 'ds/scalar-reconfigure-all-fix' into maint-2.45

Scalar fix.

* ds/scalar-reconfigure-all-fix:
  scalar: avoid segfault in reconfigure --all
maint
Junio C Hamano 2024-06-28 15:53:12 -07:00
commit b608b33f3d
2 changed files with 45 additions and 3 deletions

View File

@ -645,7 +645,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,
@ -665,6 +664,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);
@ -712,13 +712,17 @@ 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;

the_repository = old_repo;

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

View File

@ -180,6 +180,44 @@ test_expect_success 'scalar reconfigure' '
test true = "$(git -C one/src config core.preloadIndex)"
'

test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '
repos="two three four" &&
for num in $repos
do
git init $num/src &&
scalar register $num/src &&
git -C $num/src config includeif."onbranch:foo".path something &&
git -C $num/src config core.preloadIndex false || return 1
done &&

scalar reconfigure --all &&

for num in $repos
do
test true = "$(git -C $num/src config core.preloadIndex)" || return 1
done
'

test_expect_success 'scalar reconfigure --all with detached HEADs' '
repos="two three four" &&
for num in $repos
do
rm -rf $num/src &&
git init $num/src &&
scalar register $num/src &&
git -C $num/src config core.preloadIndex false &&
test_commit -C $num/src initial &&
git -C $num/src switch --detach HEAD || return 1
done &&

scalar reconfigure --all &&

for num in $repos
do
test true = "$(git -C $num/src config core.preloadIndex)" || return 1
done
'

test_expect_success '`reconfigure -a` removes stale config entries' '
git init stale/src &&
scalar register stale &&