From 6ac5c25e7795338bd0eef4fd1469f7eec666b947 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 7 Mar 2012 12:03:10 -0500 Subject: [PATCH] Fix Git indicators in submodules, close #18 --- plugins/git/functions/git-info | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/git/functions/git-info b/plugins/git/functions/git-info index 5d0e7d3a..8f31a75f 100644 --- a/plugins/git/functions/git-info +++ b/plugins/git/functions/git-info @@ -5,12 +5,36 @@ # Sorin Ionescu # +# Gets the path to the Git directory. +function _git-dir() { + local git_root="$(git-root)" + local git_dir_or_file="${git_root}/.git" + local git_dir + + if [[ ! -d "$git_root" ]]; then + return 1 + fi + + if [[ -f "$git_dir_or_file" ]]; then + git_dir="${${${$(<"$git_dir_or_file")}[(fr)gitdir:*]}#gitdir: }" + else + git_dir="$git_dir_or_file" + fi + + if [[ -d "$git_dir" ]]; then + print "$git_dir" + return 0 + fi + + return 1 +} + # Gets the Git special action (am, merge, rebase, etc.). # Borrowed from vcs_info and edited. function _git-action() { local action='' local action_dir - local git_dir="$(git-root)/.git" + local git_dir="$(_git-dir)" for action_dir in \ "${git_dir}/rebase-apply" \ @@ -200,7 +224,7 @@ function git-info() { zformat -f commit_formatted "$commit_format" "c:$commit_short" # Stashed - if [[ -f "$(git-root)/.git/refs/stash" ]]; then + if [[ -f "$(_git-dir)/refs/stash" ]]; then stashed="$(git stash list 2>/dev/null | wc -l)" zstyle -s ':omz:plugin:git:prompt' stashed 'stashed_format' zformat -f stashed_formatted "$stashed_format" "S:$stashed"