{"thread":{"id":"56085","subject":"[PATCH] switch: rename --create to --new","startedAt":"2021-07-09T17:43:19Z","lastAt":"2021-07-09T17:43:19Z","messageCount":1,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"429571","messageId":"20210709174310.94209-1-felipe.contreras@gmail.com","threadId":"56085","inReplyTo":null,"subject":"[PATCH] switch: rename --create to --new","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-07-09T17:43:10Z","receivedAt":"2021-07-09T17:43:19Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"-c is used by `git branch` to copy a branch, it would be nice to copy\nthe same options for consistency.\n\nFortunately there's a pretty good alternative to create a new branch:\n--new.\n\n-c and --create are still supported, but deprecated.\n\nSuggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n Documentation/git-switch.txt |  8 ++++++--\n builtin/checkout.c           |  2 ++\n t/t2060-switch.sh            | 13 +++++++++++--\n 3 files changed, 19 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt\nindex 5c438cd505..67f8add9a7 100644\n--- a/Documentation/git-switch.txt\n+++ b/Documentation/git-switch.txt\n@@ -56,8 +56,8 @@ As a special case, you may use `A...B` as a shortcut for the merge\n base of `A` and `B` if there is exactly one merge base. You can leave\n out at most one of `A` and `B`, in which case it defaults to `HEAD`.\n \n--c <new-branch>::\n---create <new-branch>::\n+-n <new-branch>::\n+--new <new-branch>::\n \tCreate a new branch named `<new-branch>` starting at\n \t`<start-point>` before switching to the branch. This is a\n \tconvenient shortcut for:\n@@ -67,6 +67,10 @@ $ git branch <new-branch>\n $ git switch <new-branch>\n ------------\n \n+-c <new-branch>::\n+--create <new-branch>::\n+Deprecated alias for --new.\n+\n -C <new-branch>::\n --force-create <new-branch>::\n \tSimilar to `--create` except that if `<new-branch>` already\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex f4cd7747d3..43364b5b00 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -1833,6 +1833,8 @@ int cmd_switch(int argc, const char **argv, const char *prefix)\n \tstruct checkout_opts opts;\n \tstruct option *options = NULL;\n \tstruct option switch_options[] = {\n+\t\tOPT_STRING('n', \"new\", &opts.new_branch, N_(\"branch\"),\n+\t\t\t   N_(\"create and switch to a new branch\")),\n \t\tOPT_STRING('c', \"create\", &opts.new_branch, N_(\"branch\"),\n \t\t\t   N_(\"create and switch to a new branch\")),\n \t\tOPT_STRING('C', \"force-create\", &opts.new_branch_force, N_(\"branch\"),\ndiff --git a/t/t2060-switch.sh b/t/t2060-switch.sh\nindex 9bc6a3aa5c..e6023c70f7 100755\n--- a/t/t2060-switch.sh\n+++ b/t/t2060-switch.sh\n@@ -41,17 +41,26 @@ test_expect_success 'switch and detach current branch' '\n \n test_expect_success 'switch and create branch' '\n \ttest_when_finished git switch main &&\n-\tgit switch -c temp main^ &&\n+\tgit switch -n temp main^ &&\n \ttest_cmp_rev main^ refs/heads/temp &&\n \techo refs/heads/temp >expected-branch &&\n \tgit symbolic-ref HEAD >actual-branch &&\n \ttest_cmp expected-branch actual-branch\n '\n \n+test_expect_success 'switch and create branch (deprecated)' '\n+\ttest_when_finished git switch main &&\n+\tgit switch -c temp-d main^ &&\n+\ttest_cmp_rev main^ refs/heads/temp-d &&\n+\techo refs/heads/temp-d >expected-branch &&\n+\tgit symbolic-ref HEAD >actual-branch &&\n+\ttest_cmp expected-branch actual-branch\n+'\n+\n test_expect_success 'force create branch from HEAD' '\n \ttest_when_finished git switch main &&\n \tgit switch --detach main &&\n-\ttest_must_fail git switch -c temp &&\n+\ttest_must_fail git switch -n temp &&\n \tgit switch -C temp &&\n \ttest_cmp_rev main refs/heads/temp &&\n \techo refs/heads/temp >expected-branch &&\n-- \n2.32.0.36.g70aac2b1aa\n\n"}]}