git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Introduce --current option to git-branch builtin command.
@ 2012-06-07  7:23 Kenta Murata (村田 賢太)
  2012-06-07  8:43 ` Vincent van Ravesteijn
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Kenta Murata (村田 賢太) @ 2012-06-07  7:23 UTC (permalink / raw)
  To: git

Introducing --current option to git-branch builtin command.
This option allows us to simply show the current branch name.

---
 builtin/branch.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 0e060f2..21e4675 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -19,6 +19,7 @@
 #include "column.h"

 static const char * const builtin_branch_usage[] = {
+       "git branch --current",
        "git branch [options] [-r | -a] [--merged | --no-merged]",
        "git branch [options] [-l] [-f] <branchname> [<start-point>]",
        "git branch [options] [-r] (-d | -D) <branchname>...",
@@ -711,7 +712,7 @@ int cmd_branch(int argc, const char **argv, const
char *prefix)
 {
        int delete = 0, rename = 0, force_create = 0, list = 0;
        int verbose = 0, abbrev = -1, detached = 0;
-       int reflog = 0, edit_description = 0;
+       int reflog = 0, edit_description = 0, show_current = 0;
        int quiet = 0;
        enum branch_track track;
        int kinds = REF_LOCAL_BRANCH;
@@ -768,6 +769,7 @@ int cmd_branch(int argc, const char **argv, const
char *prefix)
                        opt_parse_merge_filter, (intptr_t) "HEAD",
                },
                OPT_COLUMN(0, "column", &colopts, "list branches in columns"),
+               OPT_BOOLEAN(0, "current", &show_current, "show current
branch only"),
                OPT_END(),
        };

@@ -794,7 +796,7 @@ int cmd_branch(int argc, const char **argv, const
char *prefix)
        argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
                             0);

-       if (!delete && !rename && !edit_description && argc == 0)
+       if (!delete && !rename && !edit_description && !show_current
&& argc == 0)
                list = 1;

        if (!!delete + !!rename + !!force_create + !!list > 1)
@@ -852,6 +854,12 @@ int cmd_branch(int argc, const char **argv, const
char *prefix)
                        rename_branch(argv[0], argv[1], rename > 1);
                else
                        usage_with_options(builtin_branch_usage, options);
+       } else if (show_current) {
+               const char *branch_name = head;
+               if (detached) {
+                       branch_name = _("(no branch)");
+               }
+               printf("%s\n", branch_name);
        } else if (argc > 0 && argc <= 2) {
                if (kinds != REF_LOCAL_BRANCH)
                        die(_("-a and -r options to 'git branch' do
not make sense with a branch name"));


-- 
Kenta Murata

COOKPAD Inc.
http://cookpad.com

MG Shirokanedai Bld. 5F, 5-12-7, Shirokanedai
Minato, Tokyo, 180-0071 Japan

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-06-07 17:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-07  7:23 [PATCH] Introduce --current option to git-branch builtin command Kenta Murata (村田 賢太)
2012-06-07  8:43 ` Vincent van Ravesteijn
2012-06-07 17:11   ` Junio C Hamano
2012-06-07 11:18 ` konglu
2012-06-07 11:23 ` Nguyen Thai Ngoc Duy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).