From 0ff587acd63c4ee8bb8124204de21d0e6300b529 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Fri, 31 Jan 2020 17:50:24 +0100 Subject: [PATCH] update git-commit --- .../git-commit-pkg.el | 2 - .../git-commit-autoloads.el | 11 ++- .../git-commit-pkg.el | 2 + .../git-commit.el | 86 ++++++++++++------- elpa/git-commit-readme.txt | 76 ++++++++++++++++ 5 files changed, 140 insertions(+), 37 deletions(-) delete mode 100644 elpa/git-commit-20190928.1746/git-commit-pkg.el rename elpa/{git-commit-20190928.1746 => git-commit-20200123.1706}/git-commit-autoloads.el (80%) create mode 100644 elpa/git-commit-20200123.1706/git-commit-pkg.el rename elpa/{git-commit-20190928.1746 => git-commit-20200123.1706}/git-commit.el (93%) create mode 100644 elpa/git-commit-readme.txt diff --git a/elpa/git-commit-20190928.1746/git-commit-pkg.el b/elpa/git-commit-20190928.1746/git-commit-pkg.el deleted file mode 100644 index 11358836..00000000 --- a/elpa/git-commit-20190928.1746/git-commit-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;;; -*- no-byte-compile: t -*- -(define-package "git-commit" "20190928.1746" "Edit Git commit messages" '((emacs "25.1") (dash "20180910") (with-editor "20181103")) :commit "7118a9af4f002d6cdc8762b16c45e1ba307dcc8a" :keywords '("git" "tools" "vc") :maintainer '("Jonas Bernoulli" . "jonas@bernoul.li") :url "https://github.com/magit/magit") diff --git a/elpa/git-commit-20190928.1746/git-commit-autoloads.el b/elpa/git-commit-20200123.1706/git-commit-autoloads.el similarity index 80% rename from elpa/git-commit-20190928.1746/git-commit-autoloads.el rename to elpa/git-commit-20200123.1706/git-commit-autoloads.el index 93c45e60..9d01c3ce 100644 --- a/elpa/git-commit-20190928.1746/git-commit-autoloads.el +++ b/elpa/git-commit-20200123.1706/git-commit-autoloads.el @@ -1,10 +1,12 @@ ;;; git-commit-autoloads.el --- automatically extracted autoloads ;; ;;; Code: -(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path)))) + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + -;;;### (autoloads nil "git-commit" "git-commit.el" (23994 46480 437172 -;;;;;; 707000)) +;;;### (autoloads nil "git-commit" "git-commit.el" (0 0 0 0)) ;;; Generated autoloads from git-commit.el (defvar global-git-commit-mode t "\ @@ -38,11 +40,14 @@ provide such a commit message. \(fn)" nil nil) +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "git-commit" '("git-commit-"))) + ;;;*** ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t +;; coding: utf-8 ;; End: ;;; git-commit-autoloads.el ends here diff --git a/elpa/git-commit-20200123.1706/git-commit-pkg.el b/elpa/git-commit-20200123.1706/git-commit-pkg.el new file mode 100644 index 00000000..adcb126c --- /dev/null +++ b/elpa/git-commit-20200123.1706/git-commit-pkg.el @@ -0,0 +1,2 @@ +;;; -*- no-byte-compile: t -*- +(define-package "git-commit" "20200123.1706" "Edit Git commit messages" '((emacs "25.1") (dash "20180910") (transient "20190812") (with-editor "20181103")) :commit "e5e475c61ce568a7e20ed8f795fa343a93632871" :keywords '("git" "tools" "vc") :maintainer '("Jonas Bernoulli" . "jonas@bernoul.li") :url "https://github.com/magit/magit") diff --git a/elpa/git-commit-20190928.1746/git-commit.el b/elpa/git-commit-20200123.1706/git-commit.el similarity index 93% rename from elpa/git-commit-20190928.1746/git-commit.el rename to elpa/git-commit-20200123.1706/git-commit.el index 73bb8f73..0a17bf84 100644 --- a/elpa/git-commit-20190928.1746/git-commit.el +++ b/elpa/git-commit-20200123.1706/git-commit.el @@ -1,6 +1,6 @@ ;;; git-commit.el --- Edit Git commit messages -*- lexical-binding: t; -*- -;; Copyright (C) 2010-2019 The Magit Project Contributors +;; Copyright (C) 2010-2020 The Magit Project Contributors ;; ;; You should have received a copy of the AUTHORS.md file which ;; lists all contributors. If not, see http://magit.vc/authors. @@ -11,8 +11,8 @@ ;; Marius Vollmer ;; Maintainer: Jonas Bernoulli -;; Package-Requires: ((emacs "25.1") (dash "20180910") (with-editor "20181103")) -;; Package-Version: 20190928.1746 +;; Package-Requires: ((emacs "25.1") (dash "20180910") (transient "20190812") (with-editor "20181103")) +;; Package-Version: 20200123.1706 ;; Keywords: git tools vc ;; Homepage: https://github.com/magit/magit @@ -119,9 +119,12 @@ (require 'magit-utils nil t) (require 'ring) (require 'server) +(require 'transient) (require 'with-editor) -(eval-when-compile (require 'recentf)) +(eval-when-compile + (require 'recentf) + (require 'subr-x)) ;;;; Declarations @@ -130,7 +133,11 @@ (defvar font-lock-beg) (defvar font-lock-end) +(declare-function magit-completing-read "magit-utils" + (prompt collection &optional predicate require-match + initial-input hist def fallback)) (declare-function magit-expand-git-file-name "magit-git" (filename)) +(declare-function magit-git-lines "magit-git" (&rest args)) (declare-function magit-list-local-branch-names "magit-git" ()) (declare-function magit-list-remote-branch-names "magit-git" (&optional remote relative)) @@ -307,7 +314,7 @@ In this context a \"keyword\" is text surrounded be brackets." :group 'git-commit-faces) (define-obsolete-face-alias 'git-commit-note - 'git-commit-keyword "Git-Commit 2.91.0") + 'git-commit-keyword "Git-Commit 3.0.0") (defface git-commit-pseudo-header '((t :inherit font-lock-string-face)) @@ -361,23 +368,11 @@ This is only used if Magit is available." (defvar git-commit-mode-map (let ((map (make-sparse-keymap))) - (cond ((featurep 'jkl) - (define-key map (kbd "C-M-i") 'git-commit-prev-message) - (define-key map (kbd "C-M-k") 'git-commit-next-message)) - (t - (define-key map (kbd "M-p") 'git-commit-prev-message) - (define-key map (kbd "M-n") 'git-commit-next-message) - ;; Old bindings to avoid confusion - (define-key map (kbd "C-c C-x a") 'git-commit-ack) - (define-key map (kbd "C-c C-x i") 'git-commit-suggested) - (define-key map (kbd "C-c C-x m") 'git-commit-modified) - (define-key map (kbd "C-c C-x o") 'git-commit-cc) - (define-key map (kbd "C-c C-x p") 'git-commit-reported) - (define-key map (kbd "C-c C-x r") 'git-commit-review) - (define-key map (kbd "C-c C-x s") 'git-commit-signoff) - (define-key map (kbd "C-c C-x t") 'git-commit-test))) + (define-key map (kbd "M-p") 'git-commit-prev-message) + (define-key map (kbd "M-n") 'git-commit-next-message) + (define-key map (kbd "C-c C-i") 'git-commit-insert-pseudo-header) (define-key map (kbd "C-c C-a") 'git-commit-ack) - (define-key map (kbd "C-c C-i") 'git-commit-suggested) + (define-key map (kbd "C-c M-i") 'git-commit-suggested) (define-key map (kbd "C-c C-m") 'git-commit-modified) (define-key map (kbd "C-c C-o") 'git-commit-cc) (define-key map (kbd "C-c C-p") 'git-commit-reported) @@ -674,9 +669,10 @@ With a numeric prefix ARG, go forward ARG comments." (defun git-commit-save-message () "Save current message to `log-edit-comment-ring'." (interactive) - (--when-let (git-commit-buffer-message) - (unless (ring-member log-edit-comment-ring it) - (ring-insert log-edit-comment-ring it)))) + (when-let ((message (git-commit-buffer-message))) + (when-let ((index (ring-member log-edit-comment-ring message))) + (ring-remove log-edit-comment-ring index)) + (ring-insert log-edit-comment-ring message))) (defun git-commit-buffer-message () (let ((flush (concat "^" comment-start)) @@ -701,6 +697,20 @@ With a numeric prefix ARG, go forward ARG comments." ;;; Headers +(define-transient-command git-commit-insert-pseudo-header () + "Insert a commit message pseudo header." + [["Insert ... by yourself" + ("a" "Ack" git-commit-ack) + ("m" "Modified" git-commit-modified) + ("r" "Reviewed" git-commit-review) + ("s" "Signed-off" git-commit-signoff) + ("t" "Tested" git-commit-test)] + ["Insert ... by someone" + ("C-c" "Cc" git-commit-cc) + ("C-r" "Reported" git-commit-reported) + ("C-i" "Suggested" git-commit-suggested) + ("C-a" "Co-authored" git-commit-co-authored)]]) + (defun git-commit-ack (name mail) "Insert a header acknowledging that you have looked at the commit." (interactive (git-commit-self-ident)) @@ -728,22 +738,22 @@ With a numeric prefix ARG, go forward ARG comments." (defun git-commit-cc (name mail) "Insert a header mentioning someone who might be interested." - (interactive (git-commit-read-ident)) + (interactive (git-commit-read-ident "Cc")) (git-commit-insert-header "Cc" name mail)) (defun git-commit-reported (name mail) "Insert a header mentioning the person who reported the issue." - (interactive (git-commit-read-ident)) + (interactive (git-commit-read-ident "Reported-by")) (git-commit-insert-header "Reported-by" name mail)) (defun git-commit-suggested (name mail) "Insert a header mentioning the person who suggested the change." - (interactive (git-commit-read-ident)) + (interactive (git-commit-read-ident "Suggested-by")) (git-commit-insert-header "Suggested-by" name mail)) -(defun git-commit-co-authored-by (name mail) +(defun git-commit-co-authored (name mail) "Insert a header mentioning the person who co-authored the commit." - (interactive (git-commit-read-ident)) + (interactive (git-commit-read-ident "Co-authored-by")) (git-commit-insert-header "Co-authored-by" name mail)) (defun git-commit-self-ident () @@ -758,9 +768,21 @@ With a numeric prefix ARG, go forward ARG comments." (ignore-errors (car (process-lines "git" "config" "user.email"))) (read-string "Email: ")))) -(defun git-commit-read-ident () - (list (read-string "Name: ") - (read-string "Email: "))) +(defun git-commit-read-ident (prompt) + (if (require 'magit-git nil t) + (let ((str (magit-completing-read + prompt + (sort (delete-dups + (magit-git-lines "log" "-n9999" "--format=%aN <%ae>")) + 'string<) + nil nil nil 'git-commit-read-ident-history))) + (save-match-data + (if (string-match "\\`\\([^<]+\\) *<\\([^>]+\\)>\\'" str) + (list (save-match-data (string-trim (match-string 1 str))) + (string-trim (match-string 2 str))) + (user-error "Invalid input")))) + (list (read-string "Name: ") + (read-string "Email: ")))) (defun git-commit-insert-header (header name email) (setq header (format "%s: %s <%s>" header name email)) diff --git a/elpa/git-commit-readme.txt b/elpa/git-commit-readme.txt new file mode 100644 index 00000000..a8c2f7a6 --- /dev/null +++ b/elpa/git-commit-readme.txt @@ -0,0 +1,76 @@ +This package assists the user in writing good Git commit messages. + +While Git allows for the message to be provided on the command +line, it is preferable to tell Git to create the commit without +actually passing it a message. Git then invokes the `$GIT_EDITOR' +(or if that is undefined `$EDITOR') asking the user to provide the +message by editing the file ".git/COMMIT_EDITMSG" (or another file +in that directory, e.g. ".git/MERGE_MSG" for merge commits). + +When `global-git-commit-mode' is enabled, which it is by default, +then opening such a file causes the features described below, to +be enabled in that buffer. Normally this would be done using a +major-mode but to allow the use of any major-mode, as the user sees +fit, it is done here by running a setup function, which among other +things turns on the preferred major-mode, by default `text-mode'. + +Git waits for the `$EDITOR' to finish and then either creates the +commit using the contents of the file as commit message, or, if the +editor process exited with a non-zero exit status, aborts without +creating a commit. Unfortunately Emacsclient (which is what Emacs +users should be using as `$EDITOR' or at least as `$GIT_EDITOR') +does not differentiate between "successfully" editing a file and +aborting; not out of the box that is. + +By making use of the `with-editor' package this package provides +both ways of finish an editing session. In either case the file +is saved, but Emacseditor's exit code differs. + + C-c C-c Finish the editing session successfully by returning + with exit code 0. Git then creates the commit using + the message it finds in the file. + + C-c C-k Aborts the edit editing session by returning with exit + code 1. Git then aborts the commit. + +Aborting the commit does not cause the message to be lost, but +relying solely on the file not being tampered with is risky. This +package additionally stores all aborted messages for the duration +of the current session (i.e. until you close Emacs). To get back +an aborted message use M-p and M-n while editing a message. + + M-p Replace the buffer contents with the previous message + from the message ring. Of course only after storing + the current content there too. + + M-n Replace the buffer contents with the next message from + the message ring, after storing the current content. + +Some support for pseudo headers as used in some projects is +provided by these commands: + + C-c C-s Insert a Signed-off-by header. + C-c C-a Insert a Acked-by header. + C-c C-m Insert a Modified-by header. + C-c C-t Insert a Tested-by header. + C-c C-r Insert a Reviewed-by header. + C-c C-o Insert a Cc header. + C-c C-p Insert a Reported-by header. + C-c C-i Insert a Suggested-by header. + +When Git requests a commit message from the user, it does so by +having her edit a file which initially contains some comments, +instructing her what to do, and providing useful information, such +as which files were modified. These comments, even when left +intact by the user, do not become part of the commit message. This +package ensures these comments are propertizes as such and further +prettifies them by using different faces for various parts, such as +files. + +Finally this package highlights style errors, like lines that are +too long, or when the second line is not empty. It may even nag +you when you attempt to finish the commit without having fixed +these issues. The style checks and many other settings can easily +be configured: + + M-x customize-group RET git-commit RET -- 2.47.3