Subject: Re: [PATCH v4] branch: introduce --show-current display option

From: Rafael Ascensão <[email-masked]>
Date: Wed, 17 Oct 2018 10:39:43 +0100

On Fri, Oct 12, 2018 at 03:33:21PM +0200, Daniels Umanovskis wrote:
> Intended both for scripting and interactive/informative use.
> Unlike git branch --list, no filtering is needed to just get the
> branch name.

Are we going forward with advertising this as a scriptable alternative?

> +	} else if (show_current) {
> +		print_current_branch_name();
> +		return 0;

Do we need the slightly different check done in
print_current_branch_name() ? A very similar check is already done early
in cmd_branch.

builtin/branch.c:671
	head = resolve_refdup("HEAD", 0, &head_oid, NULL);
	if (!head)
		die(_("Failed to resolve HEAD as a valid ref."));
	if (!strcmp(head, "HEAD"))
		filter.detached = 1;
	else if (!skip_prefix(head, "refs/heads/", &head))
		die(_("HEAD not found below refs/heads!"));

What's being proposed can be achieved with

+	} else if (show_current) {
+		if (!filter.detached)
+			puts(head);
+		return 0;

without failing tests.

--
Cheers,
Rafael Ascensão