]> git.ipfire.org Git - thirdparty/git.git/commitdiff
worktree: add skeleton "repair" command
authorEric Sunshine <sunshine@sunshineco.com>
Thu, 27 Aug 2020 08:21:25 +0000 (04:21 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 27 Aug 2020 15:59:13 +0000 (08:59 -0700)
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>
Documentation/git-worktree.txt
builtin/worktree.c
t/t2406-worktree-repair.sh [new file with mode: 0755]

index 6ee6ec79824a6a8e43d2411b9226c72a49d52c9e..ae432d39a865b370797645c29a48155fee01d053 100644 (file)
@@ -15,6 +15,7 @@ SYNOPSIS
 'git worktree move' <worktree> <new-path>
 'git worktree prune' [-n] [-v] [--expire <expire>]
 'git worktree remove' [-f] <worktree>
+'git worktree repair'
 'git worktree unlock' <worktree>
 
 DESCRIPTION
@@ -110,6 +111,11 @@ and no modification in tracked files) can be removed. Unclean working
 trees or ones with submodules can be removed with `--force`. The main
 working tree cannot be removed.
 
+repair::
+
+Repair working tree administrative files, if possible, if they have
+become corrupted or outdated due to external factors.
+
 unlock::
 
 Unlock a working tree, allowing it to be pruned, moved or deleted.
index 378f332b5d07edb55b48559ba328f980b84927e6..88af412d4f7186a0c22e3f6f36ea8523adfd816f 100644 (file)
@@ -1030,6 +1030,19 @@ static int remove_worktree(int ac, const char **av, const char *prefix)
        return ret;
 }
 
+static int repair(int ac, const char **av, const char *prefix)
+{
+       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);
+       return rc;
+}
+
 int cmd_worktree(int ac, const char **av, const char *prefix)
 {
        struct option options[] = {
@@ -1056,5 +1069,7 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
                return move_worktree(ac - 1, av + 1, prefix);
        if (!strcmp(av[1], "remove"))
                return remove_worktree(ac - 1, av + 1, prefix);
+       if (!strcmp(av[1], "repair"))
+               return repair(ac - 1, av + 1, prefix);
        usage_with_options(worktree_usage, options);
 }
diff --git a/t/t2406-worktree-repair.sh b/t/t2406-worktree-repair.sh
new file mode 100755 (executable)
index 0000000..cc679e1
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+test_description='test git worktree repair'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+       test_commit init
+'
+
+test_done