git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Martin <git@mfriebe.de>, "Sergey Organov" <sorganov@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Felipe Contreras" <felipe.contreras@gmail.com>
Subject: [PATCH] switch: rename --create to --new
Date: Fri,  9 Jul 2021 12:43:10 -0500	[thread overview]
Message-ID: <20210709174310.94209-1-felipe.contreras@gmail.com> (raw)

-c is used by `git branch` to copy a branch, it would be nice to copy
the same options for consistency.

Fortunately there's a pretty good alternative to create a new branch:
--new.

-c and --create are still supported, but deprecated.

Suggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Documentation/git-switch.txt |  8 ++++++--
 builtin/checkout.c           |  2 ++
 t/t2060-switch.sh            | 13 +++++++++++--
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt
index 5c438cd505..67f8add9a7 100644
--- a/Documentation/git-switch.txt
+++ b/Documentation/git-switch.txt
@@ -56,8 +56,8 @@ As a special case, you may use `A...B` as a shortcut for the merge
 base of `A` and `B` if there is exactly one merge base. You can leave
 out at most one of `A` and `B`, in which case it defaults to `HEAD`.
 
--c <new-branch>::
---create <new-branch>::
+-n <new-branch>::
+--new <new-branch>::
 	Create a new branch named `<new-branch>` starting at
 	`<start-point>` before switching to the branch. This is a
 	convenient shortcut for:
@@ -67,6 +67,10 @@ $ git branch <new-branch>
 $ git switch <new-branch>
 ------------
 
+-c <new-branch>::
+--create <new-branch>::
+Deprecated alias for --new.
+
 -C <new-branch>::
 --force-create <new-branch>::
 	Similar to `--create` except that if `<new-branch>` already
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f4cd7747d3..43364b5b00 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1833,6 +1833,8 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
 	struct checkout_opts opts;
 	struct option *options = NULL;
 	struct option switch_options[] = {
+		OPT_STRING('n', "new", &opts.new_branch, N_("branch"),
+			   N_("create and switch to a new branch")),
 		OPT_STRING('c', "create", &opts.new_branch, N_("branch"),
 			   N_("create and switch to a new branch")),
 		OPT_STRING('C', "force-create", &opts.new_branch_force, N_("branch"),
diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh
index 9bc6a3aa5c..e6023c70f7 100755
--- a/t/t2060-switch.sh
+++ b/t/t2060-switch.sh
@@ -41,17 +41,26 @@ test_expect_success 'switch and detach current branch' '
 
 test_expect_success 'switch and create branch' '
 	test_when_finished git switch main &&
-	git switch -c temp main^ &&
+	git switch -n temp main^ &&
 	test_cmp_rev main^ refs/heads/temp &&
 	echo refs/heads/temp >expected-branch &&
 	git symbolic-ref HEAD >actual-branch &&
 	test_cmp expected-branch actual-branch
 '
 
+test_expect_success 'switch and create branch (deprecated)' '
+	test_when_finished git switch main &&
+	git switch -c temp-d main^ &&
+	test_cmp_rev main^ refs/heads/temp-d &&
+	echo refs/heads/temp-d >expected-branch &&
+	git symbolic-ref HEAD >actual-branch &&
+	test_cmp expected-branch actual-branch
+'
+
 test_expect_success 'force create branch from HEAD' '
 	test_when_finished git switch main &&
 	git switch --detach main &&
-	test_must_fail git switch -c temp &&
+	test_must_fail git switch -n temp &&
 	git switch -C temp &&
 	test_cmp_rev main refs/heads/temp &&
 	echo refs/heads/temp >expected-branch &&
-- 
2.32.0.36.g70aac2b1aa


                 reply	other threads:[~2021-07-09 17:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210709174310.94209-1-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@mfriebe.de \
    --cc=git@vger.kernel.org \
    --cc=sorganov@gmail.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 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 NNTP newsgroup(s).