@@ -30,7 +30,7 @@ struct add_opts {
30
30
int detach ;
31
31
int quiet ;
32
32
int checkout ;
33
- int keep_locked ;
33
+ const char * keep_locked ;
34
34
};
35
35
36
36
static int show_only ;
@@ -302,10 +302,10 @@ static int add_worktree(const char *path, const char *refname,
302
302
* after the preparation is over.
303
303
*/
304
304
strbuf_addf (& sb , "%s/locked" , sb_repo .buf );
305
- if (! opts -> keep_locked )
306
- write_file (sb .buf , "initializing" );
305
+ if (opts -> keep_locked )
306
+ write_file (sb .buf , "%s" , opts -> keep_locked );
307
307
else
308
- write_file (sb .buf , "added with --lock" );
308
+ write_file (sb .buf , _ ( "initializing" ) );
309
309
310
310
strbuf_addf (& sb_git , "%s/.git" , path );
311
311
if (safe_create_leading_directories_const (sb_git .buf ))
@@ -475,6 +475,8 @@ static int add(int ac, const char **av, const char *prefix)
475
475
const char * branch ;
476
476
const char * new_branch = NULL ;
477
477
const char * opt_track = NULL ;
478
+ const char * lock_reason = NULL ;
479
+ int keep_locked = 0 ;
478
480
struct option options [] = {
479
481
OPT__FORCE (& opts .force ,
480
482
N_ ("checkout <branch> even if already checked out in other worktree" ),
@@ -485,7 +487,9 @@ static int add(int ac, const char **av, const char *prefix)
485
487
N_ ("create or reset a branch" )),
486
488
OPT_BOOL ('d' , "detach" , & opts .detach , N_ ("detach HEAD at named commit" )),
487
489
OPT_BOOL (0 , "checkout" , & opts .checkout , N_ ("populate the new working tree" )),
488
- OPT_BOOL (0 , "lock" , & opts .keep_locked , N_ ("keep the new working tree locked" )),
490
+ OPT_BOOL (0 , "lock" , & keep_locked , N_ ("keep the new working tree locked" )),
491
+ OPT_STRING (0 , "reason" , & lock_reason , N_ ("string" ),
492
+ N_ ("reason for locking" )),
489
493
OPT__QUIET (& opts .quiet , N_ ("suppress progress reporting" )),
490
494
OPT_PASSTHRU (0 , "track" , & opt_track , NULL ,
491
495
N_ ("set up tracking mode (see git-branch(1))" ),
@@ -500,6 +504,13 @@ static int add(int ac, const char **av, const char *prefix)
500
504
ac = parse_options (ac , av , prefix , options , worktree_usage , 0 );
501
505
if (!!opts .detach + !!new_branch + !!new_branch_force > 1 )
502
506
die (_ ("-b, -B, and --detach are mutually exclusive" ));
507
+ if (lock_reason && !keep_locked )
508
+ die (_ ("--reason requires --lock" ));
509
+ if (lock_reason )
510
+ opts .keep_locked = lock_reason ;
511
+ else if (keep_locked )
512
+ opts .keep_locked = _ ("added with --lock" );
513
+
503
514
if (ac < 1 || ac > 2 )
504
515
usage_with_options (worktree_usage , options );
505
516
0 commit comments