git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v3 00/22] rid git-checkout of too-intimate knowledge of new worktree
@ 2015-07-17 22:59 Eric Sunshine
  2015-07-17 22:59 ` [PATCH v3 01/22] checkout: avoid resolving HEAD unnecessarily Eric Sunshine
                   ` (21 more replies)
  0 siblings, 22 replies; 24+ messages in thread
From: Eric Sunshine @ 2015-07-17 22:59 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Duy Nguyen, Michael J Gruber, Eric Sunshine

This is v3 of [1] which rids git-checkout of specialized knowledge that
it's operating in a newly created linked worktree. Thanks to Junio for
his review, and Duy and Michael J Gruber for additional observations.

A v2 to v3 interdiff is included below.

Changes since v2:

* patch 06/22: strip only trailing ".git" rather than "/.git" from
  "'branch' is already checked out at '/some/patch/.git'" message[2];
  also reword commit message slightly to better emphasize that the
  trailing ".git" is more than a mere cosmetic issue[2]

* patch 10/22 (new): change worktree setup message from "Enter
  <path>..." to "Preparing <path>..." to avoid possibly confusing the
  user into thinking that 'cd <path>' occurred[3]

* patch 13/22: add tests of -b/-B/--detach exclusivity

* patch 14/22 (new): suppress accidental triggering of branch
  auto-vivication with "git worktree add --detach <path>"; instead treat
  it as shorthand for "git worktree add --detach <path> HEAD"[3]

[1]: http://thread.gmane.org/gmane.comp.version-control.git/274024
[2]: http://article.gmane.org/gmane.comp.version-control.git/274035
[3]: http://article.gmane.org/gmane.comp.version-control.git/274083

Eric Sunshine (22):
  checkout: avoid resolving HEAD unnecessarily
  checkout: name check_linked_checkouts() more meaningfully
  checkout: improve die_if_checked_out() robustness
  checkout: die_if_checked_out: simplify strbuf management
  checkout: generalize die_if_checked_out() branch name argument
  checkout: check_linked_checkout: improve "already checked out"
    aesthetic
  checkout: check_linked_checkout: simplify symref parsing
  checkout: teach check_linked_checkout() about symbolic link HEAD
  branch: publish die_if_checked_out()
  worktree: improve worktree setup message
  worktree: simplify new branch (-b/-B) option checking
  worktree: introduce options container
  worktree: make --detach mutually exclusive with -b/-B
  worktree: add: suppress auto-vivication with --detach and no <branch>
  worktree: make branch creation distinct from worktree population
  worktree: elucidate environment variables intended for child processes
  worktree: add_worktree: construct worktree-population command locally
  worktree: detect branch-name/detached and error conditions locally
  worktree: make setup of new HEAD distinct from worktree population
  worktree: avoid resolving HEAD unnecessarily
  worktree: populate via "git reset --hard" rather than "git checkout"
  checkout: drop intimate knowledge of newly created worktree

 branch.c                |  67 ++++++++++++++++++++++++++
 branch.h                |   7 +++
 builtin/checkout.c      |  82 +++-----------------------------
 builtin/worktree.c      | 123 ++++++++++++++++++++++++++++++++----------------
 t/t2025-worktree-add.sh |  34 +++++++++++++
 5 files changed, 197 insertions(+), 116 deletions(-)

-- 
2.5.0.rc2.378.g0af52e8

---- 8< ----
diff --git a/branch.c b/branch.c
index dfd7698..af9480f 100644
--- a/branch.c
+++ b/branch.c
@@ -347,7 +347,7 @@ static void check_linked_checkout(const char *branch, const char *id)
 	} else
 		strbuf_addstr(&gitdir, get_git_common_dir());
 	skip_prefix(branch, "refs/heads/", &branch);
-	strbuf_strip_suffix(&gitdir, "/.git");
+	strbuf_strip_suffix(&gitdir, ".git");
 	die(_("'%s' is already checked out at '%s'"), branch, gitdir.buf);
 done:
 	strbuf_release(&path);
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 2873064..5d9371c 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -264,7 +264,7 @@ static int add_worktree(const char *path, const char *refname,
 	strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
 	write_file(sb.buf, 1, "../..\n");
 
-	fprintf_ln(stderr, _("Enter %s (identifier %s)"), path, name);
+	fprintf_ln(stderr, _("Preparing %s (identifier %s)"), path, name);
 
 	argv_array_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);
 	argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
