{"thread":{"id":"47521","subject":"[PATCH 0/4] branch: add '--show-description' option","startedAt":"2018-01-01T22:54:58Z","lastAt":"2018-01-02T19:26:07Z","messageCount":10,"participants":["SZEDER Gábor","Eric Sunshine","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"335597","messageId":"20180101225448.2561-1-szeder.dev@gmail.com","threadId":"47521","inReplyTo":null,"subject":"[PATCH 0/4] branch: add '--show-description' option","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-01-01T22:54:44Z","receivedAt":"2018-01-01T22:54:58Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"'git branch' has an option to edit a branch's description, but lacks the\noption to show that description.  The last patch adds the option to do\njust that.  The first three patches are while-at-it minor cleanups and\nfixes in the area.\n\n\nSZEDER Gábor (4):\n  branch: '--edit-description' is incompatible with other options\n  t3200: fix a misindented line\n  t3200: restore branch after \"unborn --edit-description\" test\n  branch: add '--show-description' option\n\n Documentation/git-branch.txt           |  6 +++++-\n builtin/branch.c                       | 39 +++++++++++++++++++++++++++++++---\n contrib/completion/git-completion.bash |  4 ++--\n t/t3200-branch.sh                      | 26 ++++++++++++++++++++++-\n 4 files changed, 68 insertions(+), 7 deletions(-)\n\n-- \n2.16.0.rc0.67.g3a46dbca7\n\n"},{"id":"335598","messageId":"20180101225448.2561-3-szeder.dev@gmail.com","threadId":"47521","inReplyTo":"20180101225448.2561-1-szeder.dev@gmail.com","subject":"[PATCH 2/4] t3200: fix a misindented line","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-01-01T22:54:46Z","receivedAt":"2018-01-01T22:55:01Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n t/t3200-branch.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 503a88d02..e9f55ac04 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -1215,7 +1215,7 @@ test_expect_success 'use --edit-description' '\n \t\techo \"New contents\" >\"$1\"\n \tEOF\n \tEDITOR=./editor git branch --edit-description &&\n-\t\twrite_script editor <<-\\EOF &&\n+\twrite_script editor <<-\\EOF &&\n \t\tgit stripspace -s <\"$1\" >\"EDITOR_OUTPUT\"\n \tEOF\n \tEDITOR=./editor git branch --edit-description &&\n-- \n2.16.0.rc0.67.g3a46dbca7\n\n"},{"id":"335599","messageId":"20180101225448.2561-5-szeder.dev@gmail.com","threadId":"47521","inReplyTo":"20180101225448.2561-1-szeder.dev@gmail.com","subject":"[PATCH 4/4] branch: add '--show-description' option","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-01-01T22:54:48Z","receivedAt":"2018-01-01T22:55:04Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"'git branch' has an option to edit a branch's description, but lacks\nthe option to show that description.\n\nTherefore, add a new '--show-description' option to do just that, as a\nmore user-friendly alternative to 'git config --get\nbranch.$branchname.description':\n\n  - it's shorter to type (both in the number of characters and the\n    number of TABs if using completion),\n  - works on the current branch without explicitly naming it,\n  - hides the implementation detail that branch descriptions are\n    stored in the config file, and\n  - errors out with a proper error message when the given branch\n    doesn't exist (but exits quietly with an error code when the\n    branch does exit but has no description, just like the 'git config'\n    query does).\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n Documentation/git-branch.txt           |  6 +++++-\n builtin/branch.c                       | 39 +++++++++++++++++++++++++++++++---\n contrib/completion/git-completion.bash |  4 ++--\n t/t3200-branch.sh                      | 23 ++++++++++++++++++++\n 4 files changed, 66 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex b3084c99c..e05c9e193 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -20,7 +20,7 @@ SYNOPSIS\n 'git branch' (-m | -M) [<oldbranch>] <newbranch>\n 'git branch' (-c | -C) [<oldbranch>] <newbranch>\n 'git branch' (-d | -D) [-r] <branchname>...\n-'git branch' --edit-description [<branchname>]\n+'git branch' (--edit-description | --show-description) [<branchname>]\n \n DESCRIPTION\n -----------\n@@ -226,6 +226,10 @@ start-point is either a local or remote-tracking branch.\n \t`request-pull`, and `merge` (if enabled)). Multi-line explanations\n \tmay be used.\n \n+--show-description::\n+\tShow the description of the branch previously set using\n+\t`--edit-description`.\n+\n --contains [<commit>]::\n \tOnly list branches which contain the specified commit (HEAD\n \tif not specified). Implies `--list`.\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 32531aa44..f2f6614e2 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -573,7 +573,7 @@ static int edit_branch_description(const char *branch_name)\n int cmd_branch(int argc, const char **argv, const char *prefix)\n {\n \tint delete = 0, rename = 0, copy = 0, force = 0, list = 0;\n-\tint reflog = 0, edit_description = 0;\n+\tint reflog = 0, edit_description = 0, show_description = 0;\n \tint quiet = 0, unset_upstream = 0;\n \tconst char *new_upstream = NULL;\n \tenum branch_track track;\n@@ -615,6 +615,8 @@ 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_BOOL(0, \"show-description\", &show_description,\n+\t\t\t N_(\"show the description for the branch\")),\n \t\tOPT__FORCE(&force, N_(\"force creation, move/rename, deletion\")),\n \t\tOPT_MERGED(&filter, N_(\"print only branches that are merged\")),\n \t\tOPT_NO_MERGED(&filter, N_(\"print only branches that are not merged\")),\n@@ -654,7 +656,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, prefix, options, builtin_branch_usage,\n \t\t\t     0);\n \n-\tif (!delete && !rename && !copy && !edit_description && !new_upstream && !unset_upstream && argc == 0)\n+\tif (!delete && !rename && !copy &&\n+\t    !edit_description && !show_description &&\n+\t    !new_upstream && !unset_upstream && argc == 0)\n \t\tlist = 1;\n \n \tif (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE || filter.points_at.nr ||\n@@ -662,7 +666,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tlist = 1;\n \n \tif (!!delete + !!rename + !!copy + !!new_upstream +\n-\t    list + unset_upstream + edit_description > 1)\n+\t    list + unset_upstream + edit_description + show_description > 1)\n \t\tusage_with_options(builtin_branch_usage, options);\n \n \tif (filter.abbrev == -1)\n@@ -737,6 +741,35 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \n \t\tif (edit_branch_description(branch_name))\n \t\t\treturn 1;\n+\t} else if (show_description) {\n+\t\tconst char *branch_name;\n+\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\tchar *description = NULL;\n+\n+\t\tif (!argc) {\n+\t\t\tif (filter.detached)\n+\t\t\t\tdie(_(\"cannot show description on detached HEAD\"));\n+\t\t\tbranch_name = head;\n+\t\t} else if (argc == 1)\n+\t\t\tbranch_name = argv[0];\n+\t\telse\n+\t\t\tdie(_(\"cannot show description of more than one branch\"));\n+\n+\t\tstrbuf_addf(&buf, \"refs/heads/%s\", branch_name);\n+\t\tif (!ref_exists(buf.buf)) {\n+\t\t\tstrbuf_release(&buf);\n+\t\t\treturn error(_(\"no branch named '%s'\"), branch_name);\n+\t\t}\n+\t\tstrbuf_reset(&buf);\n+\n+\t\tstrbuf_addf(&buf, \"branch.%s.description\", branch_name);\n+\t\tif (git_config_get_string(buf.buf, &description)) {\n+\t\t\tstrbuf_release(&buf);\n+\t\t\treturn 1;\n+\t\t}\n+\t\tprintf(\"%s\", description);\n+\t\tstrbuf_release(&buf);\n+\t\tfree(description);\n \t} else if (copy) {\n \t\tif (!argc)\n \t\t\tdie(_(\"branch name required\"));\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 3683c772c..0fcc13ea0 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1203,8 +1203,8 @@ _git_branch ()\n \t\t__gitcomp \"\n \t\t\t--color --no-color --verbose --abbrev= --no-abbrev\n \t\t\t--track --no-track --contains --no-contains --merged --no-merged\n-\t\t\t--set-upstream-to= --edit-description --list\n-\t\t\t--unset-upstream --delete --move --copy --remotes\n+\t\t\t--set-upstream-to= --edit-description --show-description\n+\t\t\t--list --unset-upstream --delete --move --copy --remotes\n \t\t\t--column --no-column --sort= --points-at\n \t\t\t\"\n \t\t;;\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 427ad490d..53adccc5e 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -1239,6 +1239,29 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '\n \ttest_must_fail env EDITOR=./editor git branch --edit-description\n '\n \n+test_expect_success '--show-description' '\n+\techo \"New contents\" >expect &&\n+\tgit branch --show-description >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--show-description on detached HEAD' '\n+\tgit checkout --detach &&\n+\ttest_when_finished git checkout master &&\n+\ttest_must_fail git branch --show-description\n+'\n+\n+test_expect_success '--show-description with no description errors quietly' '\n+\tgit config --unset branch.master.description &&\n+\ttest_must_fail git branch --show-description >actual 2>actual.err &&\n+\ttest_must_be_empty actual &&\n+\ttest_must_be_empty actual.err\n+'\n+\n+test_expect_success '--show-description on non-existing branch' '\n+\ttest_must_fail git branch --show-description no-such-branch\n+'\n+\n test_expect_success '--merged catches invalid object names' '\n \ttest_must_fail git branch --merged 0000000000000000000000000000000000000000\n '\n-- \n2.16.0.rc0.67.g3a46dbca7\n\n"},{"id":"335600","messageId":"20180101225448.2561-4-szeder.dev@gmail.com","threadId":"47521","inReplyTo":"20180101225448.2561-1-szeder.dev@gmail.com","subject":"[PATCH 3/4] t3200: restore branch after \"unborn --edit-description\" test","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-01-01T22:54:47Z","receivedAt":"2018-01-01T22:55:07Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"The test 'refuse --edit-description on unborn branch for now' switches\nto an orphan branch and leaves the test repository in that state.\nThis might badly influence the subsequent test expecting 'git branch\n--merged' to error out, by hiding a potential regression with an error\ntriggered by the unborn branch.  Furthermore, a new test that will be\nadded later in this series failed first because of this.\n\nUse test_when_finished to switch back to the master branch at the end\nof the test in question.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n t/t3200-branch.sh | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex e9f55ac04..427ad490d 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -1234,6 +1234,7 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '\n \twrite_script editor <<-\\EOF &&\n \t\techo \"New contents\" >\"$1\"\n \tEOF\n+\ttest_when_finished git checkout master &&\n \tgit checkout --orphan unborn &&\n \ttest_must_fail env EDITOR=./editor git branch --edit-description\n '\n-- \n2.16.0.rc0.67.g3a46dbca7\n\n"},{"id":"335601","messageId":"20180101225448.2561-2-szeder.dev@gmail.com","threadId":"47521","inReplyTo":"20180101225448.2561-1-szeder.dev@gmail.com","subject":"[PATCH 1/4] branch: '--edit-description' is incompatible with other options","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-01-01T22:54:45Z","receivedAt":"2018-01-01T22:55:10Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"'--edit-description' is incompatible with 'git branch's other options,\nbut the check for conflicting options doesn't look for this option.\nAs a result 'git branch' doesn't error out showing usage when\n'--edit-description' is used in combination with other options, but\ne.g. 'git branch --list --edit-description' lists all branches and\ndoesn't edit any branch descriptions, while 'git branch\n--edit-description --list' edits the current branch's description but\ndoesn't list the branches.\n\nLook for '--edit-description', too, when looking for conflicting\noptions.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n builtin/branch.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 8dcc2ed05..32531aa44 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -662,7 +662,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tlist = 1;\n \n \tif (!!delete + !!rename + !!copy + !!new_upstream +\n-\t    list + unset_upstream > 1)\n+\t    list + unset_upstream + edit_description > 1)\n \t\tusage_with_options(builtin_branch_usage, options);\n \n \tif (filter.abbrev == -1)\n-- \n2.16.0.rc0.67.g3a46dbca7\n\n"},{"id":"335606","messageId":"CAPig+cQ=Fj-sWrxDH1RV=PnYT01LGapzJjrRT5QdqUTkyc0rfg@mail.gmail.com","threadId":"47521","inReplyTo":"20180101225448.2561-5-szeder.dev@gmail.com","subject":"Re: [PATCH 4/4] branch: add '--show-description' option","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-01-02T05:17:36Z","receivedAt":"2018-01-02T05:17:45Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Jan 1, 2018 at 5:54 PM, SZEDER Gábor <szeder.dev@gmail.com> wrote:\n> 'git branch' has an option to edit a branch's description, but lacks\n> the option to show that description.\n>\n> Therefore, add a new '--show-description' option to do just that, as a\n> more user-friendly alternative to 'git config --get\n> branch.$branchname.description':\n>   [...]\n>   - errors out with a proper error message when the given branch\n>     doesn't exist (but exits quietly with an error code when the\n>     branch does exit but has no description, just like the 'git config'\n\ns/exit/exist/\n\n>     query does).\n>\n> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n> ---\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> @@ -737,6 +741,35 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n> +       } else if (show_description) {\n> +               [...]\n> +               if (!argc) {\n> +                       if (filter.detached)\n> +                               die(_(\"cannot show description on detached HEAD\"));\n> +                       branch_name = head;\n> +               } else if (argc == 1)\n> +                       branch_name = argv[0];\n> +               else\n> +                       die(_(\"cannot show description of more than one branch\"));\n\nAside from paralleling the single branch accepted by\n--edit-description, why this limitation? (Just curious; I don't feel\nstrongly one way or the other.)\n"},{"id":"335608","messageId":"c3937260-1ffd-797b-7f25-53a6a4bf3676@kdbg.org","threadId":"47521","inReplyTo":"20180101225448.2561-5-szeder.dev@gmail.com","subject":"Re: [PATCH 4/4] branch: add '--show-description' option","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2018-01-02T09:32:15Z","receivedAt":"2018-01-02T09:32:25Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 01.01.2018 um 23:54 schrieb SZEDER Gábor:\n> 'git branch' has an option to edit a branch's description, but lacks\n> the option to show that description.\n> \n> Therefore, add a new '--show-description' option to do just that, as a\n> more user-friendly alternative to 'git config --get\n> branch.$branchname.description':\n> \n>    - it's shorter to type (both in the number of characters and the\n>      number of TABs if using completion),\n>    - works on the current branch without explicitly naming it,\n>    - hides the implementation detail that branch descriptions are\n>      stored in the config file, and\n>    - errors out with a proper error message when the given branch\n>      doesn't exist (but exits quietly with an error code when the\n>      branch does exit but has no description, just like the 'git config'\n>      query does).\n\n> +test_expect_success '--show-description with no description errors quietly' '\n> +\tgit config --unset branch.master.description &&\n> +\ttest_must_fail git branch --show-description >actual 2>actual.err &&\n> +\ttest_must_be_empty actual &&\n> +\ttest_must_be_empty actual.err\n> +'\n\nChecking the exact contents of stderr typically fails when tests are run \nunder -x. Perhaps\n\n\ttest_i18ngrep ! \"fatal: \" actual.err &&\"\n\ttest_i18ngrep ! \"error: \" actual.err &&\n\ttest_i18ngrep ! \"warning: \" actual.err\n\nWhich makes me wonder: Why would --show-description have to error out \nsilently? This is not 'git config' after all.\n\n-- Hannes\n"},{"id":"335610","messageId":"CAM0VKjm0WMDm_AETogX7ygMgeqY28YQLJLoM+dxtkfQfnT3aww@mail.gmail.com","threadId":"47521","inReplyTo":"CAPig+cQ=Fj-sWrxDH1RV=PnYT01LGapzJjrRT5QdqUTkyc0rfg@mail.gmail.com","subject":"Re: [PATCH 4/4] branch: add '--show-description' option","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-01-02T10:39:13Z","receivedAt":"2018-01-02T10:39:19Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Jan 2, 2018 at 6:17 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Mon, Jan 1, 2018 at 5:54 PM, SZEDER Gábor <szeder.dev@gmail.com> wrote:\n\n> s/exit/exist/\n\nThanks.\n\n>>     query does).\n>>\n>> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n>> ---\n>> diff --git a/builtin/branch.c b/builtin/branch.c\n>> @@ -737,6 +741,35 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n>> +       } else if (show_description) {\n>> +               [...]\n>> +               if (!argc) {\n>> +                       if (filter.detached)\n>> +                               die(_(\"cannot show description on detached HEAD\"));\n>> +                       branch_name = head;\n>> +               } else if (argc == 1)\n>> +                       branch_name = argv[0];\n>> +               else\n>> +                       die(_(\"cannot show description of more than one branch\"));\n>\n> Aside from paralleling the single branch accepted by\n> --edit-description, why this limitation? (Just curious; I don't feel\n> strongly one way or the other.)\n\nIt's not just '--edit-description', most other options won't accept\nmultiple branches either.  As far as I can tell only deleting branches\ncan deal with multiple branches in one go.\n\nFurthermore, branch descriptions are likely more lines long, so we\ncan't just dump them one after the other, but we we would have to\nseparate the descriptions of different branches in the output.\nConsidering that 'git branch' mostly works only with a single branch at\na time, I didn't feel the need to do so.\n\nGábor\n"},{"id":"335611","messageId":"CAM0VKj=HNvd_wvZMJSGB7hCrjnUj+J+Q17zpbV1ju=rvbDLPrQ@mail.gmail.com","threadId":"47521","inReplyTo":"c3937260-1ffd-797b-7f25-53a6a4bf3676@kdbg.org","subject":"Re: [PATCH 4/4] branch: add '--show-description' option","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-01-02T10:41:23Z","receivedAt":"2018-01-02T10:41:29Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Jan 2, 2018 at 10:32 AM, Johannes Sixt <j6t@kdbg.org> wrote:\n> Am 01.01.2018 um 23:54 schrieb SZEDER Gábor:\n\n>>    - errors out with a proper error message when the given branch\n>>      doesn't exist (but exits quietly with an error code when the\n>>      branch does exit but has no description, just like the 'git config'\n>>      query does).\n>\n>\n>> +test_expect_success '--show-description with no description errors\n>> quietly' '\n>> +       git config --unset branch.master.description &&\n>> +       test_must_fail git branch --show-description >actual 2>actual.err\n>> &&\n>> +       test_must_be_empty actual &&\n>> +       test_must_be_empty actual.err\n>> +'\n>\n>\n> Checking the exact contents of stderr typically fails when tests are run\n> under -x. Perhaps\n>\n>         test_i18ngrep ! \"fatal: \" actual.err &&\"\n>         test_i18ngrep ! \"error: \" actual.err &&\n>         test_i18ngrep ! \"warning: \" actual.err\n>\n> Which makes me wonder: Why would --show-description have to error out\n> silently? This is not 'git config' after all.\n\nI figured it would be beneficial if it were a drop-in replacement for\nthe original 'git config' query.\n\nI don't have a strong opinion about this, and certainly wouldn't mind\nadding an error message instead.\n\nGábor\n"},{"id":"335620","messageId":"20180102192549.27131-1-szeder.dev@gmail.com","threadId":"47521","inReplyTo":"CAM0VKj=HNvd_wvZMJSGB7hCrjnUj+J+Q17zpbV1ju=rvbDLPrQ@mail.gmail.com","subject":"Re: [PATCH 4/4] branch: add '--show-description' option","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-01-02T19:25:49Z","receivedAt":"2018-01-02T19:26:07Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"\nOn Tue, Jan 2, 2018 at 10:32 AM, Johannes Sixt <j6t@kdbg.org> wrote:\n> > Which makes me wonder: Why would --show-description have to error out\n> > silently? This is not 'git config' after all.\n\n> I don't have a strong opinion about this, and certainly wouldn't mind\n> adding an error message instead.\n\nAnd it would look like this:\n\n  -- >8 --\n\nSubject: [PATCH 4/4] branch: add '--show-description' option\n\n'git branch' has an option to edit a branch's description, but lacks\nthe option to show that description.\n\nTherefore, add a new '--show-description' option to do just that, as a\nmore user-friendly alternative to 'git config --get\nbranch.$branchname.description':\n\n  - it's shorter to type (both in the number of characters and the\n    number of TABs if using completion),\n  - works on the current branch without explicitly naming it,\n  - hides the implementation detail that branch descriptions are\n    stored in the config file, and\n  - errors out with a proper error message when the given branch\n    doesn't exist or has no description.\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n Documentation/git-branch.txt           |  6 +++++-\n builtin/branch.c                       | 39 +++++++++++++++++++++++++++++++---\n contrib/completion/git-completion.bash |  4 ++--\n t/t3200-branch.sh                      | 21 ++++++++++++++++++\n 4 files changed, 64 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex b3084c99c..e05c9e193 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -20,7 +20,7 @@ SYNOPSIS\n 'git branch' (-m | -M) [<oldbranch>] <newbranch>\n 'git branch' (-c | -C) [<oldbranch>] <newbranch>\n 'git branch' (-d | -D) [-r] <branchname>...\n-'git branch' --edit-description [<branchname>]\n+'git branch' (--edit-description | --show-description) [<branchname>]\n \n DESCRIPTION\n -----------\n@@ -226,6 +226,10 @@ start-point is either a local or remote-tracking branch.\n \t`request-pull`, and `merge` (if enabled)). Multi-line explanations\n \tmay be used.\n \n+--show-description::\n+\tShow the description of the branch previously set using\n+\t`--edit-description`.\n+\n --contains [<commit>]::\n \tOnly list branches which contain the specified commit (HEAD\n \tif not specified). Implies `--list`.\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 32531aa44..748a1a575 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -573,7 +573,7 @@ static int edit_branch_description(const char *branch_name)\n int cmd_branch(int argc, const char **argv, const char *prefix)\n {\n \tint delete = 0, rename = 0, copy = 0, force = 0, list = 0;\n-\tint reflog = 0, edit_description = 0;\n+\tint reflog = 0, edit_description = 0, show_description = 0;\n \tint quiet = 0, unset_upstream = 0;\n \tconst char *new_upstream = NULL;\n \tenum branch_track track;\n@@ -615,6 +615,8 @@ 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_BOOL(0, \"show-description\", &show_description,\n+\t\t\t N_(\"show the description for the branch\")),\n \t\tOPT__FORCE(&force, N_(\"force creation, move/rename, deletion\")),\n \t\tOPT_MERGED(&filter, N_(\"print only branches that are merged\")),\n \t\tOPT_NO_MERGED(&filter, N_(\"print only branches that are not merged\")),\n@@ -654,7 +656,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, prefix, options, builtin_branch_usage,\n \t\t\t     0);\n \n-\tif (!delete && !rename && !copy && !edit_description && !new_upstream && !unset_upstream && argc == 0)\n+\tif (!delete && !rename && !copy &&\n+\t    !edit_description && !show_description &&\n+\t    !new_upstream && !unset_upstream && argc == 0)\n \t\tlist = 1;\n \n \tif (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE || filter.points_at.nr ||\n@@ -662,7 +666,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tlist = 1;\n \n \tif (!!delete + !!rename + !!copy + !!new_upstream +\n-\t    list + unset_upstream + edit_description > 1)\n+\t    list + unset_upstream + edit_description + show_description > 1)\n \t\tusage_with_options(builtin_branch_usage, options);\n \n \tif (filter.abbrev == -1)\n@@ -737,6 +741,35 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \n \t\tif (edit_branch_description(branch_name))\n \t\t\treturn 1;\n+\t} else if (show_description) {\n+\t\tconst char *branch_name;\n+\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\tchar *description = NULL;\n+\n+\t\tif (!argc) {\n+\t\t\tif (filter.detached)\n+\t\t\t\tdie(_(\"cannot show description on detached HEAD\"));\n+\t\t\tbranch_name = head;\n+\t\t} else if (argc == 1)\n+\t\t\tbranch_name = argv[0];\n+\t\telse\n+\t\t\tdie(_(\"cannot show description of more than one branch\"));\n+\n+\t\tstrbuf_addf(&buf, \"refs/heads/%s\", branch_name);\n+\t\tif (!ref_exists(buf.buf)) {\n+\t\t\tstrbuf_release(&buf);\n+\t\t\treturn error(_(\"no branch named '%s'\"), branch_name);\n+\t\t}\n+\t\tstrbuf_reset(&buf);\n+\n+\t\tstrbuf_addf(&buf, \"branch.%s.description\", branch_name);\n+\t\tif (git_config_get_string(buf.buf, &description)) {\n+\t\t\tstrbuf_release(&buf);\n+\t\t\treturn error(_(\"no description for branch '%s'\"), branch_name);\n+\t\t}\n+\t\tprintf(\"%s\", description);\n+\t\tstrbuf_release(&buf);\n+\t\tfree(description);\n \t} else if (copy) {\n \t\tif (!argc)\n \t\t\tdie(_(\"branch name required\"));\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 3683c772c..0fcc13ea0 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1203,8 +1203,8 @@ _git_branch ()\n \t\t__gitcomp \"\n \t\t\t--color --no-color --verbose --abbrev= --no-abbrev\n \t\t\t--track --no-track --contains --no-contains --merged --no-merged\n-\t\t\t--set-upstream-to= --edit-description --list\n-\t\t\t--unset-upstream --delete --move --copy --remotes\n+\t\t\t--set-upstream-to= --edit-description --show-description\n+\t\t\t--list --unset-upstream --delete --move --copy --remotes\n \t\t\t--column --no-column --sort= --points-at\n \t\t\t\"\n \t\t;;\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 427ad490d..54e8dcbe2 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -1239,6 +1239,27 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '\n \ttest_must_fail env EDITOR=./editor git branch --edit-description\n '\n \n+test_expect_success '--show-description' '\n+\techo \"New contents\" >expect &&\n+\tgit branch --show-description >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--show-description on detached HEAD' '\n+\tgit checkout --detach &&\n+\ttest_when_finished git checkout master &&\n+\ttest_must_fail git branch --show-description\n+'\n+\n+test_expect_success '--show-description with no description' '\n+\tgit config --unset branch.master.description &&\n+\ttest_must_fail git branch --show-description master\n+'\n+\n+test_expect_success '--show-description on non-existing branch' '\n+\ttest_must_fail git branch --show-description no-such-branch\n+'\n+\n test_expect_success '--merged catches invalid object names' '\n \ttest_must_fail git branch --merged 0000000000000000000000000000000000000000\n '\n-- \n2.16.0.rc0.67.g3a46dbca7\n\n"}]}