diff mbox series

[2/3] worktree: add -d short option for --detach

Message ID 20200904070703.47898-3-sunshine@sunshineco.com (mailing list archive)
State Accepted
Commit c670aa47dff9829360cc69174f8dd0d82f096011
Headers show
Series worktree: add -d shorthand for --detach & improve documentation | expand

Commit Message

Eric Sunshine Sept. 4, 2020, 7:07 a.m. UTC
Like git-switch and git-checkout, git-worktree can check out a branch or
set up a detached HEAD. However, unlike git-switch and git-checkout,
git-worktree does not understand -d as shorthand for --detach, which may
confound users accustomed to using -d for this purpose. Address this
shortcoming by adding -d as shorthand for --detach in order to bring
git-worktree in line with the other commands.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 Documentation/git-worktree.txt | 1 +
 builtin/worktree.c             | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 6ee6ec7982..d252b6873b 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -143,6 +143,7 @@  To remove a locked working tree, specify `--force` twice.
 	exists. `-B` overrides this safeguard, resetting `<new-branch>` to
 	`<commit-ish>`.
 
+-d::
 --detach::
 	With `add`, detach `HEAD` in the new working tree. See "DETACHED HEAD"
 	in linkgit:git-checkout[1].
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 378f332b5d..1737165d2d 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -555,7 +555,7 @@  static int add(int ac, const char **av, const char *prefix)
 			   N_("create a new branch")),
 		OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
 			   N_("create or reset a branch")),
-		OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
+		OPT_BOOL('d', "detach", &opts.detach, N_("detach HEAD at named commit")),
 		OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
 		OPT_BOOL(0, "lock", &opts.keep_locked, N_("keep the new working tree locked")),
 		OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),