branch: elpa/magit
commit c170fcf39918e567948fec43b70a592765ed5fe7
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
Distribute git-commit.el as part of magit
---
CHANGELOG | 3 +
lisp/git-commit.el | 181 ++++++++++++++---------------------------------------
lisp/magit.el | 1 -
3 files changed, 50 insertions(+), 135 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index 40f8864a48c..9a08fca2e6c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,9 @@
# -*- mode: org -*-
* v4.1.0 UNRELEASED
+- The library ~git-commit.el~ is no longer distributed as a separate
+ package, ~git-commit~, but as part of the ~magit~ package.
+
- Improved ~magit-tag-release~'s consistency and handling of arguments.
#5102
diff --git a/lisp/git-commit.el b/lisp/git-commit.el
index 308e9c7513b..a2578efcdc3 100644
--- a/lisp/git-commit.el
+++ b/lisp/git-commit.el
@@ -8,17 +8,6 @@
;; Marius Vollmer <[email protected]>
;; Maintainer: Jonas Bernoulli <[email protected]>
-;; Homepage: https://github.com/magit/magit
-;; Keywords: git tools vc
-
-;; Package-Version: 4.0.0
-;; Package-Requires: (
-;; (emacs "26.1")
-;; (compat "30.0.0.0")
-;; (seq "2.24")
-;; (transient "0.7.4")
-;; (with-editor "3.4.1"))
-
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Magit is free software: you can redistribute it and/or modify
@@ -111,13 +100,7 @@
;;; Code:
-(require 'compat)
-(require 'subr-x)
-
-(when (and (featurep 'seq)
- (not (fboundp 'seq-keep)))
- (unload-feature 'seq 'force))
-(require 'seq)
+(require 'magit-mode)
(require 'log-edit)
(require 'ring)
@@ -125,17 +108,6 @@
(require 'transient)
(require 'with-editor)
-;; For historic reasons Magit isn't a hard dependency.
-(require 'magit-base nil t)
-(require 'magit-git nil t)
-(declare-function magit-completing-read "magit-base"
- ( 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-hook-custom-get "magit-base" (symbol))
-(declare-function magit-list-local-branch-names "magit-git" ())
-
(defvar diff-default-read-only)
(defvar flyspell-generic-check-word-predicate)
(defvar font-lock-beg)
@@ -229,7 +201,7 @@ Also note that `git-commit-mode' (which see) is not a
major-mode.")
"Hook run at the end of `git-commit-setup'."
:group 'git-commit
:type 'hook
- :get (and (featurep 'magit-base) #'magit-hook-custom-get)
+ :get #'magit-hook-custom-get
:options '(git-commit-ensure-comment-gap
git-commit-save-message
git-commit-setup-changelog-support
@@ -254,12 +226,10 @@ seconds, then this hook isn't run at all. For certain
commands
such as `magit-rebase-continue' this hook is never run because
doing so would lead to a race condition.
-This hook is only run if `magit' is available.
-
Also see `magit-post-commit-hook'."
:group 'git-commit
:type 'hook
- :get (and (featurep 'magit-base) #'magit-hook-custom-get))
+ :get #'magit-hook-custom-get)
(defcustom git-commit-post-finish-hook-timeout 1
"Time in seconds to wait for git to create a commit.
@@ -335,9 +305,7 @@ serves as a good introduction."
"Whether to use a local message ring instead of the global one.
This can be set globally, in which case every repository gets its
-own commit message ring, or locally for a single repository. If
-Magit isn't available, then setting this to a non-nil value has
-no effect."
+own commit message ring, or locally for a single repository."
:group 'git-commit
:safe 'booleanp
:type 'boolean)
@@ -402,18 +370,13 @@ In this context a \"keyword\" is text surrounded by
brackets."
:group 'git-commit-faces)
(defface git-commit-comment-branch-local
- (if (featurep 'magit)
- '((t :inherit magit-branch-local))
- '((t :inherit font-lock-variable-name-face)))
+ '((t :inherit magit-branch-local))
"Face used for names of local branches in commit message comments."
:group 'git-commit-faces)
(defface git-commit-comment-branch-remote
- (if (featurep 'magit)
- '((t :inherit magit-branch-remote))
- '((t :inherit font-lock-variable-name-face)))
- "Face used for names of remote branches in commit message comments.
-This is only used if Magit is available."
+ '((t :inherit magit-branch-remote))
+ "Face used for names of remote branches in commit message comments."
:group 'git-commit-faces)
(defface git-commit-comment-detached
@@ -532,16 +495,7 @@ the redundant bindings, then set this to nil, before
loading
buffer-file-name)))
(not (file-accessible-directory-p
(file-name-directory buffer-file-name)))
- (if (require 'magit-git nil t)
- ;; Emacs prepends a "c:".
- (magit-expand-git-file-name
- (substring buffer-file-name 2))
- ;; Fallback if we can't load `magit-git'.
- (and (string-match
- "\\`[a-z]:/\\(cygdrive/\\)?\\([a-z]\\)/\\(.*\\)"
- buffer-file-name)
- (concat (match-string 2 buffer-file-name) ":/"
- (match-string 3 buffer-file-name)))))))
+ (magit-expand-git-file-name (substring buffer-file-name
2)))))
(when (file-accessible-directory-p (file-name-directory file))
(let ((inhibit-read-only t))
(insert-file-contents file t)
@@ -575,15 +529,8 @@ Used as the local value of `header-line-format', in buffer
using
(defun git-commit-setup ()
(let ((gitdir default-directory)
- (cd nil))
- (when (and (fboundp 'magit-toplevel)
- (boundp 'magit--separated-gitdirs))
- ;; `magit-toplevel' is autoloaded and defined in magit-git.el. That
- ;; library declares this function without loading magit-process.el,
- ;; which defines it.
- (require 'magit-process nil t)
- (when git-commit-cd-to-toplevel
- (setq cd (or (car (rassoc default-directory magit--separated-gitdirs))
+ (cd (and git-commit-cd-to-toplevel
+ (or (car (rassoc default-directory magit--separated-gitdirs))
(magit-toplevel)))))
;; Pretend that git-commit-mode is a major-mode,
;; so that directory-local settings can be used.
@@ -595,7 +542,6 @@ Used as the local value of `header-line-format', in buffer
using
;; because the maintainer can use the latter
;; to enforce conventions, while s/he has no
;; control over the former.
- (fboundp 'magit-toplevel)
(or cd (magit-toplevel)))
gitdir)))
(let ((buffer-file-name nil) ; trick hack-dir-local-variables
@@ -634,14 +580,13 @@ Used as the local value of `header-line-format', in
buffer using
(when (fboundp 'magit-commit--reset-command)
(add-hook 'with-editor-post-finish-hook #'magit-commit--reset-command)
(add-hook 'with-editor-post-cancel-hook #'magit-commit--reset-command))
- (when (and (fboundp 'magit-rev-parse)
- (not (memq last-command
- '(magit-sequencer-continue
- magit-sequencer-skip
- magit-am-continue
- magit-am-skip
- magit-rebase-continue
- magit-rebase-skip))))
+ (unless (memq last-command
+ '(magit-sequencer-continue
+ magit-sequencer-skip
+ magit-am-continue
+ magit-am-skip
+ magit-rebase-continue
+ magit-rebase-skip))
(add-hook 'with-editor-post-finish-hook
(apply-partially #'git-commit-run-post-finish-hook
(magit-rev-parse "HEAD"))
@@ -667,9 +612,7 @@ Used as the local value of `header-line-format', in buffer
using
(with-editor-usage-message))
(defun git-commit-run-post-finish-hook (previous)
- (when (and git-commit-post-finish-hook
- (require 'magit nil t)
- (fboundp 'magit-rev-parse))
+ (when git-commit-post-finish-hook
(cl-block nil
(let ((break (time-add (current-time)
(seconds-to-time
@@ -856,8 +799,7 @@ Save current message first."
(when-let ((index (ring-member log-edit-comment-ring message)))
(ring-remove log-edit-comment-ring index))
(ring-insert log-edit-comment-ring message)
- (when (and git-commit-use-local-message-ring
- (fboundp 'magit-repository-local-set))
+ (when git-commit-use-local-message-ring
(magit-repository-local-set 'log-edit-comment-ring
log-edit-comment-ring))
(message "Message saved"))
@@ -865,8 +807,7 @@ Save current message first."
(defun git-commit-prepare-message-ring ()
(make-local-variable 'log-edit-comment-ring-index)
- (when (and git-commit-use-local-message-ring
- (fboundp 'magit-repository-local-get))
+ (when git-commit-use-local-message-ring
(setq-local log-edit-comment-ring
(magit-repository-local-get
'log-edit-comment-ring
@@ -894,13 +835,6 @@ Save current message first."
(setq str (replace-match "\n" t t str)))
str))))
-;;; Utilities
-
-(defsubst git-commit-executable ()
- (if (fboundp 'magit-git-executable)
- (magit-git-executable)
- "git"))
-
;;; Trailers
(transient-define-prefix git-commit-insert-trailer ()
@@ -989,16 +923,14 @@ return name and email of the current user (you)."
(list (or (getenv "GIT_AUTHOR_NAME")
(getenv "GIT_COMMITTER_NAME")
(with-demoted-errors "Error running 'git config user.name': %S"
- (car (process-lines
- (git-commit-executable) "config" "user.name")))
+ (magit-get "user.name"))
user-full-name
(read-string "Name: "))
(or (getenv "GIT_AUTHOR_EMAIL")
(getenv "GIT_COMMITTER_EMAIL")
(getenv "EMAIL")
(with-demoted-errors "Error running 'git config user.email': %S"
- (car (process-lines
- (git-commit-executable) "config" "user.email")))
+ (magit-get "user.email"))
(read-string "Email: ")))))
(defalias 'git-commit-self-ident #'git-commit-get-ident)
@@ -1007,23 +939,19 @@ return name and email of the current user (you)."
(defun git-commit-read-ident (prompt)
"Read a name and email, prompting with PROMPT, and return them.
-If Magit is available, read them using a single prompt, offering
-past commit authors as completion candidates. The input must
-have the form \"NAME <EMAIL>\"."
- (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: "))))
+Read them using a single prompt, offering past commit authors as
+completion candidates. The input must have the form \"NAME <EMAIL>\"."
+ (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")))))
(defun git-commit--insert-ident-trailer (trailer name email)
(git-commit--insert-trailer trailer (format "%s <%s>" name email)))
@@ -1196,17 +1124,7 @@ Added to `font-lock-extend-region-functions'."
(modify-syntax-entry ?\' "." table)
(modify-syntax-entry ?` "." table)
(set-syntax-table table))
- (setq-local comment-start
- (or (with-temp-buffer
- (and (zerop
- (call-process
- (git-commit-executable) nil (list t nil) nil
- "config" "core.commentchar"))
- (not (bobp))
- (progn
- (goto-char (point-min))
- (buffer-substring (point) (line-end-position)))))
- "#"))
+ (setq-local comment-start (or (magit-get "core.commentchar") "#"))
(setq-local comment-start-skip (format "^%s+[\s\t]*" comment-start))
(setq-local comment-end "")
(setq-local comment-end-skip "\n")
@@ -1219,22 +1137,17 @@ Added to `font-lock-extend-region-functions'."
(aref comment-start 0)))
(markdown-fill-paragraph justify)))))
(setq-local git-commit--branch-name-regexp
- (if (and (featurep 'magit-git)
- ;; When using cygwin git, we may end up in a
- ;; non-existing directory, which would cause
- ;; any git calls to signal an error.
- (file-accessible-directory-p default-directory))
- (progn
- ;; Make sure the below functions are available.
- (require 'magit)
- ;; Font-Lock wants every submatch to succeed, so
- ;; also match the empty string. Avoid listing
- ;; remote branches and using `regexp-quote',
- ;; because in repositories that have thousands of
- ;; branches that would be very slow. See #4353.
- (format "\\(\\(?:%s\\)\\|\\)\\([^']+\\)"
- (string-join (magit-list-local-branch-names)
- "\\|")))
+ ;; When using cygwin git, we may end up in a
+ ;; non-existing directory, which would cause
+ ;; any git calls to signal an error.
+ (if (file-accessible-directory-p default-directory)
+ ;; Font-Lock wants every submatch to succeed, so
+ ;; also match the empty string. Avoid listing
+ ;; remote branches and using `regexp-quote',
+ ;; because in repositories that have thousands of
+ ;; branches that would be very slow. See #4353.
+ (format "\\(\\(?:%s\\)\\|\\)\\([^']+\\)"
+ (string-join (magit-list-local-branch-names)
"\\|"))
"\\([^']*\\)"))
(setq-local font-lock-multiline t)
(add-hook 'font-lock-extend-region-functions
diff --git a/lisp/magit.el b/lisp/magit.el
index e6172daa2b6..2b878207959 100644
--- a/lisp/magit.el
+++ b/lisp/magit.el
@@ -22,7 +22,6 @@
;; (emacs "26.1")
;; (compat "30.0.0.0")
;; (dash "2.19.1")
-;; (git-commit "4.0.0")
;; (magit-section "4.0.0")
;; (seq "2.24")
;; (transient "0.7.4")