From afa266a7eae670a56ddafaedbb1d7fc6500cb923 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 2 Aug 2016 00:11:28 +0200 Subject: [PATCH] git completions: Fix cases without current branch Sometimes git just isn't on a branch. --- share/completions/git.fish | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index e2352c4a1..807ae3f4e 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -11,13 +11,16 @@ function __fish_git_commits end function __fish_git_branches - command git branch --no-color -a $argv ^/dev/null | string match -r -v ' -> ' | string trim -c "* " | string replace -r "^remotes/" "" + # In some cases, git can end up on no branch - e.g. with a detached head + # This will result in output like `* (no branch)` or a localized `* (HEAD detached at SHA)` + # The first `string match -v` filters it out because it's not useful as a branch argument + command git branch --no-color -a $argv ^/dev/null | string match -v '\* (*)' | string match -r -v ' -> ' | string trim -c "* " | string replace -r "^remotes/" "" end function __fish_git_unique_remote_branches # Allow all remote branches with one remote without the remote part # This is useful for `git checkout` to automatically create a remote-tracking branch - command git branch --no-color -a $argv ^/dev/null | string match -r -v ' -> ' | string trim -c "* " | string replace -r "^remotes/[^/]*/" "" | sort | uniq -u + command git branch --no-color -a $argv ^/dev/null | string match -v '\* (*)' | string match -r -v ' -> ' | string trim -c "* " | string replace -r "^remotes/[^/]*/" "" | sort | uniq -u end function __fish_git_tags