update packages
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
;;; magit-process.el --- process functionality -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2010-2021 The Magit Project Contributors
|
||||
;; Copyright (C) 2010-2022 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.
|
||||
@@ -8,6 +8,8 @@
|
||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
||||
|
||||
;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
;; Magit is free software; you can redistribute it and/or modify it
|
||||
;; under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation; either version 3, or (at your option)
|
||||
@@ -31,19 +33,14 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'ansi-color)
|
||||
(require 'cl-lib)
|
||||
(require 'dash)
|
||||
|
||||
(eval-when-compile
|
||||
(require 'subr-x))
|
||||
|
||||
(require 'with-editor)
|
||||
(require 'magit-utils)
|
||||
(require 'magit-section)
|
||||
(require 'magit-git)
|
||||
(require 'magit-mode)
|
||||
|
||||
(require 'ansi-color)
|
||||
(require 'with-editor)
|
||||
|
||||
(declare-function auth-source-search "auth-source"
|
||||
(&rest spec &key max require create delete &allow-other-keys))
|
||||
|
||||
@@ -100,11 +97,14 @@ When this is nil, no sections are ever removed."
|
||||
:type '(choice (const :tag "Never remove old sections" nil) integer))
|
||||
|
||||
(defvar magit-process-extreme-logging nil
|
||||
"Whether `magit-process-file' logs to *Messages* buffer.
|
||||
"Whether `magit-process-file' logs to the *Messages* buffer.
|
||||
|
||||
Only intended for temporary use when you try to figure out how
|
||||
Magit uses Git behind the scene. Output that normally goes to
|
||||
the magit-process buffer continues to go there. Not all output
|
||||
goes to either of these two buffers.")
|
||||
goes to either of these two buffers.
|
||||
|
||||
Also see `magit-git-debug'.")
|
||||
|
||||
(defcustom magit-process-error-tooltip-max-lines 20
|
||||
"The number of lines for `magit-process-error-lines' to return.
|
||||
@@ -176,11 +176,12 @@ itself from the hook, to avoid further futile attempts."
|
||||
"Please enter the passphrase for the ssh key"
|
||||
"Please enter the passphrase to unlock the OpenPGP secret key"
|
||||
"^.*'s password: ?$"
|
||||
"^Token: $" ; For git-credential-manager-core (#4318).
|
||||
"^Yubikey for .*: ?$"
|
||||
"^Enter PIN for .*: ?$")
|
||||
"List of regexps matching password prompts of Git and its subprocesses.
|
||||
Also see `magit-process-find-password-functions'."
|
||||
:package-version '(magit . "2.8.0")
|
||||
:package-version '(magit . "3.0.0")
|
||||
:group 'magit-process
|
||||
:type '(repeat (regexp)))
|
||||
|
||||
@@ -355,7 +356,7 @@ then raise an error."
|
||||
(defun magit-run-git (&rest args)
|
||||
"Call Git synchronously in a separate process, and refresh.
|
||||
|
||||
Option `magit-git-executable' specifies the Git executable and
|
||||
Function `magit-git-executable' specifies the Git executable and
|
||||
option `magit-git-global-arguments' specifies constant arguments.
|
||||
The arguments ARGS specify arguments to Git, they are flattened
|
||||
before use.
|
||||
@@ -377,7 +378,7 @@ Process output goes into a new section in the buffer returned by
|
||||
(defun magit-call-git (&rest args)
|
||||
"Call Git synchronously in a separate process.
|
||||
|
||||
Option `magit-git-executable' specifies the Git executable and
|
||||
Function `magit-git-executable' specifies the Git executable and
|
||||
option `magit-git-global-arguments' specifies constant arguments.
|
||||
The arguments ARGS specify arguments to Git, they are flattened
|
||||
before use.
|
||||
@@ -386,7 +387,8 @@ Process output goes into a new section in the buffer returned by
|
||||
`magit-process-buffer'."
|
||||
(run-hooks 'magit-pre-call-git-hook)
|
||||
(let ((default-process-coding-system (magit--process-coding-system)))
|
||||
(apply #'magit-call-process magit-git-executable
|
||||
(apply #'magit-call-process
|
||||
(magit-git-executable)
|
||||
(magit-process-git-arguments args))))
|
||||
|
||||
(defun magit-call-process (program &rest args)
|
||||
@@ -400,6 +402,17 @@ Process output goes into a new section in the buffer returned by
|
||||
(apply #'magit-process-file program nil process-buf nil args))
|
||||
process-buf (current-buffer) default-directory section)))
|
||||
|
||||
(defun magit-process-git (destination &rest args)
|
||||
"Call Git synchronously in a separate process, returning its exit code.
|
||||
DESTINATION specifies how to handle the output, like for
|
||||
`call-process', except that file handlers are supported.
|
||||
Enable Cygwin's \"noglob\" option during the call and
|
||||
ensure unix eol conversion."
|
||||
(apply #'magit-process-file
|
||||
(magit-git-executable)
|
||||
nil destination nil
|
||||
(magit-process-git-arguments args)))
|
||||
|
||||
(defun magit-process-file (process &optional infile buffer display &rest args)
|
||||
"Process files synchronously in a separate process.
|
||||
Identical to `process-file' but temporarily enable Cygwin's
|
||||
@@ -437,9 +450,10 @@ conversion."
|
||||
ARGS is flattened and then used as arguments to Git.
|
||||
|
||||
The current buffer's content is used as the process's standard
|
||||
input.
|
||||
input. The buffer is assumed to be temporary and thus OK to
|
||||
modify.
|
||||
|
||||
Option `magit-git-executable' specifies the Git executable and
|
||||
Function `magit-git-executable' specifies the Git executable and
|
||||
option `magit-git-global-arguments' specifies constant arguments.
|
||||
The remaining arguments ARGS specify arguments to Git, they are
|
||||
flattened before use."
|
||||
@@ -460,11 +474,11 @@ flattened before use."
|
||||
(default-process-coding-system (magit--process-coding-system))
|
||||
(flat-args (magit-process-git-arguments args))
|
||||
(`(,process-buf . ,section)
|
||||
(magit-process-setup magit-git-executable flat-args))
|
||||
(magit-process-setup (magit-git-executable) flat-args))
|
||||
(inhibit-read-only t))
|
||||
(magit-process-finish
|
||||
(apply #'call-process-region (point-min) (point-max)
|
||||
magit-git-executable nil process-buf nil flat-args)
|
||||
(magit-git-executable) nil process-buf nil flat-args)
|
||||
process-buf nil default-directory section))))
|
||||
|
||||
;;; Asynchronous Processes
|
||||
@@ -480,7 +494,7 @@ current when this function was called (if it is a Magit buffer
|
||||
and still alive), as well as the respective Magit status buffer.
|
||||
|
||||
See `magit-start-process' for more information."
|
||||
(message "Running %s %s" magit-git-executable
|
||||
(message "Running %s %s" (magit-git-executable)
|
||||
(let ((m (mapconcat #'identity (-flatten args) " ")))
|
||||
(remove-list-of-text-properties 0 (length m) '(face) m)
|
||||
m))
|
||||
@@ -528,7 +542,7 @@ If INPUT is non-nil, it has to be a buffer or the name of an
|
||||
existing buffer. The buffer content becomes the processes
|
||||
standard input.
|
||||
|
||||
Option `magit-git-executable' specifies the Git executable and
|
||||
Function `magit-git-executable' specifies the Git executable and
|
||||
option `magit-git-global-arguments' specifies constant arguments.
|
||||
The remaining arguments ARGS specify arguments to Git, they are
|
||||
flattened before use.
|
||||
@@ -540,7 +554,7 @@ and still alive), as well as the respective Magit status buffer.
|
||||
See `magit-start-process' for more information."
|
||||
(run-hooks 'magit-pre-start-git-hook)
|
||||
(let ((default-process-coding-system (magit--process-coding-system)))
|
||||
(apply #'magit-start-process magit-git-executable input
|
||||
(apply #'magit-start-process (magit-git-executable) input
|
||||
(magit-process-git-arguments args))))
|
||||
|
||||
(defun magit-start-process (program &optional input &rest args)
|
||||
@@ -580,11 +594,11 @@ Magit status buffer."
|
||||
(when (eq system-type 'windows-nt)
|
||||
;; On w32, git expects UTF-8 encoded input, ignore any user
|
||||
;; configuration telling us otherwise.
|
||||
(set-process-coding-system process 'utf-8-unix))
|
||||
(set-process-coding-system process nil 'utf-8-unix))
|
||||
(process-put process 'section section)
|
||||
(process-put process 'command-buf (current-buffer))
|
||||
(process-put process 'default-dir default-directory)
|
||||
(when inhibit-magit-refresh
|
||||
(when magit-inhibit-refresh
|
||||
(process-put process 'inhibit-refresh t))
|
||||
(oset section process process)
|
||||
(with-current-buffer process-buf
|
||||
@@ -611,7 +625,7 @@ Magit status buffer."
|
||||
(default-process-coding-system
|
||||
(magit--process-coding-system)))
|
||||
(apply #'start-file-process "git" process-buf
|
||||
magit-git-executable args))))
|
||||
(magit-git-executable) args))))
|
||||
(process-put process 'command-buf command-buf)
|
||||
(process-put process 'parsed (point))
|
||||
(setq magit-this-process process)
|
||||
@@ -652,12 +666,15 @@ Magit status buffer."
|
||||
|
||||
(defun magit-process--format-arguments (program args)
|
||||
(cond
|
||||
((and args (equal program magit-git-executable))
|
||||
((and args (equal program (magit-git-executable)))
|
||||
(setq args (-split-at (length magit-git-global-arguments) args))
|
||||
(concat (propertize (file-name-nondirectory program)
|
||||
'font-lock-face 'magit-section-heading)
|
||||
" "
|
||||
(propertize (char-to-string magit-ellipsis)
|
||||
(propertize (if (stringp magit-ellipsis)
|
||||
magit-ellipsis
|
||||
;; For backward compatibility.
|
||||
(char-to-string magit-ellipsis))
|
||||
'font-lock-face 'magit-section-heading
|
||||
'help-echo (mapconcat #'identity (car args) " "))
|
||||
" "
|
||||
@@ -758,7 +775,9 @@ Magit status buffer."
|
||||
(let ((map (cl-gensym)))
|
||||
`(let ((,map (make-sparse-keymap)))
|
||||
(set-keymap-parent ,map minibuffer-local-map)
|
||||
(define-key ,map "\C-g"
|
||||
;; Note: Leaving (kbd ...) unevaluated leads to the
|
||||
;; magit-process:password-prompt test failing.
|
||||
(define-key ,map ,(kbd "C-g")
|
||||
(lambda ()
|
||||
(interactive)
|
||||
(ignore-errors (kill-process ,proc))
|
||||
@@ -790,13 +809,38 @@ To use this function add it to the appropriate hook
|
||||
'magit-process-password-auth-source)
|
||||
|
||||
KEY typically derives from a prompt such as:
|
||||
Password for 'https://tarsius@bitbucket.org'
|
||||
Password for 'https://yourname@github.com'
|
||||
in which case it would be the string
|
||||
tarsius@bitbucket.org
|
||||
yourname@github.com
|
||||
which matches the ~/.authinfo.gpg entry
|
||||
machine bitbucket.org login tarsius password 12345
|
||||
machine github.com login yourname password 12345
|
||||
or iff that is undefined, for backward compatibility
|
||||
machine tarsius@bitbucket.org password 12345"
|
||||
machine yourname@github.com password 12345
|
||||
|
||||
On github.com you should not use your password but a
|
||||
personal access token, see [1]. For information about
|
||||
the peculiarities of other forges, please consult the
|
||||
respective documentation.
|
||||
|
||||
After manually editing ~/.authinfo.gpg you must reset
|
||||
the cache using
|
||||
M-x auth-source-forget-all-cached RET
|
||||
|
||||
The above will save you from having to repeatedly type
|
||||
your token or password, but you might still repeatedly
|
||||
be asked for your username. To prevent that, change an
|
||||
URL like
|
||||
https://github.com/foo/bar.git
|
||||
to
|
||||
https://yourname@github.com/foo/bar.git
|
||||
|
||||
Instead of changing all such URLs manually, they can
|
||||
be translated on the fly by doing this once
|
||||
git config --global \
|
||||
url.https://yourname@github.com.insteadOf \
|
||||
https://github.com
|
||||
|
||||
[1]: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token."
|
||||
(require 'auth-source)
|
||||
(and (string-match "\\`\\(.+\\)@\\([^@]+\\)\\'" key)
|
||||
(let* ((user (match-string 1 key))
|
||||
@@ -810,12 +854,26 @@ or iff that is undefined, for backward compatibility
|
||||
(funcall secret)
|
||||
secret))))
|
||||
|
||||
(defun magit-process-git-credential-manager-core (process string)
|
||||
"Authenticate using `git-credential-manager-core'.
|
||||
|
||||
To use this function add it to the appropriate hook
|
||||
(add-hook \\='magit-process-prompt-functions
|
||||
\\='magit-process-git-credential-manager-core)"
|
||||
(and (string-match "^option (enter for default): $" string)
|
||||
(progn
|
||||
(magit-process-buffer)
|
||||
(let ((option (format "%c\n"
|
||||
(read-char-choice "Option: " '(?\r ?\j ?1 ?2)))))
|
||||
(insert-before-markers-and-inherit option)
|
||||
(process-send-string process option)))))
|
||||
|
||||
(defun magit-process-password-prompt (process string)
|
||||
"Find a password based on prompt STRING and send it to git.
|
||||
Use `magit-process-password-prompt-regexps' to find a known
|
||||
prompt. If and only if one is found, then call functions in
|
||||
`magit-process-find-password-functions' until one of them returns
|
||||
the password. If all function return nil, then read the password
|
||||
the password. If all functions return nil, then read the password
|
||||
from the user."
|
||||
(when-let ((prompt (magit-process-match-prompt
|
||||
magit-process-password-prompt-regexps string)))
|
||||
@@ -879,7 +937,7 @@ as argument."
|
||||
(condition-case nil
|
||||
(start-process "git-credential-cache--daemon"
|
||||
" *git-credential-cache--daemon*"
|
||||
magit-git-executable
|
||||
(magit-git-executable)
|
||||
"credential-cache--daemon"
|
||||
magit-credential-cache-daemon-socket)
|
||||
;; Some Git implementations (e.g. Windows) won't have
|
||||
@@ -922,7 +980,7 @@ as argument."
|
||||
|
||||
(defun magit-process-set-mode-line (program args)
|
||||
"Display the git command (sans arguments) in the mode line."
|
||||
(when (equal program magit-git-executable)
|
||||
(when (equal program (magit-git-executable))
|
||||
(setq args (nthcdr (length magit-git-global-arguments) args)))
|
||||
(let ((str (concat " " (propertize
|
||||
(concat (file-name-nondirectory program)
|
||||
@@ -971,8 +1029,8 @@ If STR is supplied, it replaces the `mode-line-process' text."
|
||||
;; The following closure captures the repokey value, and is
|
||||
;; added to `pre-command-hook'.
|
||||
(cl-labels ((enable-magit-process-unset-mode-line
|
||||
() ;; Remove ourself from the hook variable, so
|
||||
;; that we only run once.
|
||||
() ;;; Remove ourself from the hook variable, so
|
||||
;;; that we only run once.
|
||||
(remove-hook 'pre-command-hook
|
||||
#'enable-magit-process-unset-mode-line)
|
||||
;; Clear the inhibit flag for the repository in
|
||||
|
||||
Reference in New Issue
Block a user