update packages
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
(require 'magit-base)
|
||||
|
||||
(require 'format-spec)
|
||||
(require 'server)
|
||||
|
||||
;; From `magit-branch'.
|
||||
(defvar magit-branch-prefer-remote-upstream)
|
||||
@@ -67,7 +68,7 @@
|
||||
;; From `magit-status'.
|
||||
(defvar magit-status-show-untracked-files)
|
||||
|
||||
(eval-and-compile
|
||||
(eval-and-compile ;declare slot names
|
||||
(cl-pushnew 'orig-rev eieio--known-slot-names)
|
||||
(cl-pushnew 'number eieio--known-slot-names))
|
||||
|
||||
@@ -94,6 +95,13 @@ this."
|
||||
:type '(choice (coding-system :tag "Coding system to decode Git output")
|
||||
(const :tag "Use system default" nil)))
|
||||
|
||||
(defun magit--early-process-lines (program &rest args)
|
||||
"Only used to initialize custom options."
|
||||
(let ((process-environment
|
||||
(append magit-git-environment process-environment)))
|
||||
(ignore-error file-missing
|
||||
(apply #'process-lines-ignore-status program args))))
|
||||
|
||||
(defvar magit-git-w32-path-hack nil
|
||||
"Alist of (EXE . (PATHENTRY)).
|
||||
This specifies what additional PATH setting needs to be added to
|
||||
@@ -105,31 +113,29 @@ successfully.")
|
||||
;; Avoid the wrappers "cmd/git.exe" and "cmd/git.cmd",
|
||||
;; which are much slower than using "bin/git.exe" directly.
|
||||
(and-let ((exec (executable-find "git")))
|
||||
(ignore-errors
|
||||
;; Git for Windows 2.x provides cygpath so we can
|
||||
;; ask it for native paths.
|
||||
(let* ((core-exe
|
||||
(car
|
||||
(process-lines
|
||||
exec "-c"
|
||||
"alias.X=!x() { which \"$1\" | cygpath -mf -; }; x"
|
||||
"X" "git")))
|
||||
(hack-entry (assoc core-exe magit-git-w32-path-hack))
|
||||
;; Running the libexec/git-core executable
|
||||
;; requires some extra PATH entries.
|
||||
(path-hack
|
||||
(list (concat "PATH="
|
||||
(car (process-lines
|
||||
exec "-c"
|
||||
"alias.P=!cygpath -wp \"$PATH\""
|
||||
"P"))))))
|
||||
;; The defcustom STANDARD expression can be
|
||||
;; evaluated many times, so make sure it is
|
||||
;; idempotent.
|
||||
(if hack-entry
|
||||
(setcdr hack-entry path-hack)
|
||||
(push (cons core-exe path-hack) magit-git-w32-path-hack))
|
||||
core-exe))))
|
||||
;; Git for Windows 2.x provides cygpath so we can
|
||||
;; ask it for native paths.
|
||||
(let* ((core-exe
|
||||
(car (magit--early-process-lines
|
||||
exec "-c"
|
||||
"alias.X=!x() { which \"$1\" | cygpath -mf -; }; x"
|
||||
"X" "git")))
|
||||
(hack-entry (assoc core-exe magit-git-w32-path-hack))
|
||||
;; Running the libexec/git-core executable
|
||||
;; requires some extra PATH entries.
|
||||
(path-hack
|
||||
(list (concat "PATH="
|
||||
(car (magit--early-process-lines
|
||||
exec "-c"
|
||||
"alias.P=!cygpath -wp \"$PATH\""
|
||||
"P"))))))
|
||||
;; The defcustom STANDARD expression can be
|
||||
;; evaluated many times, so make sure it is
|
||||
;; idempotent.
|
||||
(if hack-entry
|
||||
(setcdr hack-entry path-hack)
|
||||
(push (cons core-exe path-hack) magit-git-w32-path-hack))
|
||||
core-exe)))
|
||||
(and (eq system-type 'darwin)
|
||||
(executable-find "git"))
|
||||
"git")
|
||||
@@ -148,9 +154,52 @@ option."
|
||||
:group 'magit-process
|
||||
:type 'string)
|
||||
|
||||
(defvar magit--overriding-githook-directory nil)
|
||||
|
||||
(defcustom magit-overriding-githook-directory nil
|
||||
"Directory containing the Git hook scripts used by Magit.
|
||||
|
||||
No Magit-specific Git hook scripts are used if this is nil, which it
|
||||
is the default. This feature is still experimental.
|
||||
|
||||
Git does not allow overriding just an individual hook. It is only
|
||||
possible to point Git at an alternative directory containing hook
|
||||
scripts, using the Git variable `core.hooksPath'. When doing that,
|
||||
the hooks located in `$GIT_DIR/hooks' are ignored.
|
||||
|
||||
If `magit', use the directory containing Git hook scripts distributed
|
||||
with Magit. To counteract Git's limited granularity, Magit provides a
|
||||
script for every Git hook, most of which only run the respective script
|
||||
located in `$GIT_DIR/hooks', provided it exists and is executable.
|
||||
|
||||
A few Git hooks additionally run Lisp hooks:
|
||||
|
||||
- `post-commit' runs `magit-git-post-commit-functions'
|
||||
- `post-merge' runs `magit-git-post-merge-functions'
|
||||
- `post-rewrite' runs `magit-git-post-rewrite-functions'
|
||||
|
||||
All of these hooks also run `magit-common-git-post-rewrite-functions'.
|
||||
For many uses this hook variable is more useful than the three above.
|
||||
|
||||
If you want to teach additional Git hooks to run Lisp hooks, you have to
|
||||
copy Magit's hook script directory elsewhere, modify the hook scripts in
|
||||
question, and point this variable at the used directory.
|
||||
|
||||
Magit only sets `core.hooksPath' when calling Git asynchronously. Doing
|
||||
the same when calling Git synchronously would cause Git and Magit to wait
|
||||
on one another."
|
||||
:package-version '(magit . "4.5.0")
|
||||
:group 'magit-process
|
||||
:set (lambda (symbol value)
|
||||
(set-default-toplevel-value symbol value)
|
||||
(setq magit--overriding-githook-directory nil))
|
||||
:type '(choice (const :tag "Do not shadow Git's hook directory" nil)
|
||||
(const :tag "Use Magit's hook directory" magit)
|
||||
(directory :tag "Custom directory")))
|
||||
|
||||
(defcustom magit-git-global-arguments
|
||||
`("--no-pager" "--literal-pathspecs"
|
||||
"-c" "core.preloadindex=true"
|
||||
"-c" "core.preloadIndex=true"
|
||||
"-c" "log.showSignature=false"
|
||||
"-c" "color.ui=false"
|
||||
"-c" "color.diff=false"
|
||||
@@ -331,7 +380,11 @@ is remote."
|
||||
magit-remote-git-executable
|
||||
magit-git-executable))
|
||||
|
||||
(defun magit-process-git-arguments (args)
|
||||
(defun magit-process-git-arguments--length ()
|
||||
(+ (length magit-git-global-arguments)
|
||||
(if magit--overriding-githook-directory 2 0)))
|
||||
|
||||
(defun magit-process-git-arguments (args &optional async)
|
||||
"Prepare ARGS for a function that invokes Git.
|
||||
|
||||
Magit has many specialized functions for running Git; they all
|
||||
@@ -339,9 +392,27 @@ pass arguments through this function before handing them to Git,
|
||||
to do the following.
|
||||
|
||||
* Prepend `magit-git-global-arguments' to ARGS.
|
||||
* If ASYNC is non-nil and `magit-overriding-githook-directory' is non-nil
|
||||
and valid, set `core.hooksPath' by adding additional aguments to ARGS.
|
||||
* Flatten ARGS, removing nil arguments.
|
||||
* If `system-type' is `windows-nt', encode ARGS to `w32-ansi-code-page'."
|
||||
(setq args (append magit-git-global-arguments (flatten-tree args)))
|
||||
(cond ((not async))
|
||||
(magit--overriding-githook-directory)
|
||||
((eq magit-overriding-githook-directory 'magit)
|
||||
(setq magit--overriding-githook-directory
|
||||
(expand-file-name "git-hooks"
|
||||
(locate-dominating-file
|
||||
(locate-library "magit.el") "git-hooks"))))
|
||||
((and magit-overriding-githook-directory
|
||||
(file-directory-p magit-overriding-githook-directory))
|
||||
(setq magit--overriding-githook-directory
|
||||
magit-overriding-githook-directory)))
|
||||
(setq args
|
||||
(append magit-git-global-arguments
|
||||
(and magit--overriding-githook-directory
|
||||
(list "-c" (format "core.hooksPath=%s"
|
||||
magit--overriding-githook-directory)))
|
||||
(flatten-tree args)))
|
||||
(if (and (eq system-type 'windows-nt) (boundp 'w32-ansi-code-page))
|
||||
;; On w32, the process arguments *must* be encoded in the
|
||||
;; current code-page (see #3250).
|
||||
@@ -606,7 +677,7 @@ executable."
|
||||
(error "`git --exec-path' failed"))))
|
||||
exec-suffixes
|
||||
#'file-executable-p)
|
||||
(compat-call executable-find command t)))
|
||||
(executable-find command t)))
|
||||
|
||||
;;; Git Version
|
||||
|
||||
@@ -953,7 +1024,7 @@ returning the truename."
|
||||
"(see https://magit.vc/goto/e6a78ed2)"))
|
||||
|
||||
(defun magit--assert-usable-git ()
|
||||
(if (not (compat-call executable-find (magit-git-executable) t))
|
||||
(if (not (executable-find (magit-git-executable) t))
|
||||
(signal 'magit-git-executable-not-found (magit-git-executable))
|
||||
(let ((magit-git-debug
|
||||
(lambda (err)
|
||||
@@ -1208,14 +1279,11 @@ or if no rename is detected."
|
||||
"Failed to parse Cygwin mount: %S" mount)))
|
||||
;; If --exec-path is not a native Windows path,
|
||||
;; then we probably have a cygwin git.
|
||||
(let ((process-environment
|
||||
(append magit-git-environment
|
||||
process-environment)))
|
||||
(and (not (string-match-p
|
||||
"\\`[a-zA-Z]:"
|
||||
(car (process-lines
|
||||
magit-git-executable "--exec-path"))))
|
||||
(ignore-errors (process-lines "mount")))))
|
||||
(and (not (string-match-p
|
||||
"\\`[a-zA-Z]:"
|
||||
(car (magit--early-process-lines
|
||||
magit-git-executable "--exec-path"))))
|
||||
(magit--early-process-lines "mount")))
|
||||
#'> :key (pcase-lambda (`(,cyg . ,_win)) (length cyg))))
|
||||
"Alist of (CYGWIN . WIN32) directory names.
|
||||
Sorted from longest to shortest CYGWIN name."
|
||||
@@ -2896,6 +2964,34 @@ out. Only existing branches can be selected."
|
||||
(magit-confirm t nil (format "%s %%d modules" verb) nil modules)
|
||||
(list (magit-read-module-path (format "%s module" verb) predicate)))))
|
||||
|
||||
;;; Git Hooks
|
||||
|
||||
(defun magit-run-git-hook (githook &rest args)
|
||||
(dolist (githook (ensure-list githook))
|
||||
(let* ((githook (symbol-name githook))
|
||||
(hook (save-match-data
|
||||
(if (string-match "\\`common-" githook)
|
||||
(intern (format "magit-common-git-%s-functions"
|
||||
(substring githook (match-end 0))))
|
||||
(intern (format "magit-git-%s-functions" githook))))))
|
||||
(when (and (boundp hook)
|
||||
(symbol-value hook))
|
||||
(magit--client-message "Running %s..." hook)
|
||||
(apply #'run-hook-with-args hook args)
|
||||
(magit--client-message "Running %s...done" hook))))
|
||||
;; Emacsclient prints the returned value to stdout. We cannot prevent
|
||||
;; that, but we can use something that looks like we actually *wanted*
|
||||
;; to print (which we don't).
|
||||
'---)
|
||||
|
||||
(defun magit--client-message (format-string &rest args)
|
||||
;; See `server-process-filter'.
|
||||
(let ((msg (format "-print %s\n"
|
||||
(server-quote-arg
|
||||
(apply #'format-message format-string args)))))
|
||||
(dolist (client server-clients)
|
||||
(server-send-string client msg))))
|
||||
|
||||
;;; _
|
||||
(provide 'magit-git)
|
||||
;; Local Variables:
|
||||
|
||||
Reference in New Issue
Block a user