emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

support for git commit --amend/--signoff


From: Dan Nicolaescu
Subject: support for git commit --amend/--signoff
Date: Fri, 11 Jun 2010 02:19:14 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

It would be nice if VC commit would support --amend and --signoff for git.

The patch below adds key bindings to toggle some variables in the log-edit 
buffer.
(for --amend it also inserts the contents of the last commit message)

Now vc-git-checkin needs to know any of these variables has been set,
so that it can pass the right flags to the git commit command.

Other VC backends might want to implement similar things.

What is the best way to pass custom flags to the vc-checkin command?


=== modified file 'lisp/vc-git.el'
--- lisp/vc-git.el      2010-06-09 05:24:01 +0000
+++ lisp/vc-git.el      2010-06-10 00:00:50 +0000
@@ -550,6 +550,48 @@ or an empty string if none."
 
 (declare-function log-edit-extract-headers "log-edit" (headers string))
 
+(defvar vc-git-log-edit-signoff nil)
+
+(defvar vc-git-log-edit-amend nil)
+
+(defun vc-git-log-edit-toggle-signoff ()
+  (interactive)
+  (setq vc-git-log-edit-signoff (not vc-git-log-edit-signoff)))
+
+(defun vc-git-log-edit-toggle-amend ()
+  (interactive)
+  (unless vc-git-log-edit-amend
+    (vc-git-command (current-buffer) 1 nil
+                        "log" "--max-count=1" "--pretty=format:%s" "HEAD"))
+  (setq vc-git-log-edit-amend (not vc-git-log-edit-amend)))
+
+(defvar vc-git-log-edit-map
+  (let ((map (make-sparse-keymap "Git-Log-Edit"))
+  (menu-map (make-sparse-keymap)))
+
+    ;; FIXME: Are these key bindings OK?
+    (define-key map "\C-c\C-s" 'vc-git-log-edit-toggle-signoff)
+    (define-key map "\C-c\C-m" 'vc-git-log-edit-toggle-amend)
+
+    ;; FIXME: This does not work.  And it would be better if we could
+    ;; add items to the Log-Edit menu.
+    (define-key map [menu-bar vc-git-log-edit] (cons "Git-Log-Edit" menu-map))
+    (define-key menu-map [ts]
+      '(menu-item "Signoff" vc-git-log-edit-toggle-signoff
+                    :help "Toggle signoff"
+                            :button (:toggle . vc-git-log-edit-signoff)))
+    (define-key menu-map [ta]
+      '(menu-item "Amend" vc-git-log-edit-toggle-amend
+                    :help "Toggle amend, insert old log when turning it on"
+                            :button (:toggle . vc-git-log-edit-amend)))
+    map))
+
+(define-derived-mode vc-git-log-edit-mode log-edit-mode "*VC-log*"
+  "Major mode for editing Git log messages.
+It is based on `log-edit-mode', it has Git specific extensions."
+  (make-local-variable 'vc-git-log-edit-signoff)
+  (make-local-variable 'vc-git-log-edit-amend))
+
 (defun vc-git-checkin (files rev comment)
   (let ((coding-system-for-write vc-git-commits-coding-system))
     (apply 'vc-git-command nil 0 files




reply via email to

[Prev in Thread] Current Thread [Next in Thread]