summaryrefslogtreecommitdiff
path: root/lisp/km-magit.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/km-magit.el')
-rw-r--r--lisp/km-magit.el49
1 files changed, 25 insertions, 24 deletions
diff --git a/lisp/km-magit.el b/lisp/km-magit.el
index f6f4cdf..204bddb 100644
--- a/lisp/km-magit.el
+++ b/lisp/km-magit.el
@@ -1,6 +1,6 @@
;;; km-magit.el --- Magit extensions
-;; Copyright (C) 2012-2020 Kyle Meyer <kyle@kyleam.com>
+;; Copyright Kyle Meyer <kyle@kyleam.com>
;; Author: Kyle Meyer <kyle@kyleam.com>
;; URL: https://git.kyleam.com/emacs.d
@@ -50,19 +50,21 @@ a proper commit."
(interactive)
(magit-run-git "commit" "--all" "--message=auto"))
-(defun km/magit-update-or-auto-commit (&optional no-directory)
+(defun km/magit-update-or-auto-commit (&optional full-name)
(interactive "P")
(let ((files (delete-dups (nconc (magit-unstaged-files)
(magit-staged-files)))))
(cl-case (length files)
(0 (user-error "No tracked files with changes"))
(1
- (magit-run-git "commit" "--all" "--message"
- (concat (funcall (if no-directory
- #'file-name-nondirectory
- #'identity)
- (car files))
- ": Update")))
+ (let ((file (car files)))
+ (magit-run-git "commit" "--all" "--message"
+ (concat (funcall (if full-name
+ #'identity
+ #'file-name-nondirectory)
+ file)
+ (and (magit-rev-verify (concat "HEAD:" file))
+ ": Update")))))
(t
(km/magit-auto-commit)))))
@@ -255,7 +257,7 @@ argument SUFFIX, prompt for a suffix to use instead of
(list
(magit-completing-read
"Branch to archive" (magit-list-refnames "refs/heads")
- nil 'require nil nil
+ nil 'require-match nil nil
(or (magit-branch-at-point) (magit-get-previous-branch)))))))
(setq branches
(mapcar (lambda (branch)
@@ -320,7 +322,7 @@ argument SUFFIX, prompt for a suffix to use instead of
(interactive
(list (magit-completing-read
"Delete set with member" (magit-list-refnames "refs/heads")
- nil 'require nil nil
+ nil 'require-match nil nil
(or (magit-branch-at-point) (magit-get-previous-branch)))))
(km/magit-branch--set-action
"Delete"
@@ -332,7 +334,7 @@ argument SUFFIX, prompt for a suffix to use instead of
(interactive
(list (magit-completing-read
"Archive set with member" (magit-list-refnames "refs/heads")
- nil 'require nil nil
+ nil 'require-match nil nil
(or (magit-branch-at-point) (magit-get-previous-branch)))))
(km/magit-branch--set-action
"Archive"
@@ -467,13 +469,13 @@ N defaults to 20."
(1 (car files))
(t (magit-completing-read "File" files nil t))))))
-(defun km/magit-insert-staged-file (&optional no-directory)
+(defun km/magit-insert-staged-file (&optional full-name)
"Select a 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 unless FULL-NAME 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
@@ -489,7 +491,7 @@ command will still offer the staged files)."
(0 (error "No files found"))
(t
(completing-read "Staged file: " files nil t)))))
- (insert (if no-directory (file-name-nondirectory file) file)))))
+ (insert (if full-name file (file-name-nondirectory file))))))
(defun km/magit-shorten-hash (hash &optional n)
(magit-rev-parse (format "--short=%s" (or n (magit-abbrev-length))) hash))
@@ -544,11 +546,11 @@ argument."
(kill-new (message "%s" desc))))
(defun km/magit-rev-ancestor-p (rev-a rev-b)
- "Report whether REV-A is the ancestor of REV-B."
+ "Report whether REV-A is an ancestor of REV-B."
(interactive
- (let* ((rev-a (magit-read-branch-or-commit "Ancestor candidate")))
+ (let ((rev-a (magit-read-branch-or-commit "Ancestor candidate")))
(list rev-a (magit-read-other-branch-or-commit
- (format "Is %s the ancestor of" rev-a)
+ (format "Is %s an ancestor of" rev-a)
rev-a))))
(message "%s is %san ancestor of %s" rev-a
(if (magit-git-success "merge-base" "--is-ancestor"
@@ -881,9 +883,6 @@ appending [M/N] to each entry."
;; specified.
(when (magit-anything-modified-p t)
(user-error "There are uncommitted changes"))
- (setq args (seq-remove
- (lambda (a) (string-match-p "\\`--base=" a))
- args))
(let* ((current (magit-get-current-branch))
(upstream (or (magit-get-upstream-branch current)
(user-error "No upstream branch")))
@@ -894,8 +893,10 @@ appending [M/N] to each entry."
(concat "reset: moving back to " current)
current)
(magit-branch-checkout patch-branch))
- (apply #'magit-run-git "format-patch"
- upstream (concat "--base=" upstream) args)
+ (unless (seq-some (lambda (a) (string-match-p "\\`--base=" a))
+ args)
+ (setq args (cons (concat "--base=" upstream) args)))
+ (apply #'magit-run-git "format-patch" upstream args)
(let* ((patches (or (seq-filter
(lambda (f) (string-suffix-p ".patch" f))
(magit-untracked-files))
@@ -1142,8 +1143,8 @@ function."
;; This always converts to commits IDs. It could try to map
;; refnames to the appropriate GitHub link (including remotes
;; to forks), but I don't have much need for it at the moment.
- (let ((rev1 (magit-rev-parse (match-string 1 magit-buffer-range)))
- (rev2 (magit-rev-parse (match-string 3 magit-buffer-range))))
+ (let ((rev1 (magit-commit-p (match-string 1 magit-buffer-range)))
+ (rev2 (magit-commit-p (match-string 3 magit-buffer-range))))
(format "%s/compare/%s...%s"
(or (km/magit-github-url) "")
rev1 rev2)))))