diff options
author | Kyle Meyer <kyle@kyleam.com> | 2015-07-14 23:12:44 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2015-07-14 23:12:44 -0400 |
commit | 15450af548e1b291b1742039ec1f5013c7f63db1 (patch) | |
tree | 1a18762f6b1b87b7b111574a416f04e8bee4c93d | |
parent | ba8b6f3042dcfeecf74acedddeb1aa37c9a925bc (diff) | |
download | emacs.d-15450af548e1b291b1742039ec1f5013c7f63db1.tar.gz |
Rewrite magit-insert-staged-file
-rw-r--r-- | lisp/init-git.el | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el index 6281c4d..24c4d8d 100644 --- a/lisp/init-git.el +++ b/lisp/init-git.el @@ -271,14 +271,15 @@ 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 (or (magit-staged-files) - (magit-changed-files "HEAD"))) - (file (if (= 1 (length files)) - (car files) - (completing-read "Staged file: " files nil t)))) - (insert (if no-directory (file-name-nondirectory file) file)))) + (magit-with-toplevel + (let* ((files (or (magit-staged-files) + (magit-changed-files "HEAD^..HEAD"))) + (file (cl-case (length files) + (1 (car files)) + (0 (error "No files found")) + (t + (completing-read "Staged file: " files nil t))))) + (insert (if no-directory (file-name-nondirectory file) file))))) (define-key ctl-x-4-map "g" 'magit-find-file-other-window) (define-key km/file-map "g" 'magit-find-file) |