{"thread":{"id":"60002","subject":"[PATCH] branch: reject \"--no-all\" and \"--no-remotes\" early","startedAt":"2023-07-18T18:28:07Z","lastAt":"2023-07-18T18:28:07Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"479605","messageId":"xmqqjzuxgjmi.fsf@gitster.g","threadId":"60002","inReplyTo":null,"subject":"[PATCH] branch: reject \"--no-all\" and \"--no-remotes\" early","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-18T18:27:49Z","receivedAt":"2023-07-18T18:28:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As the command line parser for \"git branch --all\" forgets to use\nPARSE_OPT_NONEG, it accepted \"git branch --no-all\", and then passed\na nonsense value to the underlying machinery, leading to a fatal\nerror \"filter_refs: invalid type\".  The \"--remotes\" option had\nexactly the same issue.\n\nCatch the unsupported options early in the option parser.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/branch.c         | 10 ++++++----\n t/t3203-branch-output.sh | 16 ++++++++++++++++\n 2 files changed, 22 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex a27bc0a3df..518be060c5 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -720,8 +720,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT_STRING('u', \"set-upstream-to\", &new_upstream, N_(\"upstream\"), N_(\"change the upstream info\")),\n \t\tOPT_BOOL(0, \"unset-upstream\", &unset_upstream, N_(\"unset the upstream info\")),\n \t\tOPT__COLOR(&branch_use_color, N_(\"use colored output\")),\n-\t\tOPT_SET_INT('r', \"remotes\",     &filter.kind, N_(\"act on remote-tracking branches\"),\n-\t\t\tFILTER_REFS_REMOTES),\n+\t\tOPT_SET_INT_F('r', \"remotes\",     &filter.kind, N_(\"act on remote-tracking branches\"),\n+\t\t\t      FILTER_REFS_REMOTES,\n+\t\t\t      PARSE_OPT_NONEG),\n \t\tOPT_CONTAINS(&filter.with_commit, N_(\"print only branches that contain the commit\")),\n \t\tOPT_NO_CONTAINS(&filter.no_commit, N_(\"print only branches that don't contain the commit\")),\n \t\tOPT_WITH(&filter.with_commit, N_(\"print only branches that contain the commit\")),\n@@ -729,8 +730,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT__ABBREV(&filter.abbrev),\n \n \t\tOPT_GROUP(N_(\"Specific git-branch actions:\")),\n-\t\tOPT_SET_INT('a', \"all\", &filter.kind, N_(\"list both remote-tracking and local branches\"),\n-\t\t\tFILTER_REFS_REMOTES | FILTER_REFS_BRANCHES),\n+\t\tOPT_SET_INT_F('a', \"all\", &filter.kind, N_(\"list both remote-tracking and local branches\"),\n+\t\t\t      FILTER_REFS_REMOTES | FILTER_REFS_BRANCHES,\n+\t\t\t      PARSE_OPT_NONEG),\n \t\tOPT_BIT('d', \"delete\", &delete, N_(\"delete fully merged branch\"), 1),\n \t\tOPT_BIT('D', NULL, &delete, N_(\"delete branch (even if not merged)\"), 2),\n \t\tOPT_BIT('m', \"move\", &rename, N_(\"move/rename a branch and its reflog\"), 1),\ndiff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh\nindex 93f8295339..758963b189 100755\n--- a/t/t3203-branch-output.sh\n+++ b/t/t3203-branch-output.sh\n@@ -55,9 +55,17 @@ cat >expect <<'EOF'\n EOF\n test_expect_success 'git branch -r shows remote branches' '\n \tgit branch -r >actual &&\n+\ttest_cmp expect actual &&\n+\n+\tgit branch --remotes >actual &&\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'git branch --no-remotes is rejected' '\n+\ttest_must_fail git branch --no-remotes 2>err &&\n+\tgrep \"unknown option .no-remotes.\" err\n+'\n+\n cat >expect <<'EOF'\n   branch-one\n   branch-two\n@@ -68,9 +76,17 @@ cat >expect <<'EOF'\n EOF\n test_expect_success 'git branch -a shows local and remote branches' '\n \tgit branch -a >actual &&\n+\ttest_cmp expect actual &&\n+\n+\tgit branch --all >actual &&\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'git branch --no-all is rejected' '\n+\ttest_must_fail git branch --no-all 2>err &&\n+\tgrep \"unknown option .no-all.\" err\n+'\n+\n cat >expect <<'EOF'\n two\n one\n-- \n2.41.0-376-gcba07a324d\n\n"}]}