t4201: make use of abbreviation in the test more robust
[gitweb.git] / builtin / worktree.c
index 5c4854d3e4a679f59f4a7db7cb3f37bd0e210622..831fe058a53da95643b1a93038f576d5bffea7ef 100644 (file)
@@ -125,9 +125,9 @@ static int prune(int ac, const char **av, const char *prefix)
 {
        struct option options[] = {
                OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
-               OPT__VERBOSE(&verbose, N_("report pruned objects")),
+               OPT__VERBOSE(&verbose, N_("report pruned working trees")),
                OPT_EXPIRY_DATE(0, "expire", &expire,
-                               N_("expire objects older than <time>")),
+                               N_("expire working trees older than <time>")),
                OPT_END()
        };
 
@@ -388,7 +388,7 @@ static void show_worktree_porcelain(struct worktree *wt)
                printf("HEAD %s\n", sha1_to_hex(wt->head_sha1));
                if (wt->is_detached)
                        printf("detached\n");
-               else
+               else if (wt->head_ref)
                        printf("branch %s\n", wt->head_ref);
        }
        printf("\n");
@@ -406,10 +406,12 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
        else {
                strbuf_addf(&sb, "%-*s ", abbrev_len,
                                find_unique_abbrev(wt->head_sha1, DEFAULT_ABBREV));
-               if (!wt->is_detached)
+               if (wt->is_detached)
+                       strbuf_addstr(&sb, "(detached HEAD)");
+               else if (wt->head_ref)
                        strbuf_addf(&sb, "[%s]", shorten_unambiguous_ref(wt->head_ref, 0));
                else
-                       strbuf_addstr(&sb, "(detached HEAD)");
+                       strbuf_addstr(&sb, "(error)");
        }
        printf("%s\n", sb.buf);
 
@@ -445,7 +447,7 @@ static int list(int ac, const char **av, const char *prefix)
        if (ac)
                usage_with_options(worktree_usage, options);
        else {
-               struct worktree **worktrees = get_worktrees();
+               struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);
                int path_maxlen = 0, abbrev = DEFAULT_ABBREV, i;
 
                if (!porcelain)
@@ -476,7 +478,7 @@ static int lock_worktree(int ac, const char **av, const char *prefix)
        if (ac != 1)
                usage_with_options(worktree_usage, options);
 
-       worktrees = get_worktrees();
+       worktrees = get_worktrees(0);
        wt = find_worktree(worktrees, prefix, av[0]);
        if (!wt)
                die(_("'%s' is not a working tree"), av[0]);
@@ -509,7 +511,7 @@ static int unlock_worktree(int ac, const char **av, const char *prefix)
        if (ac != 1)
                usage_with_options(worktree_usage, options);
 
-       worktrees = get_worktrees();
+       worktrees = get_worktrees(0);
        wt = find_worktree(worktrees, prefix, av[0]);
        if (!wt)
                die(_("'%s' is not a working tree"), av[0]);