@@ -16,6 +16,7 @@ static const char * const worktree_usage[] = {
1616 N_ ("git worktree list [<options>]" ),
1717 N_ ("git worktree lock [<options>] <path>" ),
1818 N_ ("git worktree prune [<options>]" ),
19+ N_ ("git worktree unlock <path>" ),
1920 NULL
2021};
2122
@@ -495,6 +496,31 @@ static int lock_worktree(int ac, const char **av, const char *prefix)
495496 return 0 ;
496497}
497498
499+ static int unlock_worktree (int ac , const char * * av , const char * prefix )
500+ {
501+ struct option options [] = {
502+ OPT_END ()
503+ };
504+ struct worktree * * worktrees , * wt ;
505+ int ret ;
506+
507+ ac = parse_options (ac , av , prefix , options , worktree_usage , 0 );
508+ if (ac != 1 )
509+ usage_with_options (worktree_usage , options );
510+
511+ worktrees = get_worktrees ();
512+ wt = find_worktree (worktrees , prefix , av [0 ]);
513+ if (!wt )
514+ die (_ ("'%s' is not a working tree" ), av [0 ]);
515+ if (is_main_worktree (wt ))
516+ die (_ ("The main working tree cannot be locked or unlocked" ));
517+ if (!is_worktree_locked (wt ))
518+ die (_ ("'%s' is not locked" ), av [0 ]);
519+ ret = unlink_or_warn (git_common_path ("worktrees/%s/locked" , wt -> id ));
520+ free_worktrees (worktrees );
521+ return ret ;
522+ }
523+
498524int cmd_worktree (int ac , const char * * av , const char * prefix )
499525{
500526 struct option options [] = {
@@ -513,5 +539,7 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
513539 return list (ac - 1 , av + 1 , prefix );
514540 if (!strcmp (av [1 ], "lock" ))
515541 return lock_worktree (ac - 1 , av + 1 , prefix );
542+ if (!strcmp (av [1 ], "unlock" ))
543+ return unlock_worktree (ac - 1 , av + 1 , prefix );
516544 usage_with_options (worktree_usage , options );
517545}
0 commit comments