worktree: simplify prefixing paths
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sun, 22 May 2016 09:33:56 +0000 (16:33 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 24 May 2016 20:19:23 +0000 (13:19 -0700)
This also makes slash conversion always happen on Windows (a side effect
of prefix_filename). Which is a good thing.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/worktree.c
index b53f8024fc60ec8096c7cd6ab3423a15b2915f69..f9dac376f748480c72023e9f4375edc90069a2ce 100644 (file)
@@ -337,7 +337,7 @@ static int add(int ac, const char **av, const char *prefix)
        if (ac < 1 || ac > 2)
                usage_with_options(worktree_usage, options);
 
-       path = prefix ? prefix_filename(prefix, strlen(prefix), av[0]) : av[0];
+       path = prefix_filename(prefix, strlen(prefix), av[0]);
        branch = ac < 2 ? "HEAD" : av[1];
 
        opts.force_new_branch = !!new_branch_force;
@@ -467,6 +467,8 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
 
        if (ac < 2)
                usage_with_options(worktree_usage, options);
+       if (!prefix)
+               prefix = "";
        if (!strcmp(av[1], "add"))
                return add(ac - 1, av + 1, prefix);
        if (!strcmp(av[1], "prune"))