git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Rafael Ascensão" <rafa.almas@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Daniels Umanovskis <daniels@umanovskis.se>, git@vger.kernel.org
Subject: Re: [PATCH v2 1/1] branch: introduce --show-current display option
Date: Thu, 11 Oct 2018 16:43:19 +0100	[thread overview]
Message-ID: <20181011154319.GA6386@rigel> (raw)
In-Reply-To: <20181011003440.GD13853@sigill.intra.peff.net>

On Wed, Oct 10, 2018 at 08:34:40PM -0400, Jeff King wrote:
> It just seems like in its current form it might be in an uncanny valley
> where it is not quite scriptable plumbing, but not as informative as
> other porcelain.

I agree it feels a bit out of place, and still think that

    $ git branch --list HEAD

would be a good candidate to be taught how to print the current branch.

I suggested this in the previous iteration but either got lost in the
noise or was uninteresting. If the latter, I would love to receive
feedback on it.
https://public-inbox.org/git/20181010142423.GA3390@rigel/

Something like the following (not meant as a real patch), would show the
current branch when attached, (HEAD detached at hash) when detached, and
nothing if unborn branch.

This will also keep the current formatting git branch uses (which is
sliglty harder to parse). I view it as a plus. Otherwise people will
eventually start parsing it instead of using the recommended plumbing.

--
Cheers
Rafael Ascensão

-- >8 --
diff --git a/builtin/branch.c b/builtin/branch.c
index b67593288c..78a3de526c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -684,6 +684,17 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		if ((filter.kind & FILTER_REFS_BRANCHES) && filter.detached)
 			filter.kind |= FILTER_REFS_DETACHED_HEAD;
 		filter.name_patterns = argv;
+
+		while (*argv) {
+			if (!strcmp(*argv, "HEAD")) {
+				const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
+				skip_prefix(refname, "refs/heads/", &refname);
+				filter.name_patterns[argv - filter.name_patterns] = refname;
+				break;
+			}
+			argv++;
+		}
+
 		/*
 		 * If no sorting parameter is given then we default to sorting
 		 * by 'refname'. This would give us an alphabetically sorted

  reply	other threads:[~2018-10-11 15:43 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10 20:54 [PATCH v2 0/1] branch: introduce --show-current display option Daniels Umanovskis
2018-10-10 20:54 ` [PATCH v2 1/1] " Daniels Umanovskis
2018-10-11  0:34   ` Jeff King
2018-10-11 15:43     ` Rafael Ascensão [this message]
2018-10-11 16:36       ` Daniels Umanovskis
2018-10-11 17:51         ` Jeff King
2018-10-11 20:35           ` Rafael Ascensão
2018-10-11 20:46             ` Daniels Umanovskis
2018-10-11 20:53             ` Jeff King
2018-10-11 22:34               ` Rafael Ascensão
2018-10-11  6:54   ` Junio C Hamano
2018-10-11 17:29     ` Daniels Umanovskis
2018-10-11 17:52       ` Jeff King
2018-10-11 22:20     ` [PATCH v3] " Daniels Umanovskis
2018-10-11 23:15       ` Junio C Hamano
2018-10-11 23:31         ` Daniels Umanovskis
2018-10-12 13:33         ` [PATCH v4] " Daniels Umanovskis
2018-10-12 13:43           ` Eric Sunshine
2018-10-16 23:09             ` Junio C Hamano
2018-10-16 23:26               ` Eric Sunshine
2018-10-17 10:18                 ` Johannes Schindelin
2018-10-17 10:39                   ` Eric Sunshine
2018-10-18  9:51                     ` Johannes Schindelin
2018-10-18 14:19                       ` Eric Sunshine
2018-10-16  5:59           ` Junio C Hamano
2018-10-17  9:39           ` Rafael Ascensão
2018-10-17 17:36             ` Daniels Umanovskis
2018-10-11 22:53   ` [PATCH v2 1/1] " SZEDER Gábor
2018-10-11 22:56     ` SZEDER Gábor
2018-10-11 22:58       ` Daniels Umanovskis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181011154319.GA6386@rigel \
    --to=rafa.almas@gmail.com \
    --cc=daniels@umanovskis.se \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).