diff options
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r-- | builtin/worktree.c | 110 |
1 files changed, 85 insertions, 25 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c index c6710b2552..4a24d53be1 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -15,15 +15,73 @@ #include "worktree.h" #include "quote.h" -static const char * const worktree_usage[] = { - N_("git worktree add [<options>] <path> [<commit-ish>]"), - N_("git worktree list [<options>]"), - N_("git worktree lock [<options>] <path>"), - N_("git worktree move <worktree> <new-path>"), - N_("git worktree prune [<options>]"), - N_("git worktree remove [<options>] <worktree>"), - N_("git worktree repair [<path>...]"), - N_("git worktree unlock <path>"), +#define BUILTIN_WORKTREE_ADD_USAGE \ + N_("git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]]\n" \ + " [-b <new-branch>] <path> [<commit-ish>]") +#define BUILTIN_WORKTREE_LIST_USAGE \ + N_("git worktree list [-v | --porcelain [-z]]") +#define BUILTIN_WORKTREE_LOCK_USAGE \ + N_("git worktree lock [--reason <string>] <worktree>") +#define BUILTIN_WORKTREE_MOVE_USAGE \ + N_("git worktree move <worktree> <new-path>") +#define BUILTIN_WORKTREE_PRUNE_USAGE \ + N_("git worktree prune [-n] [-v] [--expire <expire>]") +#define BUILTIN_WORKTREE_REMOVE_USAGE \ + N_("git worktree remove [-f] <worktree>") +#define BUILTIN_WORKTREE_REPAIR_USAGE \ + N_("git worktree repair [<path>...]") +#define BUILTIN_WORKTREE_UNLOCK_USAGE \ + N_("git worktree unlock <worktree>") + +static const char * const git_worktree_usage[] = { + BUILTIN_WORKTREE_ADD_USAGE, + BUILTIN_WORKTREE_LIST_USAGE, + BUILTIN_WORKTREE_LOCK_USAGE, + BUILTIN_WORKTREE_MOVE_USAGE, + BUILTIN_WORKTREE_PRUNE_USAGE, + BUILTIN_WORKTREE_REMOVE_USAGE, + BUILTIN_WORKTREE_REPAIR_USAGE, + BUILTIN_WORKTREE_UNLOCK_USAGE, + NULL +}; + +static const char * const git_worktree_add_usage[] = { + BUILTIN_WORKTREE_ADD_USAGE, + NULL, +}; + +static const char * const git_worktree_list_usage[] = { + BUILTIN_WORKTREE_LIST_USAGE, + NULL +}; + +static const char * const git_worktree_lock_usage[] = { + BUILTIN_WORKTREE_LOCK_USAGE, + NULL +}; + +static const char * const git_worktree_move_usage[] = { + BUILTIN_WORKTREE_MOVE_USAGE, + NULL +}; + +static const char * const git_worktree_prune_usage[] = { + BUILTIN_WORKTREE_PRUNE_USAGE, + NULL +}; + +static const char * const git_worktree_remove_usage[] = { + BUILTIN_WORKTREE_REMOVE_USAGE, + NULL +}; + +static const char * const git_worktree_repair_usage[] = { + BUILTIN_WORKTREE_REPAIR_USAGE, + NULL +}; + +static const char * const git_worktree_unlock_usage[] = { + BUILTIN_WORKTREE_UNLOCK_USAGE, NULL }; @@ -153,9 +211,10 @@ static int prune(int ac, const char **av, const char *prefix) }; expire = TIME_MAX; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_prune_usage, + 0); if (ac) - usage_with_options(worktree_usage, options); + usage_with_options(git_worktree_prune_usage, options); prune_worktrees(); return 0; } @@ -573,7 +632,7 @@ static int add(int ac, const char **av, const char *prefix) memset(&opts, 0, sizeof(opts)); opts.checkout = 1; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_add_usage, 0); if (!!opts.detach + !!new_branch + !!new_branch_force > 1) die(_("options '%s', '%s', and '%s' cannot be used together"), "-b", "-B", "--detach"); if (lock_reason && !keep_locked) @@ -584,7 +643,7 @@ static int add(int ac, const char **av, const char *prefix) opts.keep_locked = _("added with --lock"); if (ac < 1 || ac > 2) - usage_with_options(worktree_usage, options); + usage_with_options(git_worktree_add_usage, options); path = prefix_filename(prefix, av[0]); branch = ac < 2 ? "HEAD" : av[1]; @@ -772,9 +831,9 @@ static int list(int ac, const char **av, const char *prefix) }; expire = TIME_MAX; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_list_usage, 0); if (ac) - usage_with_options(worktree_usage, options); + usage_with_options(git_worktree_list_usage, options); else if (verbose && porcelain) die(_("options '%s' and '%s' cannot be used together"), "--verbose", "--porcelain"); else if (!line_terminator && !porcelain) @@ -811,9 +870,9 @@ static int lock_worktree(int ac, const char **av, const char *prefix) }; struct worktree **worktrees, *wt; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_lock_usage, 0); if (ac != 1) - usage_with_options(worktree_usage, options); + usage_with_options(git_worktree_lock_usage, options); worktrees = get_worktrees(); wt = find_worktree(worktrees, prefix, av[0]); @@ -844,9 +903,9 @@ static int unlock_worktree(int ac, const char **av, const char *prefix) struct worktree **worktrees, *wt; int ret; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_unlock_usage, 0); if (ac != 1) - usage_with_options(worktree_usage, options); + usage_with_options(git_worktree_unlock_usage, options); worktrees = get_worktrees(); wt = find_worktree(worktrees, prefix, av[0]); @@ -914,9 +973,10 @@ static int move_worktree(int ac, const char **av, const char *prefix) const char *reason = NULL; char *path; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_move_usage, + 0); if (ac != 2) - usage_with_options(worktree_usage, options); + usage_with_options(git_worktree_move_usage, options); path = prefix_filename(prefix, av[1]); strbuf_addstr(&dst, path); @@ -1042,9 +1102,9 @@ static int remove_worktree(int ac, const char **av, const char *prefix) const char *reason = NULL; int ret = 0; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_remove_usage, 0); if (ac != 1) - usage_with_options(worktree_usage, options); + usage_with_options(git_worktree_remove_usage, options); worktrees = get_worktrees(); wt = find_worktree(worktrees, prefix, av[0]); @@ -1102,7 +1162,7 @@ static int repair(int ac, const char **av, const char *prefix) }; int rc = 0; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_repair_usage, 0); p = ac > 0 ? av : self; for (; *p; p++) repair_worktree_at_path(*p, report_repair, &rc); @@ -1130,6 +1190,6 @@ int cmd_worktree(int ac, const char **av, const char *prefix) if (!prefix) prefix = ""; - ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + ac = parse_options(ac, av, prefix, options, git_worktree_usage, 0); return fn(ac, av, prefix); } |