]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/worktree.c
Merge branch 'es/wt-add-detach'
[thirdparty/git.git] / builtin / worktree.c
index 1737165d2dc0e7fa45771f765bf518a208b6fd21..99abaeec6c6edcb5a16e0d5e7439981f81561319 100644 (file)
@@ -924,7 +924,6 @@ static int move_worktree(int ac, const char **av, const char *prefix)
 static void check_clean_worktree(struct worktree *wt,
                                 const char *original_path)
 {
-       struct strvec child_env = STRVEC_INIT;
        struct child_process cp;
        char buf[1];
        int ret;
@@ -935,15 +934,14 @@ static void check_clean_worktree(struct worktree *wt,
         */
        validate_no_submodules(wt);
 
-       strvec_pushf(&child_env, "%s=%s/.git",
+       child_process_init(&cp);
+       strvec_pushf(&cp.env_array, "%s=%s/.git",
                     GIT_DIR_ENVIRONMENT, wt->path);
-       strvec_pushf(&child_env, "%s=%s",
+       strvec_pushf(&cp.env_array, "%s=%s",
                     GIT_WORK_TREE_ENVIRONMENT, wt->path);
-       memset(&cp, 0, sizeof(cp));
        strvec_pushl(&cp.args, "status",
                     "--porcelain", "--ignore-submodules=none",
                     NULL);
-       cp.env = child_env.v;
        cp.git_cmd = 1;
        cp.dir = wt->path;
        cp.out = -1;
@@ -1030,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[] = {
@@ -1056,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);
 }