Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Improve git current-branch #92

Open
salcode opened this issue Nov 19, 2018 · 2 comments
Open

Improve git current-branch #92

salcode opened this issue Nov 19, 2018 · 2 comments

Comments

@salcode
Copy link
Member

salcode commented Nov 19, 2018

See

# Outputs the name of the current branch
# Usage example: git pull origin $(git_current_branch)
# Using '--quiet' with 'symbolic-ref' will not cause a fatal error (128) if
# it's not a symbolic ref, but in a Git repo.
function git_current_branch() {
  local ref
  ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null)
  local ret=$?
  if [[ $ret != 0 ]]; then
    [[ $ret == 128 ]] && return  # no git repo.
    ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
  fi
  echo ${ref#refs/heads/}
}

source

@salcode
Copy link
Member Author

salcode commented May 16, 2019

I think we should deprecate

git FeCurrentBranchName

and change everything to use

git current-branch

@salcode salcode changed the title Improve FeCurrentBranchName Improve git current-branch May 16, 2019
@salcode
Copy link
Member Author

salcode commented Oct 2, 2020

As of Git 2.22 we can use

git branch --show-current

Do we want to refactor to use the new way but fallback to a pre-Git 2.22 way? e.g.

current-branch = "!f() {               \
	git                                \
		"branch --show-current"        \
		"2>/dev/null"                  \
	||                                 \
	git "rev-parse --abbrev-ref HEAD"; \
}; f"                                  \

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

No branches or pull requests

1 participant