Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch name for gs #15

Open
powelleric opened this issue Sep 21, 2017 · 5 comments
Open

Branch name for gs #15

powelleric opened this issue Sep 21, 2017 · 5 comments
Labels

Comments

@powelleric
Copy link

I was getting some funny output from gs. The branch was always listed as 'branch'. Looking in the function, it seems like the answer is to use the fourth field from cut.

~/manager-dev > gs
# On branch: branch
#
#
➤ Untracked files:
#
#       untracked: [1] metadata.cache
#       untracked: [2] schema.cache
#

Changing line 19 from
echo $branch_name|cut -d ' ' -f3
to:
echo $branch_name|cut -d ' ' -f4
seems to have fixed it.

Seems to make sense because when you parse the first line of git status, the branch name is the fourth column of that line: # On branch master

@shinriyo
Copy link
Owner

@powelleric really? if I changed echo $branch_name|cut -d ' ' -f4 like your code,
Branch name wasn't shown..

@powelleric
Copy link
Author

Thanks for your response, @shinriyo. Great avatar BTW!

Hmm, I wonder if we could have different versions of git or something....

What does it look like for you to do git status | head -1?

Here is what is happening for me.


> git status | head -1
# On branch standalone
> git status | head -1 | cut -d " " -f 3
branch
> git status | head -1 | cut -d " " -f 4
standalone

If it turns out that different git versions are causing this, we could try something like this: git status | head -1 | sed 's/.*branch //'. However, I think Mac uses its own sed by default, not GNU sed and I wonder if the arguments are the same.

@aweibell
Copy link

I don't get the hash in front of my output:

➤ git status | head -1
On branch master

That means cut ... -f 3 is correct for my git output.

➤ git --version
git version 2.7.4

@powelleric
Copy link
Author

@aweibell I figured it was going to be something along these lines. I can actually observe both behaviors between my Mac and Ubuntu server. (The Mac doesn't have breeze on it yet so I didn't realize this until now.)

I've proposed a solution below that uses fishs internal string function.

Mac

> git --version
git version 2.3.2 (Apple Git-55)
> git status | head -1
On branch develop
> git status | head -1 | string replace --regex '.*On branch ' ''
develop

Ubuntu

> git --version                                                                                                                                                                                                                                           
git version 2.13.0
> git status | head -1
# On branch standalone
> git status | head -1 | string replace --regex '.*On branch ' ''
standalone

@shinriyo shinriyo added the bug label Apr 28, 2020
@bingocaller
Copy link
Contributor

I think this has been resolved by #38; it uses git branch --show-current, which was added in git v2.22.0, AFAIK.
@powelleric can you confirm/deny that gs works for you now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants