diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-09-09 13:53:07 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-09-09 13:53:07 -0700 |
commit | eb7460fd312511941d64007b5dfc4799a20a8d18 (patch) | |
tree | 53391a8da272c0fb179597bfb552b13c8afe753f /builtin/worktree.c | |
parent | Merge branch 'jk/worktree-check-clean-leakfix' (diff) | |
parent | init: make --separate-git-dir work from within linked worktree (diff) | |
download | tgif-eb7460fd312511941d64007b5dfc4799a20a8d18.tar.xz |
Merge branch 'es/worktree-repair'
"git worktree" gained a "repair" subcommand to help users recover
after moving the worktrees or repository manually without telling
Git. Also, "git init --separate-git-dir" no longer corrupts
administrative data related to linked worktrees.
* es/worktree-repair:
init: make --separate-git-dir work from within linked worktree
init: teach --separate-git-dir to repair linked worktrees
worktree: teach "repair" to fix outgoing links to worktrees
worktree: teach "repair" to fix worktree back-links to main worktree
worktree: add skeleton "repair" command
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r-- | builtin/worktree.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c index df214697d2..bb70fde97e 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -1028,6 +1028,34 @@ static int remove_worktree(int ac, const char **av, const char *prefix) return ret; } +static void report_repair(int iserr, const char *path, const char *msg, void *cb_data) +{ + if (!iserr) { + printf_ln(_("repair: %s: %s"), msg, path); + } else { + int *exit_status = (int *)cb_data; + fprintf_ln(stderr, _("error: %s: %s"), msg, path); + *exit_status = 1; + } +} + +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); + repair_worktrees(report_repair, &rc); + p = ac > 0 ? av : self; + for (; *p; p++) + repair_worktree_at_path(*p, report_repair, &rc); + return rc; +} + int cmd_worktree(int ac, const char **av, const char *prefix) { struct option options[] = { @@ -1054,5 +1082,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); } |