{"thread":{"id":"38109","subject":"[RFC/PATCH 0/2] Make git branch -f forceful","startedAt":"2014-12-04T13:26:43Z","lastAt":"2014-12-08T16:28:45Z","messageCount":9,"participants":["Michael J Gruber","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"253051","messageId":"cover.1417699299.git.git@drmicha.warpmail.net","threadId":"38109","inReplyTo":null,"subject":"[RFC/PATCH 0/2] Make git branch -f forceful","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-04T13:26:43Z","receivedAt":"2014-12-04T13:26:43Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"For many git commands, '-f/--force' is a way to force actions which\nwould otherwise error out. Way more than once, I've been trying this\nwith 'git branch -d' and 'git branch -m'...\n\nI've had these two patches sitting in my tree for 3 years now it seems.\nHere's a rebase.\n\nBefore applying these for food I should probably rename force_create to force.\n\nMichael J Gruber (2):\n  t3200-branch: test -M\n  branch: allow -f with -m and -d\n\n builtin/branch.c  |  9 +++++++--\n t/t3200-branch.sh | 14 ++++++++++++++\n 2 files changed, 21 insertions(+), 2 deletions(-)\n\n-- \n2.2.0.rc3.286.g888a711\n"},{"id":"253053","messageId":"4522a9a6606467e130c2430d717286c92c777b6f.1417699299.git.git@drmicha.warpmail.net","threadId":"38109","inReplyTo":"cover.1417699299.git.git@drmicha.warpmail.net","subject":"[RFC/PATCH 1/2] t3200-branch: test -M","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-04T13:26:44Z","receivedAt":"2014-12-04T13:26:44Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n t/t3200-branch.sh | 9 +++++++++\n 1 file changed, 9 insertions(+)\n\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 432921b..0b3b8f5 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -97,6 +97,15 @@ test_expect_success 'git branch -m o/o o should fail when o/p exists' '\n \ttest_must_fail git branch -m o/o o\n '\n \n+test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '\n+\tgit branch o/q &&\n+\ttest_must_fail git branch -m o/q o/p\n+'\n+\n+test_expect_success 'git branch -M o/q o/p should work when o/p exists' '\n+\tgit branch -M o/q o/p\n+'\n+\n test_expect_success 'git branch -m q r/q should fail when r exists' '\n \tgit branch q &&\n \tgit branch r &&\n-- \n2.2.0.rc3.286.g888a711\n"},{"id":"253052","messageId":"7b1ae15228841d3eaed739e89295ec10a2be45fa.1417699299.git.git@drmicha.warpmail.net","threadId":"38109","inReplyTo":"cover.1417699299.git.git@drmicha.warpmail.net","subject":"[RFC/PATCH 2/2] branch: allow -f with -m and -d","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-04T13:26:45Z","receivedAt":"2014-12-04T13:26:45Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"-f/--force is the standard way to force an action, and is used by branch\nfor the recreation of existing branches, but not for deleting unmerged\nbranches nor for renaming to an existing branch.\n\nMake \"-m -f\" equivalent to \"-M\" and \"-d -f\" equivalent to\" -D\", i.e.\nallow -f/--force to be used with -m/-d also.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n builtin/branch.c  | 9 +++++++--\n t/t3200-branch.sh | 5 +++++\n 2 files changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 3b79c50..8ea04d7 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -848,7 +848,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOL('l', \"create-reflog\", &reflog, N_(\"create the branch's reflog\")),\n \t\tOPT_BOOL(0, \"edit-description\", &edit_description,\n \t\t\t N_(\"edit the description for the branch\")),\n-\t\tOPT__FORCE(&force_create, N_(\"force creation (when already exists)\")),\n+\t\tOPT__FORCE(&force_create, N_(\"force creation, move/rename, deletion\")),\n \t\t{\n \t\t\tOPTION_CALLBACK, 0, \"no-merged\", &merge_filter_ref,\n \t\t\tN_(\"commit\"), N_(\"print only not merged branches\"),\n@@ -891,7 +891,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \tif (with_commit || merge_filter != NO_FILTER)\n \t\tlist = 1;\n \n-\tif (!!delete + !!rename + !!force_create + !!new_upstream +\n+\tif (!!delete + !!rename + !!new_upstream +\n \t    list + unset_upstream > 1)\n \t\tusage_with_options(builtin_branch_usage, options);\n \n@@ -904,6 +904,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tcolopts = 0;\n \t}\n \n+\tif (force_create) {\n+\t\tdelete *= 2;\n+\t\trename *= 2;\n+\t}\n+\n \tif (delete) {\n \t\tif (!argc)\n \t\t\tdie(_(\"branch name required\"));\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 0b3b8f5..ddea498 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -106,6 +106,11 @@ test_expect_success 'git branch -M o/q o/p should work when o/p exists' '\n \tgit branch -M o/q o/p\n '\n \n+test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '\n+\tgit branch o/q &&\n+\tgit branch -m -f o/q o/p\n+'\n+\n test_expect_success 'git branch -m q r/q should fail when r exists' '\n \tgit branch q &&\n \tgit branch r &&\n-- \n2.2.0.rc3.286.g888a711\n"},{"id":"253078","messageId":"xmqqh9xbtehw.fsf@gitster.dls.corp.google.com","threadId":"38109","inReplyTo":"7b1ae15228841d3eaed739e89295ec10a2be45fa.1417699299.git.git@drmicha.warpmail.net","subject":"Re: [RFC/PATCH 2/2] branch: allow -f with -m and -d","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-04T19:13:31Z","receivedAt":"2014-12-04T19:13:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> -f/--force is the standard way to force an action, and is used by branch\n> for the recreation of existing branches, but not for deleting unmerged\n> branches nor for renaming to an existing branch.\n>\n> Make \"-m -f\" equivalent to \"-M\" and \"-d -f\" equivalent to\" -D\", i.e.\n> allow -f/--force to be used with -m/-d also.\n\nI like that goal.  And I agree with your s/force_create/force/g\nremark on the cover, too.\n\n\n\n> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n> ---\n>  builtin/branch.c  | 9 +++++++--\n>  t/t3200-branch.sh | 5 +++++\n>  2 files changed, 12 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index 3b79c50..8ea04d7 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -848,7 +848,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n>  \t\tOPT_BOOL('l', \"create-reflog\", &reflog, N_(\"create the branch's reflog\")),\n>  \t\tOPT_BOOL(0, \"edit-description\", &edit_description,\n>  \t\t\t N_(\"edit the description for the branch\")),\n> -\t\tOPT__FORCE(&force_create, N_(\"force creation (when already exists)\")),\n> +\t\tOPT__FORCE(&force_create, N_(\"force creation, move/rename, deletion\")),\n>  \t\t{\n>  \t\t\tOPTION_CALLBACK, 0, \"no-merged\", &merge_filter_ref,\n>  \t\t\tN_(\"commit\"), N_(\"print only not merged branches\"),\n> @@ -891,7 +891,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n>  \tif (with_commit || merge_filter != NO_FILTER)\n>  \t\tlist = 1;\n>  \n> -\tif (!!delete + !!rename + !!force_create + !!new_upstream +\n> +\tif (!!delete + !!rename + !!new_upstream +\n\nThis puzzled me but earlier -f implied creation and no other mode\n(hence it was an error to give it together with delete and other\nmodes), but now -f is merely a \"do forcibly whatever mode of\noperation other option determines\" that does not conflict.\n\nWhat should \"-f -u\" and \"-f -l\" do, then, though?\n\n>  \t    list + unset_upstream > 1)\n>  \t\tusage_with_options(builtin_branch_usage, options);\n>  \n> @@ -904,6 +904,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n>  \t\tcolopts = 0;\n>  \t}\n>  \n> +\tif (force_create) {\n> +\t\tdelete *= 2;\n> +\t\trename *= 2;\n> +\t}\n> +\n>  \tif (delete) {\n>  \t\tif (!argc)\n>  \t\t\tdie(_(\"branch name required\"));\n> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\n> index 0b3b8f5..ddea498 100755\n> --- a/t/t3200-branch.sh\n> +++ b/t/t3200-branch.sh\n> @@ -106,6 +106,11 @@ test_expect_success 'git branch -M o/q o/p should work when o/p exists' '\n>  \tgit branch -M o/q o/p\n>  '\n>  \n> +test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '\n> +\tgit branch o/q &&\n> +\tgit branch -m -f o/q o/p\n> +'\n> +\n>  test_expect_success 'git branch -m q r/q should fail when r exists' '\n>  \tgit branch q &&\n>  \tgit branch r &&\n"},{"id":"253161","messageId":"54818FA7.7040102@drmicha.warpmail.net","threadId":"38109","inReplyTo":"xmqqh9xbtehw.fsf@gitster.dls.corp.google.com","subject":"Re: [RFC/PATCH 2/2] branch: allow -f with -m and -d","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-05T10:57:43Z","receivedAt":"2014-12-05T10:57:43Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano schrieb am 04.12.2014 um 20:13:\n> Michael J Gruber <git@drmicha.warpmail.net> writes:\n> \n>> -f/--force is the standard way to force an action, and is used by branch\n>> for the recreation of existing branches, but not for deleting unmerged\n>> branches nor for renaming to an existing branch.\n>>\n>> Make \"-m -f\" equivalent to \"-M\" and \"-d -f\" equivalent to\" -D\", i.e.\n>> allow -f/--force to be used with -m/-d also.\n> \n> I like that goal.  And I agree with your s/force_create/force/g\n> remark on the cover, too.\n> \n> \n> \n>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n>> ---\n>>  builtin/branch.c  | 9 +++++++--\n>>  t/t3200-branch.sh | 5 +++++\n>>  2 files changed, 12 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/builtin/branch.c b/builtin/branch.c\n>> index 3b79c50..8ea04d7 100644\n>> --- a/builtin/branch.c\n>> +++ b/builtin/branch.c\n>> @@ -848,7 +848,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n>>  \t\tOPT_BOOL('l', \"create-reflog\", &reflog, N_(\"create the branch's reflog\")),\n>>  \t\tOPT_BOOL(0, \"edit-description\", &edit_description,\n>>  \t\t\t N_(\"edit the description for the branch\")),\n>> -\t\tOPT__FORCE(&force_create, N_(\"force creation (when already exists)\")),\n>> +\t\tOPT__FORCE(&force_create, N_(\"force creation, move/rename, deletion\")),\n>>  \t\t{\n>>  \t\t\tOPTION_CALLBACK, 0, \"no-merged\", &merge_filter_ref,\n>>  \t\t\tN_(\"commit\"), N_(\"print only not merged branches\"),\n>> @@ -891,7 +891,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n>>  \tif (with_commit || merge_filter != NO_FILTER)\n>>  \t\tlist = 1;\n>>  \n>> -\tif (!!delete + !!rename + !!force_create + !!new_upstream +\n>> +\tif (!!delete + !!rename + !!new_upstream +\n> \n> This puzzled me but earlier -f implied creation and no other mode\n> (hence it was an error to give it together with delete and other\n> modes), but now -f is merely a \"do forcibly whatever mode of\n> operation other option determines\" that does not conflict.\n> \n> What should \"-f -u\" and \"-f -l\" do, then, though?\n> \n>>  \t    list + unset_upstream > 1)\n>>  \t\tusage_with_options(builtin_branch_usage, options);\n>>  \n\nI would say there is nothing to force, so we ignore -f there.\nAlternatively, we could warn about that. While I do consider forcing\nsomething that doesn't need force a mistake in other contexts, I would\nnot apply that thinking to the -f option.\n\nMichael\n"},{"id":"253173","messageId":"xmqqbnniq8k8.fsf@gitster.dls.corp.google.com","threadId":"38109","inReplyTo":"54818FA7.7040102@drmicha.warpmail.net","subject":"Re: [RFC/PATCH 2/2] branch: allow -f with -m and -d","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-05T18:02:15Z","receivedAt":"2014-12-05T18:02:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n>> What should \"-f -u\" and \"-f -l\" do, then, though?\n>> \n>>>  \t    list + unset_upstream > 1)\n>>>  \t\tusage_with_options(builtin_branch_usage, options);\n>>>  \n>\n> I would say there is nothing to force, so we ignore -f there.\n\nOK, and that is what the updated code does.\n"},{"id":"253365","messageId":"cover.1418055912.git.git@drmicha.warpmail.net","threadId":"38109","inReplyTo":"xmqqbnniq8k8.fsf@gitster.dls.corp.google.com","subject":"[PATCHv2 0/2] Make git branch -f forceful","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-08T16:28:43Z","receivedAt":"2014-12-08T16:28:43Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"For many git commands, '-f/--force' is a way to force actions which\nwould otherwise error out. Way more than once, I've been trying this\nwith 'git branch -d' and 'git branch -m'...\n\nI've had these two patches sitting in my tree for 3 years now it seems.\nHere's a rebase.\n\nIn v2 I rename force_create to force and spell out the \"-f\" behaviour\nfor other options in the commit message.\n\nMichael J Gruber (2):\n  t3200-branch: test -M\n  branch: allow -f with -m and -d\n\n builtin/branch.c  | 13 +++++++++----\n t/t3200-branch.sh | 14 ++++++++++++++\n 2 files changed, 23 insertions(+), 4 deletions(-)\n\n-- \n2.2.0.345.g7041aac\n"},{"id":"253366","messageId":"4f734d9f44bd6aa1b54ca3f81aa0e3822286f9d9.1418055912.git.git@drmicha.warpmail.net","threadId":"38109","inReplyTo":"xmqqbnniq8k8.fsf@gitster.dls.corp.google.com","subject":"[PATCHv2 1/2] t3200-branch: test -M","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-08T16:28:44Z","receivedAt":"2014-12-08T16:28:44Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t3200-branch.sh | 9 +++++++++\n 1 file changed, 9 insertions(+)\n\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 432921b..0b3b8f5 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -97,6 +97,15 @@ test_expect_success 'git branch -m o/o o should fail when o/p exists' '\n \ttest_must_fail git branch -m o/o o\n '\n \n+test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '\n+\tgit branch o/q &&\n+\ttest_must_fail git branch -m o/q o/p\n+'\n+\n+test_expect_success 'git branch -M o/q o/p should work when o/p exists' '\n+\tgit branch -M o/q o/p\n+'\n+\n test_expect_success 'git branch -m q r/q should fail when r exists' '\n \tgit branch q &&\n \tgit branch r &&\n-- \n2.2.0.345.g7041aac\n"},{"id":"253367","messageId":"80b7cc5312666af6136d641a24e42aed78636724.1418055912.git.git@drmicha.warpmail.net","threadId":"38109","inReplyTo":"xmqqbnniq8k8.fsf@gitster.dls.corp.google.com","subject":"[PATCHv2 2/2] branch: allow -f with -m and -d","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2014-12-08T16:28:45Z","receivedAt":"2014-12-08T16:28:45Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"-f/--force is the standard way to force an action, and is used by branch\nfor the recreation of existing branches, but not for deleting unmerged\nbranches nor for renaming to an existing branch.\n\nMake \"-m -f\" equivalent to \"-M\" and \"-d -f\" equivalent to\" -D\", i.e.\nallow -f/--force to be used with -m/-d also.\n\nFor the list modes, \"-f\" is simply ignored.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n builtin/branch.c  | 13 +++++++++----\n t/t3200-branch.sh |  5 +++++\n 2 files changed, 14 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 3b79c50..dc6f0b2 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -800,7 +800,7 @@ static int edit_branch_description(const char *branch_name)\n \n int cmd_branch(int argc, const char **argv, const char *prefix)\n {\n-\tint delete = 0, rename = 0, force_create = 0, list = 0;\n+\tint delete = 0, rename = 0, force = 0, list = 0;\n \tint verbose = 0, abbrev = -1, detached = 0;\n \tint reflog = 0, edit_description = 0;\n \tint quiet = 0, unset_upstream = 0;\n@@ -848,7 +848,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOL('l', \"create-reflog\", &reflog, N_(\"create the branch's reflog\")),\n \t\tOPT_BOOL(0, \"edit-description\", &edit_description,\n \t\t\t N_(\"edit the description for the branch\")),\n-\t\tOPT__FORCE(&force_create, N_(\"force creation (when already exists)\")),\n+\t\tOPT__FORCE(&force, N_(\"force creation, move/rename, deletion\")),\n \t\t{\n \t\t\tOPTION_CALLBACK, 0, \"no-merged\", &merge_filter_ref,\n \t\t\tN_(\"commit\"), N_(\"print only not merged branches\"),\n@@ -891,7 +891,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \tif (with_commit || merge_filter != NO_FILTER)\n \t\tlist = 1;\n \n-\tif (!!delete + !!rename + !!force_create + !!new_upstream +\n+\tif (!!delete + !!rename + !!new_upstream +\n \t    list + unset_upstream > 1)\n \t\tusage_with_options(builtin_branch_usage, options);\n \n@@ -904,6 +904,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tcolopts = 0;\n \t}\n \n+\tif (force) {\n+\t\tdelete *= 2;\n+\t\trename *= 2;\n+\t}\n+\n \tif (delete) {\n \t\tif (!argc)\n \t\t\tdie(_(\"branch name required\"));\n@@ -1020,7 +1025,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \n \t\tbranch_existed = ref_exists(branch->refname);\n \t\tcreate_branch(head, argv[0], (argc == 2) ? argv[1] : head,\n-\t\t\t      force_create, reflog, 0, quiet, track);\n+\t\t\t      force, reflog, 0, quiet, track);\n \n \t\t/*\n \t\t * We only show the instructions if the user gave us\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 0b3b8f5..ddea498 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -106,6 +106,11 @@ test_expect_success 'git branch -M o/q o/p should work when o/p exists' '\n \tgit branch -M o/q o/p\n '\n \n+test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '\n+\tgit branch o/q &&\n+\tgit branch -m -f o/q o/p\n+'\n+\n test_expect_success 'git branch -m q r/q should fail when r exists' '\n \tgit branch q &&\n \tgit branch r &&\n-- \n2.2.0.345.g7041aac\n"}]}