All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Stephen Manz via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	Stephen Manz <smanz@alum.mit.edu>
Subject: [PATCH v2 0/3] worktree: teach add to accept --reason with --lock
Date: Thu, 08 Jul 2021 15:50:40 +0000	[thread overview]
Message-ID: <pull.992.v2.git.1625759443.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.992.git.1625550451038.gitgitgadget@gmail.com>

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.

Changes since v1:

 * Split changes into 3 commits. The first commit is removal of git
   rev-parse in the test above the ones I'm adding. The second is wrapping
   the "added with --lock" string with _() to mark it for translation. The
   third commit is the main change.
 * Reworked the if-else-if-else to if-else if-else
 * Added test_when_finished ... command to unlock the working tree
 * Changed test_expect_failure to test_expect_success and embedded
   test_must_fail and test_path_is_missing commands

Note: I don't see how to disambiguate --lock with no --reason from no --lock
at all. I still think that the original keep_locked boolean is needed along
with the new lock_reason char array. If I don't add lock_reason and change
keep_locked to a char array, it will start as NULL. But it will remain NULL
if --lock alone is given or if --lock isn't given at all.

Stephen Manz (3):
  t2400: remove unneeded `git rev-parse` from '"add" worktree with lock'
    test
  worktree: default lock string should be marked with `_()` for
    translation
  worktree: teach `add` to accept --reason <string> with --lock

 Documentation/git-worktree.txt |  4 ++--
 builtin/worktree.c             |  9 ++++++++-
 t/t2400-worktree-add.sh        | 14 +++++++++++++-
 3 files changed, 23 insertions(+), 4 deletions(-)


base-commit: 670b81a890388c60b7032a4f5b879f2ece8c4558
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-992%2FSRManz%2Flock_reason-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-992/SRManz/lock_reason-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/992

Range-diff vs v1:

 -:  ----------- > 1:  5459e5bb421 t2400: remove unneeded `git rev-parse` from '"add" worktree with lock' test
 -:  ----------- > 2:  30196cc9369 worktree: default lock string should be marked with `_()` for translation
 1:  233a580b212 ! 3:  4d17b31921a worktree: teach `add` to accept --reason <string> with --lock
     @@ builtin/worktree.c: struct add_opts {
       
       static int show_only;
      @@ builtin/worktree.c: static int add_worktree(const char *path, const char *refname,
     - 	 * after the preparation is over.
     - 	 */
       	strbuf_addf(&sb, "%s/locked", sb_repo.buf);
     --	if (!opts->keep_locked)
     -+	if (!opts->keep_locked) {
     + 	if (!opts->keep_locked)
       		write_file(sb.buf, "initializing");
     --	else
     --		write_file(sb.buf, "added with --lock");
     -+	}
     -+	else {
     -+		if (opts->lock_reason)
     -+			write_file(sb.buf, "%s", opts->lock_reason);
     -+		else
     -+			write_file(sb.buf, _("added with --lock"));
     -+	}
     ++	else if (opts->lock_reason)
     ++		write_file(sb.buf, "%s", opts->lock_reason);
     + 	else
     + 		write_file(sb.buf, _("added with --lock"));
       
     - 	strbuf_addf(&sb_git, "%s/.git", path);
     - 	if (safe_create_leading_directories_const(sb_git.buf))
      @@ builtin/worktree.c: static int add(int ac, const char **av, const char *prefix)
       		OPT_BOOL('d', "detach", &opts.detach, N_("detach HEAD at named commit")),
       		OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
     @@ builtin/worktree.c: static int add(int ac, const char **av, const char *prefix)
       
      
       ## t/t2400-worktree-add.sh ##
     -@@ t/t2400-worktree-add.sh: test_expect_success '"add" worktree' '
     - '
     - 
     - test_expect_success '"add" worktree with lock' '
     --	git rev-parse HEAD >expect &&
     - 	git worktree add --detach --lock here-with-lock main &&
     +@@ t/t2400-worktree-add.sh: test_expect_success '"add" worktree with lock' '
       	test -f .git/worktrees/here-with-lock/locked
       '
       
      +test_expect_success '"add" worktree with lock and reason' '
      +	git worktree add --detach --lock --reason "why not" 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 why not >expect &&
      +	test_cmp expect .git/worktrees/here-with-lock-reason/locked
      +'
      +
     -+test_expect_failure '"add" worktree with reason but no lock' '
     -+	git worktree add --detach --reason "why not" here-with-reason-only main &&
     -+	test -f .git/worktrees/here-with-reason-only/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' '

-- 
gitgitgadget

  parent reply	other threads:[~2021-07-08 15:50 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-06  5:47 [PATCH] worktree: teach `add` to accept --reason <string> with --lock Stephen Manz via GitGitGadget
2021-07-06  6:19 ` Eric Sunshine
2021-07-06 19:42   ` Junio C Hamano
2021-07-09  6:11     ` Eric Sunshine
2021-07-09 15:23       ` Junio C Hamano
2021-07-10  7:11         ` Eric Sunshine
2021-07-08 15:50 ` Stephen Manz via GitGitGadget [this message]
2021-07-08 15:50   ` [PATCH v2 1/3] t2400: remove unneeded `git rev-parse` from '"add" worktree with lock' test Stephen Manz via GitGitGadget
2021-07-08 15:50   ` [PATCH v2 2/3] worktree: default lock string should be marked with `_()` for translation Stephen Manz via GitGitGadget
2021-07-09  6:19     ` Eric Sunshine
2021-07-09 15:58       ` Junio C Hamano
2021-07-08 15:50   ` [PATCH v2 3/3] worktree: teach `add` to accept --reason <string> with --lock Stephen Manz via GitGitGadget
2021-07-09  7:45   ` [PATCH v2 0/3] worktree: teach add to accept --reason " Eric Sunshine
2021-07-09 16:03     ` Junio C Hamano
2021-07-10  7:15       ` Eric Sunshine
2021-07-11  0:27   ` [PATCH v3 " Stephen Manz via GitGitGadget
2021-07-11  0:27     ` [PATCH v3 1/3] t2400: clean up '"add" worktree with lock' test Stephen Manz via GitGitGadget
2021-07-11  0:27     ` [PATCH v3 2/3] worktree: mark lock strings with `_()` for translation Stephen Manz via GitGitGadget
2021-07-11  0:27     ` [PATCH v3 3/3] worktree: teach `add` to accept --reason <string> with --lock Stephen Manz via GitGitGadget
2021-07-13  3:37       ` Eric Sunshine
2021-07-13  3:47     ` [PATCH v3 0/3] worktree: teach add to accept --reason " Eric Sunshine
2021-07-15  2:32     ` [PATCH v4 " Stephen Manz via GitGitGadget
2021-07-15  2:32       ` [PATCH v4 1/3] t2400: clean up '"add" worktree with lock' test Stephen Manz via GitGitGadget
2021-07-15  2:32       ` [PATCH v4 2/3] worktree: mark lock strings with `_()` for translation Stephen Manz via GitGitGadget
2021-07-15  2:32       ` [PATCH v4 3/3] worktree: teach `add` to accept --reason <string> with --lock Stephen Manz via GitGitGadget
2021-07-15 17:17       ` [PATCH v4 0/3] worktree: teach add to accept --reason " Eric Sunshine
2021-07-17  0:14         ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.992.v2.git.1625759443.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=smanz@alum.mit.edu \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.