[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ellama bc30d6c770 1/3: Fix commit message generation fo
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ellama bc30d6c770 1/3: Fix commit message generation for partial commits |
Date: |
Sun, 14 Jul 2024 15:57:55 -0400 (EDT) |
branch: externals/ellama
commit bc30d6c770cc4c3477e99cbafe2140bf4f66755c
Author: Sergey Kostyaev <sskostyaev@gmail.com>
Commit: Sergey Kostyaev <sskostyaev@gmail.com>
Fix commit message generation for partial commits
This commit adds two new functions: `ellama--diff-cached` and
`ellama--diff`. These functions generate the diff output for staged
and unstaged changes respectively. The existing
`ellama-generate-commit-message` function now utilizes these new
functions to determine the appropriate diff to use.
---
ellama.el | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 51 insertions(+), 13 deletions(-)
diff --git a/ellama.el b/ellama.el
index 0d937297fe..d202700d4e 100644
--- a/ellama.el
+++ b/ellama.el
@@ -1642,24 +1642,62 @@ the full response text when the request completes (with
BUFFER current)."
(text (buffer-substring-no-properties beg end)))
(ellama-stream text)))
+(defun ellama--diff-cached ()
+ "Diff staged."
+ (let* ((default-directory
+ (if (string= ".git"
+ (car (reverse
+ (cl-remove
+ ""
+ (file-name-split default-directory)
+ :test #'string=))))
+ (file-name-parent-directory default-directory)
+ default-directory))
+ (vc-git-diff-switches "--cached")
+ (diff (with-temp-buffer
+ (vc-diff-internal
+ nil (vc-deduce-fileset t) nil nil nil (current-buffer))
+ (buffer-substring-no-properties (point-min) (point-max)))))
+ (if (string-empty-p diff)
+ nil
+ diff)))
+
+(defun ellama--diff ()
+ "Diff unstaged."
+ (let* ((default-directory
+ (if (string= ".git"
+ (car (reverse
+ (cl-remove
+ ""
+ (file-name-split default-directory)
+ :test #'string=))))
+ (file-name-parent-directory default-directory)
+ default-directory))
+ (vc-git-diff-switches t)
+ (diff (with-temp-buffer
+ (vc-diff-internal
+ nil (vc-deduce-fileset t) nil nil nil (current-buffer))
+ (buffer-substring-no-properties (point-min) (point-max)))))
+ (if (string-empty-p diff)
+ nil
+ diff)))
+
;;;###autoload
(defun ellama-generate-commit-message ()
"Generate commit message based on diff."
(interactive)
(save-window-excursion
- (let* ((default-directory
- (if (string= ".git"
- (car (reverse
- (cl-remove
- ""
- (file-name-split default-directory)
- :test #'string=))))
- (file-name-parent-directory default-directory)
- default-directory))
- (diff (with-temp-buffer
- (vc-diff-internal
- nil (vc-deduce-fileset t) nil nil nil (current-buffer))
- (buffer-substring-no-properties (point-min) (point-max)))))
+ (when-let* ((default-directory
+ (if (string= ".git"
+ (car (reverse
+ (cl-remove
+ ""
+ (file-name-split default-directory)
+ :test #'string=))))
+ (file-name-parent-directory default-directory)
+ default-directory))
+ (diff (or (ellama--diff-cached)
+ (ellama--diff))))
(ellama-stream
(format ellama-generate-commit-message-template diff)))))