Skip to content

Commit c6de920

Browse files
committed
gptel-context: add file path expansion to prevent duplicates
This prevents issues where the same file might be added multiple times due to different path representations (e.g., relative vs absolute paths, or paths with . and .. components). This resolves an issue where the following gptel-context-move-to-tail function would add the same file multiple times when the buffer-file-name and the file path in gptel-context differed due to path normalization. ;; Add hook to refile the modified files at the tail of context (defun gptel-context-move-to-tail () "Move the current buffer's file to the head of the context after saving." (when (and gptel-context (member (buffer-file-name) (apply #'append gptel-context))) (gptel-context-remove (buffer-file-name)) (gptel-add-file (buffer-file-name)))) (add-hook 'after-save-hook #'gptel-context-move-to-tail) (add-hook 'after-revert-hook #'gptel-context-move-to-tail)
1 parent 217e896 commit c6de920

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

gptel-context.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,12 @@ ACTION should be either `add' or `remove'."
253253
If PATH is a directory, recursively add all files in it. PATH should be
254254
readable as text."
255255
(interactive "fChoose file to add to context: ")
256-
(cond ((file-directory-p path)
257-
(gptel-context--add-directory path 'add))
258-
((gptel--file-binary-p path)
259-
(gptel-context--add-binary-file path))
260-
(t (gptel-context--add-text-file path))))
256+
(let ((path (expand-file-name path)))
257+
(cond ((file-directory-p path)
258+
(gptel-context--add-directory path 'add))
259+
((gptel--file-binary-p path)
260+
(gptel-context--add-binary-file path))
261+
(t (gptel-context--add-text-file path)))))
261262

262263
;;;###autoload (autoload 'gptel-add-file "gptel-context" "Add files to gptel's context." t)
263264
(defalias 'gptel-add-file #'gptel-context-add-file)

0 commit comments

Comments
 (0)