From 753884a1162c242b6d1c55b2af0a9e264f21b625 Mon Sep 17 00:00:00 2001 From: hiteshrepo Date: Sun, 8 Jun 2025 20:22:50 +0530 Subject: [PATCH 1/2] update tool to invoke git-commit upon user's permit --- examples/git-commit.gpt | 61 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/examples/git-commit.gpt b/examples/git-commit.gpt index 60ee2dd3..35ab340e 100644 --- a/examples/git-commit.gpt +++ b/examples/git-commit.gpt @@ -1,19 +1,68 @@ -tools: gitstatus, sys.abort +Tools: gitstatus, gitcommit, sys.abort, sys.read +Chat: true -Create well formed git commit message based of off the currently staged file +Create well formed git commit message based off of the currently staged file contents. The message should convey why something was changed and not what changed. Use the well known format that has the prefix chore, fix, etc. -Only include changed to *.go files and any change to the go.mod file. Exclude -the go.sum file. +Generate commit message based on all staged changes, except for changes to this script itself (commitmessager.gpt). Do not use markdown format for the output. If there are no changes abort. +After generating the commit message, ask for user approval. Only proceed with +the git commit if the user responds with 'yes' or 'y' (case insensitive). + +First call gitstatus to check for changes. If no changes found, call sys.abort. + +Then analyze the output from gitstatus and generate an appropriate conventional commit message. + +Display the generated commit message and ask for user confirmation using sys.read. + +If user confirms with 'yes' or 'y', call gitcommit with the message parameter. + +--- +Name: gitstatus + +#!/bin/sh + +# Check if there are any staged changes excluding this script +git diff --staged --name-only | grep -v "git-commit.gpt" > /dev/null + +if [ $? -ne 0 ]; then + echo "No staged changes found (excluding git-commit.gpt)" + exit 1 +fi + +# Show staged changes excluding this script +git diff --staged -- . ':!git-commit.gpt' + --- -name: gitstatus +Name: gitcommit +Param: message: The commit message to use #!/bin/sh -git diff --staged +# GPTScript passes parameters as environment variables +# Try to get the message from different sources +COMMIT_MESSAGE="${MESSAGE}" +if [ -z "${COMMIT_MESSAGE}" ]; then + COMMIT_MESSAGE="${message}" +fi +if [ -z "${COMMIT_MESSAGE}" ]; then + COMMIT_MESSAGE="$1" +fi + +# Check if message parameter is empty or unset +if [ -z "${COMMIT_MESSAGE}" ]; then + echo "Error: No commit message provided." + echo "Debug: MESSAGE env var: '${MESSAGE}'" + echo "Debug: message param: '${message}'" + echo "Debug: \$1: '$1'" + exit 1 +fi + +# Proceed with the commit +echo "Committing with message: ${COMMIT_MESSAGE}" +git commit -m "${COMMIT_MESSAGE}" From fdb2793ce808384403bfaa891fef094e9b5830aa Mon Sep 17 00:00:00 2001 From: hiteshrepo Date: Sun, 8 Jun 2025 20:28:43 +0530 Subject: [PATCH 2/2] fix typo --- examples/git-commit.gpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/git-commit.gpt b/examples/git-commit.gpt index 35ab340e..bf1b926c 100644 --- a/examples/git-commit.gpt +++ b/examples/git-commit.gpt @@ -5,7 +5,7 @@ Create well formed git commit message based off of the currently staged file contents. The message should convey why something was changed and not what changed. Use the well known format that has the prefix chore, fix, etc. -Generate commit message based on all staged changes, except for changes to this script itself (commitmessager.gpt). +Generate commit message based on all staged changes, except for changes to this script itself (git-commit.gpt). Do not use markdown format for the output.