{"thread":{"id":"30733","subject":"[PATCH] Introduce --current option to git-branch builtin command.","startedAt":"2012-06-07T07:23:14Z","lastAt":"2012-06-07T17:11:47Z","messageCount":5,"participants":["Kenta Murata (村田 賢太)","Vincent van Ravesteijn","konglu@minatec.inpg.fr","Nguyen Thai Ngoc Duy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"193033","messageId":"CAECJ0BmcxeS1q8bw4hN9jDja2g8GGzNyN_v7jC3ehOW70x6CRA@mail.gmail.com","threadId":"30733","inReplyTo":null,"subject":"[PATCH] Introduce --current option to git-branch builtin command.","fromName":"Kenta Murata (村田 賢太)","fromEmail":"mrkn@cookpad.com","sentAt":"2012-06-07T07:23:14Z","receivedAt":"2012-06-07T07:23:14Z","isPatch":true,"sender":{"key":"mrkn@cookpad.com","avatar":null},"body":"Introducing --current option to git-branch builtin command.\nThis option allows us to simply show the current branch name.\n\n---\n builtin/branch.c |   12 ++++++++++--\n 1 file changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 0e060f2..21e4675 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -19,6 +19,7 @@\n #include \"column.h\"\n\n static const char * const builtin_branch_usage[] = {\n+       \"git branch --current\",\n        \"git branch [options] [-r | -a] [--merged | --no-merged]\",\n        \"git branch [options] [-l] [-f] <branchname> [<start-point>]\",\n        \"git branch [options] [-r] (-d | -D) <branchname>...\",\n@@ -711,7 +712,7 @@ int cmd_branch(int argc, const char **argv, const\nchar *prefix)\n {\n        int delete = 0, rename = 0, force_create = 0, list = 0;\n        int verbose = 0, abbrev = -1, detached = 0;\n-       int reflog = 0, edit_description = 0;\n+       int reflog = 0, edit_description = 0, show_current = 0;\n        int quiet = 0;\n        enum branch_track track;\n        int kinds = REF_LOCAL_BRANCH;\n@@ -768,6 +769,7 @@ int cmd_branch(int argc, const char **argv, const\nchar *prefix)\n                        opt_parse_merge_filter, (intptr_t) \"HEAD\",\n                },\n                OPT_COLUMN(0, \"column\", &colopts, \"list branches in columns\"),\n+               OPT_BOOLEAN(0, \"current\", &show_current, \"show current\nbranch only\"),\n                OPT_END(),\n        };\n\n@@ -794,7 +796,7 @@ int cmd_branch(int argc, const char **argv, const\nchar *prefix)\n        argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,\n                             0);\n\n-       if (!delete && !rename && !edit_description && argc == 0)\n+       if (!delete && !rename && !edit_description && !show_current\n&& argc == 0)\n                list = 1;\n\n        if (!!delete + !!rename + !!force_create + !!list > 1)\n@@ -852,6 +854,12 @@ int cmd_branch(int argc, const char **argv, const\nchar *prefix)\n                        rename_branch(argv[0], argv[1], rename > 1);\n                else\n                        usage_with_options(builtin_branch_usage, options);\n+       } else if (show_current) {\n+               const char *branch_name = head;\n+               if (detached) {\n+                       branch_name = _(\"(no branch)\");\n+               }\n+               printf(\"%s\\n\", branch_name);\n        } else if (argc > 0 && argc <= 2) {\n                if (kinds != REF_LOCAL_BRANCH)\n                        die(_(\"-a and -r options to 'git branch' do\nnot make sense with a branch name\"));\n\n\n-- \nKenta Murata\n\nCOOKPAD Inc.\nhttp://cookpad.com\n\nMG Shirokanedai Bld. 5F, 5-12-7, Shirokanedai\nMinato, Tokyo, 180-0071 Japan\n"},{"id":"193042","messageId":"4FD069A5.1040905@lyx.org","threadId":"30733","inReplyTo":"CAECJ0BmcxeS1q8bw4hN9jDja2g8GGzNyN_v7jC3ehOW70x6CRA@mail.gmail.com","subject":"Re: [PATCH] Introduce --current option to git-branch builtin command.","fromName":"Vincent van Ravesteijn","fromEmail":"vfr@lyx.org","sentAt":"2012-06-07T08:43:17Z","receivedAt":"2012-06-07T08:43:17Z","isPatch":true,"sender":{"key":"vfr@lyx.org","avatar":"https://avatars.githubusercontent.com/u/687868?v=4"},"body":"Op 7-6-2012 9:23, Kenta Murata (村田 賢太) schreef:\n> Introducing --current option to git-branch builtin command.\n> This option allows us to simply show the current branch name.\n\nI don't know whether we would need such an option. To me it feels this \nis a missing option indeed, but at the same time you can use 'git \nstatus' or 'git branch' to see the current branch. It might be useful in \ncase you have lots of branches and lots of untracked files, but in that \ncase \"git status | head -n1\" or \"git branch | grep '*'\" would do the trick.\n\n>\n> ---\n>   builtin/branch.c |   12 ++++++++++--\n>   1 file changed, 10 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index 0e060f2..21e4675 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -19,6 +19,7 @@\n>   #include \"column.h\"\n>\n>   static const char * const builtin_branch_usage[] = {\n> +       \"git branch --current\",\n>          \"git branch [options] [-r | -a] [--merged | --no-merged]\",\n>          \"git branch [options] [-l] [-f]<branchname>  [<start-point>]\",\n>          \"git branch [options] [-r] (-d | -D)<branchname>...\",\n\ngit-branch has four modes: 'list', 'create', 'delete', and 'rename'. \nIsn't --current then just another option to the 'list'-mode?  Then it \nwould be  something like:\n\n\"git branch [options] [-r | -a] [--current] [--merged | --no-merged]\"\n\n\n> @@ -794,7 +796,7 @@ int cmd_branch(int argc, const char **argv, const\n> char *prefix)\n>          argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,\n>                               0);\n>\n> -       if (!delete&&  !rename&&  !edit_description&&  argc == 0)\n> +       if (!delete&&  !rename&&  !edit_description&&  !show_current\n> &&  argc == 0)\n>                  list = 1;\n\nIn line with what I wrote above, show_current should imply 'list'-mode.\n\n>\n>          if (!!delete + !!rename + !!force_create + !!list>  1)\n> @@ -852,6 +854,12 @@ int cmd_branch(int argc, const char **argv, const\n> char *prefix)\n>                          rename_branch(argv[0], argv[1], rename>  1);\n>                  else\n>                          usage_with_options(builtin_branch_usage, options);\n> +       } else if (show_current) {\n> +               const char *branch_name = head;\n> +               if (detached) {\n> +                       branch_name = _(\"(no branch)\");\n> +               }\n> +               printf(\"%s\\n\", branch_name);\n>          } else if (argc>  0&&  argc<= 2) {\n>                  if (kinds != REF_LOCAL_BRANCH)\n>                          die(_(\"-a and -r options to 'git branch' do\n> not make sense with a branch name\"));\n\nIf '--current' implies the 'list'-mode, it would use 'print_ref_list'. \nThere already is code in print_ref_list to detect whether a branch is \nthe current one, it outputs the branch list in a formatted way, it takes \ncare of 'columns', so wouldn't it be better to modify that code to only \nprint the current branch ?\n\nVincent\n"},{"id":"193051","messageId":"20120607131800.Horde.yryrAXwdC4BP0I3o4goH21A@webmail.minatec.grenoble-inp.fr","threadId":"30733","inReplyTo":"CAECJ0BmcxeS1q8bw4hN9jDja2g8GGzNyN_v7jC3ehOW70x6CRA@mail.gmail.com","subject":"Re: [PATCH] Introduce --current option to git-branch builtin command.","fromName":"","fromEmail":"konglu@minatec.inpg.fr","sentAt":"2012-06-07T11:18:00Z","receivedAt":"2012-06-07T11:18:00Z","isPatch":true,"sender":{"key":"konglu@minatec.inpg.fr","avatar":null},"body":"\n\"Kenta Murata (?? ??)\" <mrkn@cookpad.com> a écrit :\n\n> Introducing --current option to git-branch builtin command.\n> This option allows us to simply show the current branch name.\n\nIn which case would you need to use this option ? Running 'git\nbranch' is faster and would do the same thing. Even though you\nhave a lot of branches as Vincent said (and so the output of\n'git branch' would be quite verbose), I do not think that adding\nan option just for that is relevant.\n\nLucien Kong\n"},{"id":"193052","messageId":"CACsJy8Bn2S4UT5ctMBNNB_Wf8J00nGw38F6O0P-jb3dpXEcs9w@mail.gmail.com","threadId":"30733","inReplyTo":"CAECJ0BmcxeS1q8bw4hN9jDja2g8GGzNyN_v7jC3ehOW70x6CRA@mail.gmail.com","subject":"Re: [PATCH] Introduce --current option to git-branch builtin command.","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-06-07T11:23:19Z","receivedAt":"2012-06-07T11:23:19Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Jun 7, 2012 at 2:23 PM, Kenta Murata (村田 賢太) <mrkn@cookpad.com> wrote:\n> Introducing --current option to git-branch builtin command.\n> This option allows us to simply show the current branch name.\n\nor just add an alias that does \"git symbolic-ref HEAD\" (append \"|sed\ns,^refs/heads,,\" if you don't like full ref)\n-- \nDuy\n"},{"id":"193081","messageId":"7v4nqnjbcc.fsf@alter.siamese.dyndns.org","threadId":"30733","inReplyTo":"4FD069A5.1040905@lyx.org","subject":"Re: [PATCH] Introduce --current option to git-branch builtin command.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-06-07T17:11:47Z","receivedAt":"2012-06-07T17:11:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Vincent van Ravesteijn <vfr@lyx.org> writes:\n\n> git-branch has four modes: 'list', 'create', 'delete', and\n> rename'. Isn't --current then just another option to the 'list'-mode?\n\nThat is how I would look at it.  We can think of various ways that\n\"list\" can be filtered, and matching by name is one that we have an\nimplementation for.  \"Current-only\" could be another one.\n\n> If '--current' implies the 'list'-mode, it would use\n> print_ref_list'. There already is code in print_ref_list to detect\n> whether a branch is the current one, it outputs the branch list in a\n> formatted way, it takes care of 'columns', so wouldn't it be better to\n> modify that code to only print the current branch ?\n\nExactly.\n"}]}