Skip to content

Commit 9bfc98b

Browse files
committed
Convert commit popup
- Prompt for a patch as a last resort and require a match. - `magit-stgit-read-patches' now properly returns nil instead of '(nil) when reading a patch at point or from the minibuffer fails. - Take care to look out for `--all` and `--number`, in which case we want to ignore any patches specified to the function.
1 parent 9177357 commit 9bfc98b

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

magit-stgit.el

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ REQUIRE-MATCH."
205205
(or (and use-marks intersection)
206206
region
207207
(and use-marks (magit-stgit-patches-sorted magit-stgit--marked-patches))
208-
(list (or (and use-point (magit-section-value-if 'stgit-patch))
209-
(and prompt (magit-stgit-read-patch prompt require-match)))))))
208+
(and use-point (-list (magit-section-value-if 'stgit-patch)))
209+
(and prompt (-list (magit-stgit-read-patch prompt require-match))))))
210210

211211
(defun magit-stgit-mark-contains (patch)
212212
"Return whether the given PATCH is marked."
@@ -259,7 +259,7 @@ one from the minibuffer, and move to the next line."
259259
("f" "Float" magit-stgit-float)
260260
("s" "Sink" magit-stgit-sink)
261261
("a" "Goto" magit-stgit-goto-popup)]
262-
[("c" "Commit" magit-stgit-commit-popup)
262+
[("c" "Commit" magit-stgit-commit)
263263
("C" "Uncommit" magit-stgit-uncommit-popup)
264264
("r" "Repair" magit-stgit-repair)
265265
("R" "Rebase" magit-stgit-rebase-popup)]
@@ -388,23 +388,39 @@ minibuffer as well."
388388
(magit-run-stgit-and-mark-remove
389389
patches (and target (list "-t" target)) "sink" args patches)))
390390

391-
(magit-define-popup magit-stgit-commit-popup
392-
"Popup console for StGit commit."
393-
'magit-stgit-commands
394-
:switches '((?a "Commit all applied patches" "--all"))
395-
:options '((?n "Commit the specified number of patches" "--number=" read-number))
396-
:actions '((?c "Commit" magit-stgit-commit))
397-
:default-action #'magit-stgit-commit)
391+
(transient-define-prefix magit-stgit-commit ()
392+
"Commit a set of patches."
393+
:man-page "stg-commit"
394+
["Arguments"
395+
("-a" "Commit all applied patches" "--all")
396+
("-n" "Commit the first N patches from the bottom up" "--number="
397+
:reader (lambda (prompt _initial-input history)
398+
(number-to-string (read-number prompt nil history))))]
399+
["Actions"
400+
("c" "Commit" magit-stgit--commit)])
401+
402+
(defun magit-stgit--commit-need-patches-p (args)
403+
(and (not (member "--all" args))
404+
(not (member "--number" args))
405+
(not (transient-arg-value "--number=" args))))
398406

399407
;;;###autoload
400-
(defun magit-stgit-commit (patches &rest args)
401-
"Permanently store patches into the stack base."
402-
(interactive (list (magit-stgit-read-patches t t t t nil)
403-
(magit-stgit-commit-arguments)))
404-
(when (and (member "--all" (car args))
405-
(= 1 (length patches)))
406-
(setq patches (list nil)))
407-
(magit-run-stgit-and-mark-remove patches "commit" args "--" patches))
408+
(defun magit-stgit--commit (patches &rest args)
409+
"Invoke `stg commit ARGS... PATCHES...'.
410+
411+
If PATCHES is nil, commit the bottommost patch.
412+
413+
PATCHES is ignored if ARGS contains `--all' or `--number'.
414+
415+
If called interactively, commit the patches around point or read
416+
one from the minibuffer."
417+
(interactive (let ((args (transient-args 'magit-stgit-commit)))
418+
(cons (and (magit-stgit--commit-need-patches-p args)
419+
(magit-stgit-read-patches t t t t "Commit patch"))
420+
args)))
421+
(let ((patches (and (magit-stgit--commit-need-patches-p args)
422+
(or patches (error "No patches provided")))))
423+
(magit-run-stgit-and-mark-remove patches "commit" args patches)))
408424

409425
(magit-define-popup magit-stgit-uncommit-popup
410426
"Popup console for StGit uncommit."
@@ -663,7 +679,7 @@ the To, Cc, and Bcc fields for all patches."
663679
:help "Rename a patch"]
664680
["Edit patch" magit-stgit-edit
665681
:help "Edit a patch"]
666-
["Commit patch" magit-stgit-commit-popup
682+
["Commit patch" magit-stgit-commit
667683
:help "Permanently store the base patch into the stack base"]
668684
["Uncommit patch" magit-stgit-uncommit-popup
669685
:help "Turn a regular commit into an StGit patch"]

0 commit comments

Comments
 (0)