git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 0/3] make git worktree add dwim more

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Nov 18, 2017, 22:47 UTC
Message-ID
<20171118224706.13810-1-t.gummerer@gmail.com>
In-Reply-To
<20171118181103.28354-1-t.gummerer@gmail.com>

Sorry about the noise with v2 and v3 so quickly one after another. I only too late realized that the new dwim for 'add <path> <branch>' doesn't make much sense if -b or --detach are given, and it's better to keep on erroring out in these cases.

The previous rounds were at https://public-inbox.org/git/20171112134305.3949-1-t.gummerer@gmail.com/ and https://public-inbox.org/git/20171118181103.28354-1-t.gummerer@gmail.com/.

In case anybody already started reading v2, an interdiff between the two versions is below:

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 11cac104d9..eedead2c4c 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -52,9 +52,9 @@ is linked to the current repository, sharing everything except working
 directory specific files such as HEAD, index, etc. `-` may also be
 specified as `<branch>`; it is synonymous with `@{-1}`.
 +
-If <branch> is not found but there does exist a tracking branch in
-exactly one remote (call it <remote>) with a matching name, treat as
-equivalent to
+If <branch> is not found, and neither `-b` nor `-B` nor `--detach` are
+used, but there does exist a tracking branch in exactly one remote
+(call it <remote>) with a matching name, treat as equivalent to
 ------------
 $ git worktree add -b <branch> <path> <remote>/<branch>
 ------------
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 82088415b8..b2a6dd020c 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -396,7 +396,7 @@ static int add(int ac, const char **av, const char *prefix)
 		}
 	}
 
-	if (ac == 2) {
+	if (ac == 2 && !opts.new_branch && !opts.detach) {
 		struct object_id oid;
 		struct commit *commit;
 		const char *remote;
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index a566d867fe..87e233f812 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -347,6 +347,8 @@ test_expect_success '"add" <path> <branch> dwims' '
 		git config remote.repo_upstream.fetch \
 			  "refs/heads/*:refs/remotes/repo_upstream/*" &&
 		git fetch --all &&
+		test_must_fail git worktree add -b foo ../foo foo &&
+		test_must_fail git worktree add --detach ../foo foo &&
 		git worktree add ../foo foo
 	) &&
 	(

Thomas Gummerer (3):
  checkout: factor out functions to new lib file
  worktree: make add <path> <branch> dwim
  worktree: make add <path> dwim

 Documentation/git-worktree.txt |  22 +++++++--
 Makefile                       |   1 +
 builtin/checkout.c             |  41 +---------------
 builtin/worktree.c             |  24 ++++++++++
 checkout.c                     |  42 ++++++++++++++++
 checkout.h                     |  13 +++++
 t/t2025-worktree-add.sh        | 106 +++++++++++++++++++++++++++++++++++++++++
 7 files changed, 206 insertions(+), 43 deletions(-)
 create mode 100644 checkout.c
 create mode 100644 checkout.h
-- 
2.15.0.345.gf926f18f3
Previous: Thomas GummererNext: Thomas Gummerer
Message 17 of 28 in “checkout: factor out functions to new lib file”
  1. 1/2 checkout: factor out functions to new lib fileThomas Gummerer, Nov 12, 2017
  2. 2/2 worktree: make add dwimThomas Gummerer, Nov 12, 2017
  3. Junio C HamanoNov 13, 2017
  4. Thomas GummererNov 14, 2017
  5. Eric SunshineNov 14, 2017
  6. Eric SunshineNov 14, 2017
  7. Thomas GummererNov 15, 2017
  8. Thomas GummererNov 18, 2017
  9. Thomas GummererNov 15, 2017
  10. Eric SunshineNov 15, 2017
  11. Junio C HamanoNov 13, 2017
  12. Thomas GummererNov 14, 2017
  13. 1/3 checkout: factor out functions to new lib fileThomas Gummerer, Nov 18, 2017
  14. 2/3 worktree: make add <path> <branch> dwimThomas Gummerer, Nov 18, 2017
  15. Thomas GummererNov 18, 2017
  16. 3/3 worktree: make add <path> dwimThomas Gummerer, Nov 18, 2017
  17. 0/3 make git worktree add dwim moreThomas Gummerer, Nov 18, 2017
  18. 2/3 worktree: make add <path> <branch> dwimThomas Gummerer, Nov 18, 2017
  19. Eric SunshineNov 19, 2017
  20. Thomas GummererNov 19, 2017
  21. 1/3 checkout: factor out functions to new lib fileThomas Gummerer, Nov 18, 2017
  22. 3/3 worktree: make add <path> dwimThomas Gummerer, Nov 18, 2017
  23. Eric SunshineNov 19, 2017
  24. Eric SunshineNov 19, 2017
  25. Junio C HamanoNov 20, 2017
  26. Thomas GummererNov 21, 2017
  27. Junio C HamanoNov 22, 2017
  28. Thomas GummererNov 22, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.