diff options
| author | Carlo Sala <carlosalag@protonmail.com> | 2024-09-18 21:05:45 +0200 |
|---|---|---|
| committer | Carlo Sala <carlosalag@protonmail.com> | 2024-09-18 21:05:45 +0200 |
| commit | 99e2c31484bba519925a65b442d0516fc6e01c94 (patch) | |
| tree | 0fd275267e29042db8cc5b92c5210353dbf116f2 | |
| parent | e52598a5cc3c73fa907f83c84f4270fdaee9c930 (diff) | |
| download | zsh-99e2c31484bba519925a65b442d0516fc6e01c94.tar.gz zsh-99e2c31484bba519925a65b442d0516fc6e01c94.tar.bz2 zsh-99e2c31484bba519925a65b442d0516fc6e01c94.zip | |
feat(git): add `git_previous_branch` function
Closes #12538
| -rw-r--r-- | lib/git.zsh | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/git.zsh b/lib/git.zsh index 2ad5afe04..8237af751 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -162,6 +162,18 @@ function git_current_branch() { echo ${ref#refs/heads/} } +# Outputs the name of the previously checked out branch +# Usage example: git pull origin $(git_current_branch) +# rev-parse --symbolic-full-name @{-1} only prints if it is a branch +function git_previous_branch() { + local ref + ref=$(__git_prompt_git rev-parse --quiet --symbolic-full-name @{-1} 2> /dev/null) + local ret=$? + if [[ $ret != 0 ]] || [[ -z $ref ]]; then + return # no git repo or non-branch previous ref + fi + echo ${ref#refs/heads/} +} # Gets the number of commits ahead from remote function git_commits_ahead() { |
