Skip to content

Commit 58d80df

Browse files
committed
Merge branch 'js/remove-stale-scalar-repos'
'scalar reconfigure -a' is taught to automatically remove scalar.repo entires which no longer exist. * js/remove-stale-scalar-repos: tests(scalar): tighten the stale `scalar.repo` test some scalar reconfigure -a: remove stale `scalar.repo` entries
2 parents e3d40fb + a90085b commit 58d80df

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

scalar.c

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,24 @@ static int get_scalar_repos(const char *key, const char *value, void *data)
596596
return 0;
597597
}
598598

599+
static int remove_deleted_enlistment(struct strbuf *path)
600+
{
601+
int res = 0;
602+
strbuf_realpath_forgiving(path, path->buf, 1);
603+
604+
if (run_git("config", "--global",
605+
"--unset", "--fixed-value",
606+
"scalar.repo", path->buf, NULL) < 0)
607+
res = -1;
608+
609+
if (run_git("config", "--global",
610+
"--unset", "--fixed-value",
611+
"maintenance.repo", path->buf, NULL) < 0)
612+
res = -1;
613+
614+
return res;
615+
}
616+
599617
static int cmd_reconfigure(int argc, const char **argv)
600618
{
601619
int all = 0;
@@ -635,8 +653,22 @@ static int cmd_reconfigure(int argc, const char **argv)
635653
strbuf_reset(&gitdir);
636654

637655
if (chdir(dir) < 0) {
638-
warning_errno(_("could not switch to '%s'"), dir);
639-
res = -1;
656+
struct strbuf buf = STRBUF_INIT;
657+
658+
if (errno != ENOENT) {
659+
warning_errno(_("could not switch to '%s'"), dir);
660+
res = -1;
661+
continue;
662+
}
663+
664+
strbuf_addstr(&buf, dir);
665+
if (remove_deleted_enlistment(&buf))
666+
res = error(_("could not remove stale "
667+
"scalar.repo '%s'"), dir);
668+
else
669+
warning(_("removing stale scalar.repo '%s'"),
670+
dir);
671+
strbuf_release(&buf);
640672
} else if (discover_git_directory(&commondir, &gitdir) < 0) {
641673
warning_errno(_("git repository gone in '%s'"), dir);
642674
res = -1;
@@ -722,24 +754,6 @@ static int cmd_run(int argc, const char **argv)
722754
return 0;
723755
}
724756

725-
static int remove_deleted_enlistment(struct strbuf *path)
726-
{
727-
int res = 0;
728-
strbuf_realpath_forgiving(path, path->buf, 1);
729-
730-
if (run_git("config", "--global",
731-
"--unset", "--fixed-value",
732-
"scalar.repo", path->buf, NULL) < 0)
733-
res = -1;
734-
735-
if (run_git("config", "--global",
736-
"--unset", "--fixed-value",
737-
"maintenance.repo", path->buf, NULL) < 0)
738-
res = -1;
739-
740-
return res;
741-
}
742-
743757
static int cmd_unregister(int argc, const char **argv)
744758
{
745759
struct option options[] = {

t/t9210-scalar.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ test_expect_success 'scalar reconfigure' '
166166
test true = "$(git -C one/src config core.preloadIndex)"
167167
'
168168

169+
test_expect_success '`reconfigure -a` removes stale config entries' '
170+
git init stale/src &&
171+
scalar register stale &&
172+
scalar list >scalar.repos &&
173+
grep stale scalar.repos &&
174+
175+
grep -v stale scalar.repos >expect &&
176+
177+
rm -rf stale &&
178+
scalar reconfigure -a &&
179+
scalar list >scalar.repos &&
180+
test_cmp expect scalar.repos
181+
'
182+
169183
test_expect_success 'scalar delete without enlistment shows a usage' '
170184
test_expect_code 129 scalar delete
171185
'

0 commit comments

Comments
 (0)