From 0db4961c49bb70cef89ed3d7c90f8f5d9dfc822d Mon Sep 17 00:00:00 2001 From: Stephen Manz Date: Thu, 15 Jul 2021 02:32:30 +0000 Subject: worktree: teach `add` to accept --reason with --lock The default reason stored in the lock file, "added with --lock", is unlikely to be what the user would have given in a separate `git worktree lock` command. Allowing `--reason` to be specified along with `--lock` when adding a working tree gives the user control over the reason for locking without needing a second command. Signed-off-by: Stephen Manz Reviewed-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/t2400-worktree-add.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 't') diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index 93d3795cab..37ad79470f 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -72,6 +72,20 @@ test_expect_success '"add" worktree with lock' ' test -f .git/worktrees/here-with-lock/locked ' +test_expect_success '"add" worktree with lock and reason' ' + lock_reason="why not" && + git worktree add --detach --lock --reason "$lock_reason" here-with-lock-reason main && + test_when_finished "git worktree unlock here-with-lock-reason || :" && + test -f .git/worktrees/here-with-lock-reason/locked && + echo "$lock_reason" >expect && + test_cmp expect .git/worktrees/here-with-lock-reason/locked +' + +test_expect_success '"add" worktree with reason but no lock' ' + test_must_fail git worktree add --detach --reason "why not" here-with-reason-only main && + test_path_is_missing .git/worktrees/here-with-reason-only/locked +' + test_expect_success '"add" worktree from a subdir' ' ( mkdir sub && -- cgit v1.3