worktree: add relative cli/config options to repair command

This teaches the `worktree repair` command to respect the
`--[no-]relative-paths` CLI option and `worktree.useRelativePaths`
config setting. If an existing worktree with an absolute path is repaired
with `--relative-paths`, the links will be replaced with relative paths,
even if the original path was correct. This allows a user to covert
existing worktrees between absolute/relative as desired.

To simplify things, both linking files are written when one of the files
needs to be repaired. In some cases, this fixes the other file before it
is checked, in other cases this results in a correct file being written
with the same contents.

Signed-off-by: Caleb White <cdwhite3@pm.me>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Caleb White
2024-11-29 22:23:10 +00:00
committed by Junio C Hamano
parent 298d2917e2
commit e6df1ee2c1
5 changed files with 76 additions and 33 deletions

View File

@ -1385,6 +1385,8 @@ static int repair(int ac, const char **av, const char *prefix)
const char **p;
const char *self[] = { ".", NULL };
struct option options[] = {
OPT_BOOL(0, "relative-paths", &use_relative_paths,
N_("use relative paths for worktrees")),
OPT_END()
};
int rc = 0;
@ -1392,8 +1394,8 @@ static int repair(int ac, const char **av, const char *prefix)
ac = parse_options(ac, av, prefix, options, git_worktree_repair_usage, 0);
p = ac > 0 ? av : self;
for (; *p; p++)
repair_worktree_at_path(*p, report_repair, &rc);
repair_worktrees(report_repair, &rc);
repair_worktree_at_path(*p, report_repair, &rc, use_relative_paths);
repair_worktrees(report_repair, &rc, use_relative_paths);
return rc;
}