From: Karl Chen <hidden> Date: 2016-06-15 22:45:51
How about an option to git-branch that just prints the name of the
current branch for scripts' sake? To replace:
git branch --no-color 2>/dev/null | perl -ne '/^[*] (.*)/ && print $1'
From: David Aguilar <hidden> Date: 2016-06-15 22:45:51
On Thu, Jan 1, 2009 at 7:28 PM, Karl Chen [off-list ref] wrote:
How about an option to git-branch that just prints the name of
the current branch for scripts' sake? To replace:
git branch --no-color 2>/dev/null | perl -ne '/^[*] (.*)/ && print $1'
The justification I've heard before is that 'git branch' is a
porcelain and thus we shouldn't rely on its output for scripting
purposes.
You might want to use 'git symbolic-ref' instead.
$ git symbolic-ref HEAD
refs/heads/master
$ git symbolic-ref HEAD | sed -e 's,refs/heads/,,'
master
--
David
Hi,
On Thu, Jan 1, 2009 at 10:28 PM, Karl Chen [off-list ref] wrote:
How about an option to git-branch that just prints the name of the
current branch for scripts' sake? To replace:
git branch --no-color 2>/dev/null | perl -ne '/^[*] (.*)/ && print $1'
FWIW, I had this in a stalled modification in a tree, it just add the
'-c' (as "current") option to git branch. Patch is mostly for the
record :/
The main trouble I have with pipe stuff is that it forks a process for
something that can be done natively. Previously, I was using awk(1) to
extract the current branch:
$ git branch | awk '/^\*/ {print $2}'
- Arnaud
On Fri, Jan 2, 2009 at 4:28 AM, Karl Chen [off-list ref] wrote:
How about an option to git-branch that just prints the name of the
current branch for scripts' sake? To replace:
git branch --no-color 2>/dev/null | perl -ne '/^[*] (.*)/ && print $1'
I tend to support your request especially that extracting the current
branch is something that is done regularly. Looking in my own scripts/aliases
and some of my colleagues, there are plenty of variation using Perl,
sed, awk, tr
and Python to extract the current branch.
Using git-symbolic-ref is not obvious, especially that the summary/name
of the man page is :
"git-symbolic-ref - Read and modify symbolic refs"
But the description is pretty clear :
"Given one argument, reads which branch head the given symbolic ref refers to
and outputs its path, relative to the .git/ directory. Typically you
would give HEAD
as the <name> argument to see on which branch your working tree is on."
But naturally, as a lazy user, you will pick git-branch especially
that's the tools is listed
with the most commonly used git commands with a very attractive description :
"branch List, create, or delete branches"
On an user perspective, having the option in git-branch seems more natural.
Just a comment,
--
-- Alexandre Dulaunoy (adulau) -- http://www.foo.be/
-- http://www.foo.be/cgi-bin/wiki.pl/Diary
-- "Knowledge can create problems, it is not through ignorance
-- that we can solve them" Isaac Asimov
On Fri, Jan 2, 2009 at 4:28 AM, Karl Chen [off-list ref] wrote:
quoted
How about an option to git-branch that just prints the name of the
current branch for scripts' sake? To replace:
git branch --no-color 2>/dev/null | perl -ne '/^[*] (.*)/ && print $1'
I tend to support your request especially that extracting the current
branch is something that is done regularly. Looking in my own scripts/aliases
and some of my colleagues, there are plenty of variation using Perl,
sed, awk, tr
and Python to extract the current branch.
Using git-symbolic-ref is not obvious, especially that the summary/name
of the man page is :
"git-symbolic-ref - Read and modify symbolic refs"
But the description is pretty clear :
"Given one argument, reads which branch head the given symbolic ref refers to
and outputs its path, relative to the .git/ directory. Typically you
would give HEAD
as the <name> argument to see on which branch your working tree is on."
But naturally, as a lazy user, you will pick git-branch especially
that's the tools is listed
with the most commonly used git commands with a very attractive description :
I dont think it has to do with lazyness. It has to do with the fact
that parsing git branch gives you a branch name that you can use an an
argument to many other git commands. Whereas git-symbolic-ref doesnt.
It requires additional post-processing that unless you are very git
aware is not at all clear. Like for instance in this thread the
recommendation is to use sed like this:
git symbolic-ref HEAD|sed s,refs/heads/,,
however, that makes me think "how do i do that on a windows box? does
the presence of git on a windows box mean that they will necessarily
have sed available? Can i rely on that? Can i rely on the sed rule
being sufficient? And what happens with this command if im not on a
branch at all? Well it turns out that git symbolic-ref HEAD *dies*
with a fatal error on this command. SO it probably should be:
git symbolic-ref HEAD 2>/dev/null|sed s,refs/heads/,,
but now its even less portable. Even if sed is available on windows
/dev/null isnt.
Id very much like a proper way to find the usable form of the branch
name as it would make a lot of thing easier. In particular requiring
people use pipes means that there is a portability issue with scripts.
How does one make this happen on a windows box for instance?
Id also very much like a way to find the "upstream" for a branch. IOW,
id very much like to know where I will push to if i issue a "git push"
command, or what i will merge if i do a git pull. There doesnt seem to
be an easy way to find this out currently. And its very useful
information.
Im coming from the point of view of someone trying to make the perl
build process a bit more "git aware". Unfortunately Perl has to build
out of the box on so many platforms that unix-centric tricks like huge
command pipes arent very helpful. They immediately fall down when you
start dealing with oddball platforms like Windows and VMS.
Yves
--
perl -Mre=debug -e "/just|another|perl|hacker/"