Merge branch 'jc/worktree-add-short-help' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 22 Mar 2018 21:24:17 +0000 (14:24 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Mar 2018 21:24:17 +0000 (14:24 -0700)
Error message fix.

* jc/worktree-add-short-help:
worktree: say that "add" takes an arbitrary commit in short-help

1  2 
builtin/worktree.c
diff --combined builtin/worktree.c
index 7cef5b120b7786d107282d03052c5e06d3a2c85a,4666abd2cf35596370ca67bc06d0329215cdf66d..9efdc224661b02192d06c6877e49c5585ddbcdca
@@@ -14,7 -14,7 +14,7 @@@
  #include "worktree.h"
  
  static const char * const worktree_usage[] = {
-       N_("git worktree add [<options>] <path> [<branch>]"),
+       N_("git worktree add [<options>] <path> [<commit-ish>]"),
        N_("git worktree list [<options>]"),
        N_("git worktree lock [<options>] <path>"),
        N_("git worktree prune [<options>]"),
@@@ -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);
        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);