From ca82cb2d6235f7ee97e0ff4033feb341859616f0 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 23 Mar 2024 23:03:56 +0100 Subject: [PATCH] fix: Detect if in git workspace before attempting to get git diff --- zsh-copilot.plugin.zsh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zsh-copilot.plugin.zsh b/zsh-copilot.plugin.zsh index a2bfba1..19f3352 100644 --- a/zsh-copilot.plugin.zsh +++ b/zsh-copilot.plugin.zsh @@ -22,10 +22,12 @@ function _suggest_ai() { local PROMPT="$SYSTEM_PROMPT" if [[ "$ZSH_COPILOT_SEND_GIT_DIFF" == 'true' ]]; then - local git_diff=$(git diff --no-color | xargs | sed 's/ /\$/g' | xargs | sed 's/ /$/g') + if [[ "git rev-parse --is-inside-work-tree" == 'true' ]]; then + local git_diff=$(git diff --no-color | xargs | sed 's/ /\$/g' | xargs | sed 's/ /$/g') - if [[ $? -eq 0 ]]; then - PROMPT="$PROMPT; This is the git diff (newlines separated by dollar signs): $git_diff;; You may provide a git commit message if the user is trying to commit changes. Do not say something like 'Your commit message' or 'Your commit message here'. Just provide the commit message." + if [[ $? -eq 0 ]]; then + PROMPT="$PROMPT; This is the git diff (newlines separated by dollar signs): $git_diff;; You may provide a git commit message if the user is trying to commit changes. Do not say something like 'Your commit message' or 'Your commit message here'. Just provide the commit message." + fi fi fi