Skip to content

Commit e8e1ff2

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9b77c8 commit e8e1ff2

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Documentation/git-worktree.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SYNOPSIS
1515
'git worktree move' <worktree> <new-path>
1616
'git worktree prune' [-n] [-v] [--expire <expire>]
1717
'git worktree remove' [-f] <worktree>
18+
'git worktree repair'
1819
'git worktree unlock' <worktree>
1920

2021
DESCRIPTION
@@ -110,6 +111,11 @@ and no modification in tracked files) can be removed. Unclean working
110111
trees or ones with submodules can be removed with `--force`. The main
111112
working tree cannot be removed.
112113

114+
repair::
115+
116+
Repair working tree administrative files, if possible, if they have
117+
become corrupted or outdated due to external factors.
118+
113119
unlock::
114120

115121
Unlock a working tree, allowing it to be pruned, moved or deleted.

builtin/worktree.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,19 @@ static int remove_worktree(int ac, const char **av, const char *prefix)
10301030
return ret;
10311031
}
10321032

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+
10331046
int cmd_worktree(int ac, const char **av, const char *prefix)
10341047
{
10351048
struct option options[] = {
@@ -1056,5 +1069,7 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
10561069
return move_worktree(ac - 1, av + 1, prefix);
10571070
if (!strcmp(av[1], "remove"))
10581071
return remove_worktree(ac - 1, av + 1, prefix);
1072+
if (!strcmp(av[1], "repair"))
1073+
return repair(ac - 1, av + 1, prefix);
10591074
usage_with_options(worktree_usage, options);
10601075
}

t/t2406-worktree-repair.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)