summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-07-10 22:13:31 -0400
committerKyle Meyer <kyle@kyleam.com>2015-07-10 22:13:31 -0400
commitba8b6f3042dcfeecf74acedddeb1aa37c9a925bc (patch)
tree677ea96ef5dcc88cc82a5de57b0f2b26b704d26c
parente880a34d1af5fc4be480900075342a38131668da (diff)
downloademacs.d-ba8b6f3042dcfeecf74acedddeb1aa37c9a925bc.tar.gz
magit-insert-staged-file: Fall back on HEAD files
-rw-r--r--lisp/init-git.el12
1 files changed, 10 insertions, 2 deletions
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))))