* [PATCH] switch: rename --create to --new
@ 2021-07-09 17:43 Felipe Contreras
0 siblings, 0 replies; only message in thread
From: Felipe Contreras @ 2021-07-09 17:43 UTC (permalink / raw)
To: git
Cc: Martin, Sergey Organov, Ævar Arnfjörð Bjarmason,
Felipe Contreras
-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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-09 17:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 17:43 [PATCH] switch: rename --create to --new Felipe Contreras
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.