From: Junio C Hamano Date: Thu, 22 Mar 2018 21:24:17 +0000 (-0700) Subject: Merge branch 'jc/worktree-add-short-help' into maint X-Git-Tag: v2.16.3~15 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e55521be8d2606b4b513d25459d8b97a0ff8a50e?ds=inline;hp=-c Merge branch 'jc/worktree-add-short-help' into maint Error message fix. * jc/worktree-add-short-help: worktree: say that "add" takes an arbitrary commit in short-help --- e55521be8d2606b4b513d25459d8b97a0ff8a50e diff --combined builtin/worktree.c index 7cef5b120b,4666abd2cf..9efdc22466 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@@ -14,7 -14,7 +14,7 @@@ #include "worktree.h" static const char * const worktree_usage[] = { - N_("git worktree add [] []"), + N_("git worktree add [] []"), N_("git worktree list []"), N_("git worktree lock [] "), N_("git worktree prune []"), @@@ -230,21 -230,20 +230,21 @@@ static int add_worktree(const char *pat int counter = 0, len, ret; struct strbuf symref = STRBUF_INIT; struct commit *commit = NULL; + int is_branch = 0; if (file_exists(path) && !is_empty_dir(path)) die(_("'%s' already exists"), path); /* is 'refname' a branch or commit? */ if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) && - ref_exists(symref.buf)) { /* it's a branch */ + ref_exists(symref.buf)) { + is_branch = 1; if (!opts->force) die_if_checked_out(symref.buf, 0); - } else { /* must be a commit */ - commit = lookup_commit_reference_by_name(refname); - if (!commit) - die(_("invalid reference: %s"), refname); } + commit = lookup_commit_reference_by_name(refname); + if (!commit) + die(_("invalid reference: %s"), refname); name = worktree_basename(path, &len); git_path_buf(&sb_repo, "worktrees/%.*s", (int)(path + len - name), name); @@@ -309,7 -308,7 +309,7 @@@ argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path); cp.git_cmd = 1; - if (commit) + if (!is_branch) argv_array_pushl(&cp.args, "update-ref", "HEAD", oid_to_hex(&commit->object.oid), NULL); else @@@ -340,15 -339,6 +340,15 @@@ done strbuf_addf(&sb, "%s/locked", sb_repo.buf); unlink_or_warn(sb.buf); } + + /* + * Hook failure does not warrant worktree deletion, so run hook after + * is_junk is cleared, but do return appropriate code when hook fails. + */ + if (!ret && opts->checkout) + ret = run_hook_le(NULL, "post-checkout", oid_to_hex(&null_oid), + oid_to_hex(&commit->object.oid), "1", NULL); + argv_array_clear(&child_env); strbuf_release(&sb); strbuf_release(&symref);