@matheusbsbs / matheus-bagliano / commits / e8e1ff24c5
Fork 0

worktree: add skeleton "repair" command

Worktree administrative files can become corrupted or outdated due to external factors. Although, it is often possible to recover from such situations by hand-tweaking these files, doing so requires intimate knowledge of worktree internals. While information necessary to make such repairs manually can be obtained from git-worktree.txt and gitrepository-layout.txt, we can assist users more directly by teaching git-worktree how to repair its administrative files itself (at least to some extent). Therefore, add a "git worktree repair" command which attempts to correct common problems which may arise due to factors beyond Git's control. At this stage, the "repair" command is a mere skeleton; subsequent commits will flesh out the functionality. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Aug 27, 2020 at 04:21 UTC e8e1ff24c5cf885c8d0ac208b58ccaf3760e8bfa
3 files changed +32
Documentation/git-worktree.txt
+6
@@ -15,6 +15,7 @@ SYNOPSIS
15 'git worktree move' <worktree> <new-path>
16 'git worktree prune' [-n] [-v] [--expire <expire>]
17 'git worktree remove' [-f] <worktree>
18 +'git worktree repair'
19 'git worktree unlock' <worktree>
20
21 DESCRIPTION
@@ -110,6 +111,11 @@ and no modification in tracked files) can be removed. Unclean working
111 trees or ones with submodules can be removed with `--force`. The main
112 working tree cannot be removed.
113
114 +repair::
115 +
116 +Repair working tree administrative files, if possible, if they have
117 +become corrupted or outdated due to external factors.
118 +
119 unlock::
120
121 Unlock a working tree, allowing it to be pruned, moved or deleted.
builtin/worktree.c
+15
@@ -1030,6 +1030,19 @@ static int remove_worktree(int ac, const char **av, const char *prefix)
1030 return ret;
1031 }
1032
1033 +static int repair(int ac, const char **av, const char *prefix)
1034 +{
1035 + struct option options[] = {
1036 + OPT_END()
1037 + };
1038 + int rc = 0;
1039 +
1040 + ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
1041 + if (ac)
1042 + usage_with_options(worktree_usage, options);
1043 + return rc;
1044 +}
1045 +
1046 int cmd_worktree(int ac, const char **av, const char *prefix)
1047 {
1048 struct option options[] = {
@@ -1056,5 +1069,7 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
1069 return move_worktree(ac - 1, av + 1, prefix);
1070 if (!strcmp(av[1], "remove"))
1071 return remove_worktree(ac - 1, av + 1, prefix);
1072 + if (!strcmp(av[1], "repair"))
1073 + return repair(ac - 1, av + 1, prefix);
1074 usage_with_options(worktree_usage, options);
1075 }
t/t2406-worktree-repair.sh new
+11
@@ -0,0 +1,11 @@
1 +#!/bin/sh
2 +
3 +test_description='test git worktree repair'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 + test_commit init
9 +'
10 +
11 +test_done