@@ -335,7 +335,7 @@ static int add(int ac, const char **av, const char *prefix)
 	if (opts.force_new_branch)
 		opts.new_branch = new_branch_force;
 
-	if (ac < 2 && !opts.new_branch) {
+	if (ac < 2 && !opts.new_branch && !opts.detach) {
 		int n;
 		const char *s = worktree_basename(path, &n);
 		opts.new_branch = xstrndup(s, n);
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index 9e30690..8267411 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -153,6 +153,14 @@ test_expect_success '"add -b" with <branch> omitted' '
 	test_cmp_rev HEAD burble
 '
 
+test_expect_success '"add --detach" with <branch> omitted' '
+	git worktree add --detach fishhook &&
+	git rev-parse HEAD >expected &&
+	git -C fishhook rev-parse HEAD >actual &&
+	test_cmp expected actual &&
+	test_must_fail git -C fishhook symbolic-ref HEAD
+'
+
 test_expect_success '"add" with <branch> omitted' '
 	git worktree add wiffle/bat &&
 	test_cmp_rev HEAD bat
@@ -167,4 +175,22 @@ test_expect_success '"add" auto-vivify does not clobber existing branch' '
 	test_path_is_missing precious
 '
 
+test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
+	git worktree add --detach mish/mash &&
+	test_must_fail git rev-parse mash -- &&
+	test_must_fail git -C mish/mash symbolic-ref HEAD
+'
+
+test_expect_success '"add" -b/-B mutually exclusive' '
+	test_must_fail git worktree add -b poodle -B poodle bamboo master
+'
+
+test_expect_success '"add" -b/--detach mutually exclusive' '
+	test_must_fail git worktree add -b poodle --detach bamboo master
+'
+
+test_expect_success '"add" -B/--detach mutually exclusive' '
+	test_must_fail git worktree add -B poodle --detach bamboo master
+'
+
 test_done
---- 8< ----

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2015-07-17 23:20 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-17 22:59 [PATCH v3 00/22] rid git-checkout of too-intimate knowledge of new worktree Eric Sunshine
2015-07-17 22:59 ` [PATCH v3 01/22] checkout: avoid resolving HEAD unnecessarily Eric Sunshine
2015-07-17 22:59 ` [PATCH v3 02/22] checkout: name check_linked_checkouts() more meaningfully Eric Sunshine
2015-07-17 22:59 ` [PATCH v3 03/22] checkout: improve die_if_checked_out() robustness Eric Sunshine
2015-07-17 22:59 ` [PATCH v3 04/22] checkout: die_if_checked_out: simplify strbuf management Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 05/22] checkout: generalize die_if_checked_out() branch name argument Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 06/22] checkout: check_linked_checkout: improve "already checked out" aesthetic Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 07/22] checkout: check_linked_checkout: simplify symref parsing Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 08/22] checkout: teach check_linked_checkout() about symbolic link HEAD Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 09/22] branch: publish die_if_checked_out() Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 10/22] worktree: improve worktree setup message Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 11/22] worktree: simplify new branch (-b/-B) option checking Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 12/22] worktree: introduce options container Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 13/22] worktree: make --detach mutually exclusive with -b/-B Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 14/22] worktree: add: suppress auto-vivication with --detach and no <branch> Eric Sunshine
2015-07-17 23:20   ` Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 15/22] worktree: make branch creation distinct from worktree population Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 16/22] worktree: elucidate environment variables intended for child processes Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 17/22] worktree: add_worktree: construct worktree-population command locally Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 18/22] worktree: detect branch-name/detached and error conditions locally Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 19/22] worktree: make setup of new HEAD distinct from worktree population Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 20/22] worktree: avoid resolving HEAD unnecessarily Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 21/22] worktree: populate via "git reset --hard" rather than "git checkout" Eric Sunshine
2015-07-17 23:00 ` [PATCH v3 22/22] checkout: drop intimate knowledge of newly created worktree Eric Sunshine

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).