summaryrefslogtreecommitdiff
path: root/builtin/worktree.c
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2020-08-31 06:57:58 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-31 18:47:45 (GMT)
commitb214ab5aa597e748c228e657d4eb7c18960e6a67 (patch)
tree3ddaf52516ed4595071c495d049c8ee5c6a192ea /builtin/worktree.c
parentbdd1f3e4da716012a52194cdfbc9c80dfdce87d4 (diff)
downloadgit-b214ab5aa597e748c228e657d4eb7c18960e6a67.zip
git-b214ab5aa597e748c228e657d4eb7c18960e6a67.tar.gz
git-b214ab5aa597e748c228e657d4eb7c18960e6a67.tar.bz2
worktree: teach "repair" to fix outgoing links to worktrees
The .git/worktrees/<id>/gitdir file points at the location of a linked worktree's .git file. Its content must be of the form /path/to/worktree/.git (from which the location of the worktree itself can be derived by stripping the "/.git" suffix). If the gitdir file is deleted or becomes corrupted or outdated, then Git will be unable to find the linked worktree. An easy way for the gitdir file to become outdated is for the user to move the worktree manually (without using "git worktree move"). Although it is possible to manually update the gitdir file to reflect the new linked worktree location, doing so requires a level of knowledge about worktree internals beyond what a user should be expected to know offhand. Therefore, teach "git worktree repair" how to repair broken or outdated .git/worktrees/<id>/gitdir files automatically. (For this to work, the command must either be invoked from within the worktree whose gitdir file requires repair, or from within the main or any linked worktree by providing the path of the broken worktree as an argument to "git worktree repair".) Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 68b0032..8165343 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1043,15 +1043,18 @@ static void report_repair(int iserr, const char *path, const char *msg, void *cb
static int repair(int ac, const char **av, const char *prefix)
{
+ const char **p;
+ const char *self[] = { ".", NULL };
struct option options[] = {
OPT_END()
};
int rc = 0;
ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
- if (ac)
- usage_with_options(worktree_usage, options);
repair_worktrees(report_repair, &rc);
+ p = ac > 0 ? av : self;
+ for (; *p; p++)
+ repair_worktree_at_path(*p, report_repair, &rc);
return rc;
}