diff options
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r-- | builtin/worktree.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c index 3b9220f7a6..4877421118 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -16,6 +16,7 @@ static const char * const worktree_usage[] = { N_("git worktree list [<options>]"), N_("git worktree lock [<options>] <path>"), N_("git worktree prune [<options>]"), + N_("git worktree unlock <path>"), NULL }; @@ -495,6 +496,31 @@ static int lock_worktree(int ac, const char **av, const char *prefix) return 0; } +static int unlock_worktree(int ac, const char **av, const char *prefix) +{ + struct option options[] = { + OPT_END() + }; + struct worktree **worktrees, *wt; + int ret; + + ac = parse_options(ac, av, prefix, options, worktree_usage, 0); + if (ac != 1) + usage_with_options(worktree_usage, options); + + worktrees = get_worktrees(); + wt = find_worktree(worktrees, prefix, av[0]); + if (!wt) + die(_("'%s' is not a working tree"), av[0]); + if (is_main_worktree(wt)) + die(_("The main working tree cannot be locked or unlocked")); + if (!is_worktree_locked(wt)) + die(_("'%s' is not locked"), av[0]); + ret = unlink_or_warn(git_common_path("worktrees/%s/locked", wt->id)); + free_worktrees(worktrees); + return ret; +} + int cmd_worktree(int ac, const char **av, const char *prefix) { struct option options[] = { @@ -513,5 +539,7 @@ int cmd_worktree(int ac, const char **av, const char *prefix) return list(ac - 1, av + 1, prefix); if (!strcmp(av[1], "lock")) return lock_worktree(ac - 1, av + 1, prefix); + if (!strcmp(av[1], "unlock")) + return unlock_worktree(ac - 1, av + 1, prefix); usage_with_options(worktree_usage, options); } |