fix: Detect if in git workspace before attempting to get git diff

This commit is contained in:
Myzel394 2024-03-23 23:03:56 +01:00
parent f3ed362db8
commit ca82cb2d62
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -22,12 +22,14 @@ function _suggest_ai() {
local PROMPT="$SYSTEM_PROMPT"
if [[ "$ZSH_COPILOT_SEND_GIT_DIFF" == 'true' ]]; then
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."
fi
fi
fi
local response=$(curl 'https://api.openai.com/v1/chat/completions' \
--silent \