Skip to content

Commit 4582676

Browse files
dschogitster
authored andcommitted
scalar: teach 'reconfigure' to optionally handle all registered enlistments
After a Scalar upgrade, it can come in really handy if there is an easy way to reconfigure all Scalar enlistments. This new option offers this functionality. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb59d55 commit 4582676

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

contrib/scalar/scalar.c

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,22 +488,77 @@ static int cmd_register(int argc, const char **argv)
488488
return register_dir();
489489
}
490490

491+
static int get_scalar_repos(const char *key, const char *value, void *data)
492+
{
493+
struct string_list *list = data;
494+
495+
if (!strcmp(key, "scalar.repo"))
496+
string_list_append(list, value);
497+
498+
return 0;
499+
}
500+
491501
static int cmd_reconfigure(int argc, const char **argv)
492502
{
503+
int all = 0;
493504
struct option options[] = {
505+
OPT_BOOL('a', "all", &all,
506+
N_("reconfigure all registered enlistments")),
494507
OPT_END(),
495508
};
496509
const char * const usage[] = {
497-
N_("scalar reconfigure [<enlistment>]"),
510+
N_("scalar reconfigure [--all | <enlistment>]"),
498511
NULL
499512
};
513+
struct string_list scalar_repos = STRING_LIST_INIT_DUP;
514+
int i, res = 0;
515+
struct repository r = { NULL };
516+
struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT;
500517

501518
argc = parse_options(argc, argv, NULL, options,
502519
usage, 0);
503520

504-
setup_enlistment_directory(argc, argv, usage, options, NULL);
521+
if (!all) {
522+
setup_enlistment_directory(argc, argv, usage, options, NULL);
523+
524+
return set_recommended_config(1);
525+
}
526+
527+
if (argc > 0)
528+
usage_msg_opt(_("--all or <enlistment>, but not both"),
529+
usage, options);
530+
531+
git_config(get_scalar_repos, &scalar_repos);
505532

506-
return set_recommended_config(1);
533+
for (i = 0; i < scalar_repos.nr; i++) {
534+
const char *dir = scalar_repos.items[i].string;
535+
536+
strbuf_reset(&commondir);
537+
strbuf_reset(&gitdir);
538+
539+
if (chdir(dir) < 0) {
540+
warning_errno(_("could not switch to '%s'"), dir);
541+
res = -1;
542+
} else if (discover_git_directory(&commondir, &gitdir) < 0) {
543+
warning_errno(_("git repository gone in '%s'"), dir);
544+
res = -1;
545+
} else {
546+
git_config_clear();
547+
548+
the_repository = &r;
549+
r.commondir = commondir.buf;
550+
r.gitdir = gitdir.buf;
551+
552+
if (set_recommended_config(1) < 0)
553+
res = -1;
554+
}
555+
}
556+
557+
string_list_clear(&scalar_repos, 1);
558+
strbuf_release(&commondir);
559+
strbuf_release(&gitdir);
560+
561+
return res;
507562
}
508563

509564
static int cmd_run(int argc, const char **argv)

contrib/scalar/scalar.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ scalar list
1313
scalar register [<enlistment>]
1414
scalar unregister [<enlistment>]
1515
scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
16-
scalar reconfigure <enlistment>
16+
scalar reconfigure [ --all | <enlistment> ]
1717

1818
DESCRIPTION
1919
-----------
@@ -32,8 +32,8 @@ an existing Git worktree with Scalar whose name is not `src`, the enlistment
3232
will be identical to the worktree.
3333

3434
The `scalar` command implements various subcommands, and different options
35-
depending on the subcommand. With the exception of `clone` and `list`, all
36-
subcommands expect to be run in an enlistment.
35+
depending on the subcommand. With the exception of `clone`, `list` and
36+
`reconfigure --all`, all subcommands expect to be run in an enlistment.
3737

3838
COMMANDS
3939
--------
@@ -125,6 +125,9 @@ After a Scalar upgrade, or when the configuration of a Scalar enlistment
125125
was somehow corrupted or changed by mistake, this subcommand allows to
126126
reconfigure the enlistment.
127127

128+
With the `--all` option, all enlistments currently registered with Scalar
129+
will be reconfigured. Use this option after each Scalar upgrade.
130+
128131
SEE ALSO
129132
--------
130133
linkgit:git-clone[1], linkgit:git-maintenance[1].

contrib/scalar/t/t9099-scalar.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ test_expect_success 'scalar reconfigure' '
7070
scalar register one &&
7171
git -C one/src config core.preloadIndex false &&
7272
scalar reconfigure one &&
73+
test true = "$(git -C one/src config core.preloadIndex)" &&
74+
git -C one/src config core.preloadIndex false &&
75+
scalar reconfigure -a &&
7376
test true = "$(git -C one/src config core.preloadIndex)"
7477
'
7578

0 commit comments

Comments
 (0)