From ba8b6f3042dcfeecf74acedddeb1aa37c9a925bc Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 10 Jul 2015 22:13:31 -0400 Subject: magit-insert-staged-file: Fall back on HEAD files --- lisp/init-git.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/lisp/init-git.el b/lisp/init-git.el index 2c1b145..6281c4d 100644 --- a/lisp/init-git.el +++ b/lisp/init-git.el @@ -259,14 +259,22 @@ If checkout is non-nil, checkout file instead." (defun km/magit-insert-staged-file (&optional no-directory) "Select staged file to insert. + This is useful for referring to file names in commit messages. By default, the path for the file name is relative to the top directory of the repository. Remove the directory component from -the file name if NO-DIRECTORY is non-nil." +the file name if NO-DIRECTORY is non-nil. + +If there are no staged files, look instead at files that changed +in HEAD. These rules will usually offer the files of interest +while commiting, but this is not the case if you are amending a +commit with the \"--only\" flag and have staged files (i.e., this +command will still offer the staged files)." (interactive "P") (unless (magit-toplevel) (user-error "Not in git repo")) - (let* ((files (magit-staged-files)) + (let* ((files (or (magit-staged-files) + (magit-changed-files "HEAD"))) (file (if (= 1 (length files)) (car files) (completing-read "Staged file: " files nil t)))) -- cgit v1.2.3