|
3 hari lalu | |
---|---|---|
Dockerfile | 4 hari lalu | |
Makefile | 4 hari lalu | |
README.md | 3 hari lalu | |
ai-commit.sh | 3 hari lalu | |
git_commit_ai.py | 4 hari lalu | |
git_rebase_ai.py | 4 hari lalu | |
git_reword_ai.py | 4 hari lalu |
This tool leverages the Google Gemini API to assist with common Git tasks, including generating commit messages, suggesting fixup
operations for interactive rebases, and suggesting reword
operations with improved commit messages.
fixup
operations for commits that appear to be minor corrections to their predecessors. Can optionally attempt to perform the rebase automatically.reword
operations) for those that don't follow conventions or lack clarity. Can optionally attempt to perform the rebase automatically.commit
or rebase
.Build the Docker Image: You can use the provided Makefile:
make build
Or build manually:
docker build -t docker.senomas.com/commit:1.0 .
(Note: The tag docker.senomas.com/commit:1.0
is used by default. You can override it using the DOCKER_IMAGE_NAME
environment variable if needed, e.g., export DOCKER_IMAGE_NAME=my-custom-image:latest
.)
Set Environment Variables: Export your Gemini API key:
export GEMINI_API_KEY='YOUR_API_KEY'
Optionally, set the Gemini model to use (defaults to gemini-1.5-flash-latest
if not set):
export GEMINI_MODEL='gemini-1.5-pro-latest' # Or another compatible model
(Replace YOUR_API_KEY
with your actual key. Add these lines to your shell profile (e.g., .bashrc
, .zshrc
, config.fish
) for persistence.)
You can use the Makefile
for convenience or run the ai-commit.sh
script directly.
Generate Commit Message: Stage changes (git add ...
), then run:
make commit
To amend the previous commit:
make commit ARGS="-a"
Suggest Rebase Fixups: Compares current branch to upstream/main
by default.
make rebase
To compare against a different upstream reference and only show instructions (no auto-rebase):
make rebase UPSTREAM_REF="origin/develop" ARGS="--instruct"
Suggest Rebase Rewords: Compares current branch to upstream/main
by default.
make reword
To compare against a different upstream reference and only show instructions (no auto-rebase):
make reword UPSTREAM_REF="origin/develop" ARGS="--instruct"
ai-commit.sh
DirectlyThe ai-commit.sh
script acts as the main entry point, selecting the appropriate Python script based on flags.
Generate Commit Message (Default):
Stage changes (git add ...
), then run:
./ai-commit.sh
To amend the previous commit:
./ai-commit.sh -a
# or
./ai-commit.sh --amend
Suggest Rebase Fixups (-r
flag):
# Compare against upstream/main (default) and attempt auto-rebase
./ai-commit.sh -r
# Compare against origin/develop and attempt auto-rebase
./ai-commit.sh -r origin/develop
# Compare against upstream/main, show instructions only (no auto-rebase)
./ai-commit.sh -r --instruct
# Compare against origin/develop, show instructions only
./ai-commit.sh -r origin/develop --instruct
Suggest Rebase Rewords (-w
flag):
# Compare against upstream/main (default) and attempt auto-reword
./ai-commit.sh -w
# Compare against origin/develop and attempt auto-reword
./ai-commit.sh -w origin/develop
# Compare against upstream/main, show instructions only (no auto-reword)
./ai-commit.sh -w --instruct
# Compare against origin/develop, show instructions only
./ai-commit.sh -w origin/develop --instruct
Commit:
git add ...
).make commit
or ./ai-commit.sh
(optionally with -a
).y/n
).git commit
(or git commit --amend
).Rebase Fixup:
make rebase [UPSTREAM_REF=...] [ARGS=...]
or ./ai-commit.sh -r [upstream_ref] [--instruct]
.upstream_ref
(e.g., upstream/main
) and your current branch (HEAD
).fixup
operations.--instruct
is NOT used:
your-branch-backup-TIMESTAMP
).git rebase -i
non-interactively using a generated script to apply the fixups.--instruct
IS used:
Rebase Reword:
make reword [UPSTREAM_REF=...] [ARGS=...]
or ./ai-commit.sh -w [upstream_ref] [--instruct]
.upstream_ref
and HEAD
.reword
operations with the new messages.--instruct
is NOT used:
git rebase -i
non-interactively using generated scripts to mark commits for reword and supply the new messages.--instruct
IS used:
Makefile
provides simple targets that call ai-commit.sh
with appropriate flags and arguments.ai-commit.sh
script determines which Python script to run based on the presence of -r
(rebase fixup) or -w
(rebase reword) flags. If neither is present, it defaults to commit message generation.git_commit_ai.py
, git_rebase_ai.py
, or git_reword_ai.py
) inside the specified Docker container (docker.senomas.com/commit:1.0
by default).pwd
) as /repo
, .gitconfig
, and .git-credentials
(read-only) into the container.GEMINI_API_KEY
and GEMINI_MODEL
environment variables into the container.-a
, --amend
, upstream_ref
, --instruct
) to the Python script.git_commit_ai.py
:
--amend
).git diff --staged
or git diff HEAD~1 --staged
).git ls-tree
).Request content for file: ...
), to generate a commit message.git commit
.git_rebase_ai.py
:
upstream_ref
, --instruct
).git merge-base
).REQUEST_FILES: [...]
), to suggest FIXUP: ... INTO ...
lines.--instruct
, creates backup, confirms, and attempts automatic rebase using GIT_SEQUENCE_EDITOR
script to change pick
to f
. Handles potential failures and aborts.--instruct
, prints manual instructions.git_reword_ai.py
:
upstream_ref
, --instruct
).REWORD: ... NEW_MESSAGE: ... END_MESSAGE
blocks.--instruct
, creates backup, confirms, and attempts automatic rebase using GIT_SEQUENCE_EDITOR
(changes pick
to r
) and GIT_EDITOR
(supplies new message via env var) scripts. Handles potential failures and aborts.--instruct
, prints manual instructions with new messages.ai-commit.sh
: Main entry script, selects Python script based on flags.git_commit_ai.py
: Handles AI commit message generation.git_rebase_ai.py
: Handles AI rebase fixup suggestions and automation.git_reword_ai.py
: Handles AI rebase reword suggestions and automation.Dockerfile
: Defines the Docker image environment.Makefile
: Provides convenience targets (build
, commit
, rebase
, reword
).README.md
: This file.