From 40fca42d923d40839e817e79b192fd71805e974f Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 24 Jun 2010 16:20:03 -0700 Subject: [PATCH 1/4] Abstract out a magit-log-edit-toggle-field function. --- magit.el | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/magit.el b/magit.el index c03ad68d..105f71c9 100644 --- a/magit.el +++ b/magit.el @@ -3142,6 +3142,23 @@ Prefix arg means justify as well." (defun magit-log-edit-get-field (name) (cdr (assq name (magit-log-edit-get-fields)))) +(defun magit-log-edit-toggle-field (name default) + "Toggle the log-edit field named NAME. +If it's currently unset, set it to DEFAULT (t or nil). + +Return nil if the field is toggled off, and non-nil if it's +toggled on. When it's toggled on for the first time, return +'first." + (let* ((fields (magit-log-edit-get-fields)) + (cell (assq name fields)) yesp) + (if cell + (progn + (setq yesp (equal (cdr cell) "yes")) + (rplacd cell (if yesp "no" "yes"))) + (setq fields (acons name (if default "yes" "no") fields)) + (setq yesp (if default 'first))) + (magit-log-edit-set-fields fields))) + (defun magit-log-edit-setup-author-env (author) (cond (author ;; XXX - this is a bit strict, probably. @@ -3220,26 +3237,15 @@ Prefix arg means justify as well." "Toggle whether this will be an amendment to the previous commit. \(i.e., whether eventual commit does 'git commit --amend')" (interactive) - (let* ((fields (magit-log-edit-get-fields)) - (cell (assq 'amend fields))) - (if cell - (rplacd cell (if (equal (cdr cell) "yes") "no" "yes")) - (setq fields (acons 'amend "yes" fields)) - (magit-log-edit-append - (magit-format-commit "HEAD" "%s%n%n%b"))) - (magit-log-edit-set-fields fields))) + (when (eq (magit-log-edit-toggle-field 'amend t) 'first) + (magit-log-edit-append + (magit-format-commit "HEAD" "%s%n%n%b")))) (defun magit-log-edit-toggle-signoff () "Toggle whether this commit will include a signoff. \(i.e., whether eventual commit does 'git commit --signoff')" (interactive) - (let* ((fields (magit-log-edit-get-fields)) - (cell (assq 'sign-off fields))) - (if cell - (rplacd cell (if (equal (cdr cell) "yes") "no" "yes")) - (setq fields (acons 'sign-off (if magit-commit-signoff "no" "yes") - fields))) - (magit-log-edit-set-fields fields))) + (magit-log-edit-toggle-field 'sign-off (not magit-commit-signoff))) (defun magit-pop-to-log-edit (operation) (let ((dir default-directory) From ed9cb1eafad24e864c03b163260451dccf7a1e5c Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 24 Jun 2010 16:31:50 -0700 Subject: [PATCH 2/4] Add an edit-log-mode toggle for allowing empty commits. This is useful for creating commits that are just notes, with no contents. --- magit.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/magit.el b/magit.el index 105f71c9..b9347b86 100644 --- a/magit.el +++ b/magit.el @@ -3056,6 +3056,7 @@ typing and automatically refreshes the status buffer." (define-key map (kbd "C-c C-c") 'magit-log-edit-commit) (define-key map (kbd "C-c C-a") 'magit-log-edit-toggle-amending) (define-key map (kbd "C-c C-s") 'magit-log-edit-toggle-signoff) + (define-key map (kbd "C-c C-e") 'magit-log-edit-toggle-allow-empty) (define-key map (kbd "M-p") 'log-edit-previous-comment) (define-key map (kbd "M-n") 'log-edit-next-comment) (define-key map (kbd "C-c C-k") 'magit-log-edit-cancel-log-message) @@ -3187,6 +3188,7 @@ toggled on. When it's toggled on for the first time, return (interactive) (let* ((fields (magit-log-edit-get-fields)) (amend (equal (cdr (assq 'amend fields)) "yes")) + (allow-empty (equal (cdr (assq 'allow-empty fields)) "yes")) (commit-all (equal (cdr (assq 'commit-all fields)) "yes")) (sign-off-field (assq 'sign-off fields)) (sign-off (if sign-off-field @@ -3209,8 +3211,9 @@ toggled on. When it's toggled on for the first time, return magit-git-executable (append magit-git-standard-options (list "commit" "-F" "-") - (if commit-all '("--all") '()) + (if (and commit-all (not allow-empty)) '("--all") '()) (if amend '("--amend") '()) + (if allow-empty '("--allow-empty")) (if sign-off '("--signoff") '()))))))) (erase-buffer) (bury-buffer) @@ -3247,6 +3250,12 @@ toggled on. When it's toggled on for the first time, return (interactive) (magit-log-edit-toggle-field 'sign-off (not magit-commit-signoff))) +(defun magit-log-edit-toggle-allow-empty () + "Toggle whether this commit is allowed to be empty. +This means that the eventual commit does 'git commit --allow-empty'." + (interactive) + (magit-log-edit-toggle-field 'allow-empty t)) + (defun magit-pop-to-log-edit (operation) (let ((dir default-directory) (buf (get-buffer-create magit-log-edit-buffer-name))) From 8e3916d2f4bcfd50968baaf7af75d42bc7053d0a Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 24 Jun 2010 16:33:15 -0700 Subject: [PATCH 3/4] Add a note in the manual about C-c C-e. --- magit.texi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/magit.texi b/magit.texi index 5955aa6b..1698550b 100644 --- a/magit.texi +++ b/magit.texi @@ -303,6 +303,10 @@ Typing @kbd{C-c C-s} will toggle the @code{--signoff} option. The default is determined by the @code{magit-commit-signoff} customization variable. +Typing @kbd{C-c C-e} will toggle the @code{--allow-empty} option. This +allows you to make commits that serve as notes, without including any +changes. + If you change your mind and don't want to go ahead with your commit while you are in the @code{*magit-log-edit*} buffer, you can just switch to another buffer, continue editing there, staging and From b8d6d5c08b97755ec3577fa2ab5c236e4f94d1ad Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 24 Jun 2010 18:46:23 -0700 Subject: [PATCH 4/4] Make sure magit-log-edit-toggle-field returns the right value. --- magit.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/magit.el b/magit.el index b71f951f..9955db25 100644 --- a/magit.el +++ b/magit.el @@ -3161,7 +3161,8 @@ toggled on. When it's toggled on for the first time, return (rplacd cell (if yesp "no" "yes"))) (setq fields (acons name (if default "yes" "no") fields)) (setq yesp (if default 'first))) - (magit-log-edit-set-fields fields))) + (magit-log-edit-set-fields fields) + yesp)) (defun magit-log-edit-setup-author-env (author) (cond (author