scalar reconfigure: help users remove buggy repos
When running 'scalar reconfigure -a', 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Aug 28, 2023 at 13:52 UTC
f9a547d3a7a70db491f191dbc4f16c17e3308f78
1 file changed
+43
-16
scalar.c
+43
-16
@@ -662,6 +662,7 @@ static int cmd_reconfigure(int argc, const char **argv)
662
git_config(get_scalar_repos, &scalar_repos);
663
664
for (i = 0; i < scalar_repos.nr; i++) {
665
+ int succeeded = 0;
666
const char *dir = scalar_repos.items[i].string;
667
668
strbuf_reset(&commondir);
@@ -672,30 +673,56 @@ static int cmd_reconfigure(int argc, const char **argv)
673
674
if (errno != ENOENT) {
675
warning_errno(_("could not switch to '%s'"), dir);
675
- res = -1;
676
- continue;
676
+ goto loop_end;
677
}
678
679
strbuf_addstr(&buf, dir);
680
if (remove_deleted_enlistment(&buf))
681
- res = error(_("could not remove stale "
682
- "scalar.repo '%s'"), dir);
683
- else
684
- warning(_("removing stale scalar.repo '%s'"),
681
+ error(_("could not remove stale "
682
+ "scalar.repo '%s'"), dir);
683
+ else {
684
+ warning(_("removed stale scalar.repo '%s'"),
685
dir);
686
+ succeeded = 1;
687
+ }
688
strbuf_release(&buf);
687
- } else if (discover_git_directory(&commondir, &gitdir) < 0) {
688
- warning_errno(_("git repository gone in '%s'"), dir);
689
- res = -1;
690
- } else {
691
- git_config_clear();
689
+ goto loop_end;
690
+ }
691
+
692
+ switch (discover_git_directory_reason(&commondir, &gitdir)) {
693
+ case GIT_DIR_INVALID_OWNERSHIP:
694
+ warning(_("repository at '%s' has different owner"), dir);
695
+ goto loop_end;
696
+
697
+ case GIT_DIR_INVALID_GITFILE:
698
+ case GIT_DIR_INVALID_FORMAT:
699
+ warning(_("repository at '%s' has a format issue"), dir);
700
+ goto loop_end;
701
+
702
+ case GIT_DIR_DISCOVERED:
703
+ succeeded = 1;
704
+ break;
705
+
706
+ default:
707
+ warning(_("repository not found in '%s'"), dir);
708
+ break;
709
+ }
710
693
- the_repository = &r;
694
- r.commondir = commondir.buf;
695
- r.gitdir = gitdir.buf;
711
+ git_config_clear();
712
697
- if (set_recommended_config(1) < 0)
698
- res = -1;
713
+ the_repository = &r;
714
+ r.commondir = commondir.buf;
715
+ r.gitdir = gitdir.buf;
716
+
717
+ if (set_recommended_config(1) >= 0)
718
+ succeeded = 1;
719
+
720
+loop_end:
721
+ if (!succeeded) {
722
+ res = -1;
723
+ warning(_("to unregister this repository from Scalar, run\n"
724
+ "\tgit config --global --unset --fixed-value scalar.repo \"%s\""),
725
+ dir);
726
}
727
}
728