worktree: allow "-" short-hand for @{-1} in add command
Since `git worktree add` uses `git checkout` when `[<branch>]` is used, and `git checkout -` is already supported, it makes sense to allow the same shortcut in `git worktree add`. Signed-off-by: Jordan DE GEA <jordan.de-gea@grenoble-inp.org> Signed-off-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f3913c2d03
commit
1a450e2fd1
@ -340,6 +340,9 @@ static int add(int ac, const char **av, const char *prefix)
|
||||
path = prefix ? prefix_filename(prefix, strlen(prefix), av[0]) : 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;
|
||||
|
Reference in New Issue
Block a user