Merge branch 'jk/diff-submodule-diff-inline'
[gitweb.git] / builtin / worktree.c
index 48774211189b939591428e2d28d9e3d59ed3c1a5..6dcf7bd9d27004277fc568989d58a6236ed6867e 100644 (file)
@@ -112,7 +112,7 @@ static void prune_worktrees(void)
                if (ret < 0 && errno == ENOTDIR)
                        ret = unlink(path.buf);
                if (ret)
-                       error(_("failed to remove: %s"), strerror(errno));
+                       error_errno(_("failed to remove '%s'"), path.buf);
        }
        closedir(dir);
        if (!show_only)
@@ -194,7 +194,7 @@ static int add_worktree(const char *path, const char *refname,
        struct strbuf sb = STRBUF_INIT;
        const char *name;
        struct stat st;
-       struct child_process cp;
+       struct child_process cp = CHILD_PROCESS_INIT;
        struct argv_array child_env = ARGV_ARRAY_INIT;
        int counter = 0, len, ret;
        struct strbuf symref = STRBUF_INIT;
@@ -264,7 +264,7 @@ static int add_worktree(const char *path, const char *refname,
         */
        strbuf_reset(&sb);
        strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
-       write_file(sb.buf, sha1_to_hex(null_sha1));
+       write_file(sb.buf, "%s", sha1_to_hex(null_sha1));
        strbuf_reset(&sb);
        strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
        write_file(sb.buf, "../..");
@@ -273,7 +273,6 @@ static int add_worktree(const char *path, const char *refname,
 
        argv_array_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);
        argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
-       memset(&cp, 0, sizeof(cp));
        cp.git_cmd = 1;
 
        if (commit)
@@ -342,6 +341,9 @@ static int add(int ac, const char **av, const char *prefix)
        path = prefix_filename(prefix, strlen(prefix), av[0]);
        branch = ac < 2 ? "HEAD" : av[1];
 
+       if (!strcmp(branch, "-"))
+               branch = "@{-1}";
+
        opts.force_new_branch = !!new_branch_force;
        if (opts.force_new_branch) {
                struct strbuf symref = STRBUF_INIT;
@@ -362,8 +364,7 @@ static int add(int ac, const char **av, const char *prefix)
        }
 
        if (opts.new_branch) {
-               struct child_process cp;
-               memset(&cp, 0, sizeof(cp));
+               struct child_process cp = CHILD_PROCESS_INIT;
                cp.git_cmd = 1;
                argv_array_push(&cp.args, "branch");
                if (opts.force_new_branch)