Merge branch 'ab/pcre-v2'
[gitweb.git] / t / helper / test-ref-store.c
index 9077ec2c330e216ee23f84de77e03008a8d874db..05d8c4d8af093ad42d855b17d243fe07b8893bfb 100644 (file)
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "worktree.h"
 
 static const char *notnull(const char *arg, const char *name)
 {
@@ -32,6 +33,23 @@ static const char **get_store(const char **argv, struct ref_store **refs)
                strbuf_release(&sb);
 
                *refs = get_submodule_ref_store(gitdir);
+       } else if (skip_prefix(argv[0], "worktree:", &gitdir)) {
+               struct worktree **p, **worktrees = get_worktrees(0);
+
+               for (p = worktrees; *p; p++) {
+                       struct worktree *wt = *p;
+
+                       if (!wt->id) {
+                               /* special case for main worktree */
+                               if (!strcmp(gitdir, "main"))
+                                       break;
+                       } else if (!strcmp(gitdir, wt->id))
+                               break;
+               }
+               if (!*p)
+                       die("no such worktree: %s", gitdir);
+
+               *refs = get_worktree_ref_store(*p);
        } else
                die("unknown backend %s", argv[0]);
 
@@ -75,12 +93,13 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
 static int cmd_delete_refs(struct ref_store *refs, const char **argv)
 {
        unsigned int flags = arg_flags(*argv++, "flags");
+       const char *msg = *argv++;
        struct string_list refnames = STRING_LIST_INIT_NODUP;
 
        while (*argv)
                string_list_append(&refnames, *argv++);
 
-       return refs_delete_refs(refs, &refnames, flags);
+       return refs_delete_refs(refs, msg, &refnames, flags);
 }
 
 static int cmd_rename_ref(struct ref_store *refs, const char **argv)