Skip to content

Commit db8dd2d

Browse files
derrickstoleedscho
authored andcommitted
scalar reconfigure: help users remove buggy repos
When running 'scalar reconfigure -a', such as at install time, Scalar has warning messages about the repository missing (or not containing a .git directory). Failures can also happen while trying to modify the repository-local config for that repository. These warnings may seem confusing to users who don't understand what they mean or how to stop them. Add a warning that instructs the user how to remove the warning in future installations. Signed-off-by: Derrick Stolee <derrickstolee@github.com>
1 parent 1756efd commit db8dd2d

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

scalar.c

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -992,26 +992,48 @@ static int cmd_reconfigure(int argc, const char **argv)
992992
git_config(get_scalar_repos, &scalar_repos);
993993

994994
for (i = 0; i < scalar_repos.nr; i++) {
995+
int failed = 0;
995996
const char *dir = scalar_repos.items[i].string;
996997

997998
strbuf_reset(&commondir);
998999
strbuf_reset(&gitdir);
9991000

10001001
if (chdir(dir) < 0) {
10011002
warning_errno(_("could not switch to '%s'"), dir);
1002-
res = -1;
1003-
} else if (discover_git_directory(&commondir, &gitdir) < 0) {
1004-
warning_errno(_("git repository gone in '%s'"), dir);
1005-
res = -1;
1006-
} else {
1007-
git_config_clear();
1008-
1009-
the_repository = &r;
1010-
r.commondir = commondir.buf;
1011-
r.gitdir = gitdir.buf;
1012-
1013-
if (set_recommended_config(1) < 0)
1014-
res = -1;
1003+
failed = -1;
1004+
goto loop_end;
1005+
}
1006+
1007+
switch (discover_git_directory_reason(&commondir, &gitdir)) {
1008+
case GIT_DIR_INVALID_OWNERSHIP:
1009+
warning(_("repository at '%s' has different owner"), dir);
1010+
failed = -1;
1011+
goto loop_end;
1012+
1013+
case GIT_DIR_DISCOVERED:
1014+
break;
1015+
1016+
default:
1017+
warning(_("repository not found in '%s'"), dir);
1018+
failed = -1;
1019+
break;
1020+
}
1021+
1022+
git_config_clear();
1023+
1024+
the_repository = &r;
1025+
r.commondir = commondir.buf;
1026+
r.gitdir = gitdir.buf;
1027+
1028+
if (set_recommended_config(1) < 0)
1029+
failed = -1;
1030+
1031+
loop_end:
1032+
if (failed) {
1033+
res = failed;
1034+
warning(_("to unregister this repository from Scalar, run\n"
1035+
"\tgit config --global --unset --fixed-value scalar.repo \"%s\""),
1036+
dir);
10151037
}
10161038
}
10171039

0 commit comments

Comments
 (0)