Skip to main content

fish_functions/fish_prompt: skip the Git prompt in bare directories

ID
2aad261
date
2026-04-11 22:36:43+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
682fc9d
message
fish_functions/fish_prompt: skip the Git prompt in bare directories

This avoids getting errors like:

> fatal: this operation must be run in a work tree

when I'm inside the `.git` directory.
changed files
1 file, 5 additions, 1 deletion

Changed files

fish_functions/fish_prompt.fish (5191) → fish_functions/fish_prompt.fish (5262)

diff --git a/fish_functions/fish_prompt.fish b/fish_functions/fish_prompt.fish
index f0fed20..42d362a 100644
--- a/fish_functions/fish_prompt.fish
+++ b/fish_functions/fish_prompt.fish
@@ -26,6 +26,11 @@ end
 # shell prompt.
 function print_git_information
     which git 2>&1 >/dev/null
+    
+    if git rev-parse --is-bare-repository >/dev/null
+        return
+    end
+    
     if [ $status = 0 ]
         set branch (git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
         if [ -n "$branch" ]
@@ -43,7 +48,6 @@ function print_git_information
             # Print an asterisk to indicate uncommitted changes, if there are any
             # Try git update-index --really-refresh?
             if ! git diff-index --quiet HEAD --
-              
                 printf "*"
             end