commit | author | age
|
5cb5f7
|
1 |
;;; magit.el --- A Git porcelain inside Emacs -*- lexical-binding: t; coding: utf-8 -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2008-2018 The Magit Project Contributors |
|
4 |
;; |
|
5 |
;; You should have received a copy of the AUTHORS.md file which |
|
6 |
;; lists all contributors. If not, see http://magit.vc/authors. |
|
7 |
|
|
8 |
;; Author: Marius Vollmer <marius.vollmer@gmail.com> |
|
9 |
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li> |
|
10 |
;; Kyle Meyer <kyle@kyleam.com> |
|
11 |
;; Noam Postavsky <npostavs@users.sourceforge.net> |
|
12 |
;; Former-Maintainers: |
|
13 |
;; Nicolas Dudebout <nicolas.dudebout@gatech.edu> |
|
14 |
;; Peter J. Weisberg <pj@irregularexpressions.net> |
|
15 |
;; Phil Jackson <phil@shellarchive.co.uk> |
|
16 |
;; RĂ©mi Vanicat <vanicat@debian.org> |
|
17 |
;; Yann Hodique <yann.hodique@gmail.com> |
|
18 |
|
|
19 |
;; Keywords: git tools vc |
|
20 |
;; Homepage: https://github.com/magit/magit |
|
21 |
|
|
22 |
;; Magit requires at least GNU Emacs 25.1 and Git 2.0.0. |
|
23 |
|
|
24 |
;; Magit is free software; you can redistribute it and/or modify it |
|
25 |
;; under the terms of the GNU General Public License as published by |
|
26 |
;; the Free Software Foundation; either version 3, or (at your option) |
|
27 |
;; any later version. |
|
28 |
;; |
|
29 |
;; Magit is distributed in the hope that it will be useful, but WITHOUT |
|
30 |
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
31 |
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
|
32 |
;; License for more details. |
|
33 |
;; |
|
34 |
;; You should have received a copy of the GNU General Public License |
|
35 |
;; along with Magit. If not, see http://www.gnu.org/licenses. |
|
36 |
|
|
37 |
;;; Commentary: |
|
38 |
|
|
39 |
;; Magit is an interface to the version control system Git, |
|
40 |
;; implemented as an Emacs package. Magit aspires to be a complete |
|
41 |
;; Git porcelain. While we cannot (yet) claim, that Magit wraps and |
|
42 |
;; improves upon each and every Git command, it is complete enough to |
|
43 |
;; allow even experienced Git users to perform almost all of their |
|
44 |
;; daily version control tasks directly from within Emacs. While many |
|
45 |
;; fine Git clients exist, only Magit and Git itself deserve to be |
|
46 |
;; called porcelains. |
|
47 |
|
|
48 |
;;; Code: |
|
49 |
|
|
50 |
(require 'cl-lib) |
|
51 |
(require 'dash) |
|
52 |
|
|
53 |
(eval-when-compile |
|
54 |
(require 'subr-x)) |
|
55 |
|
|
56 |
(require 'with-editor) |
|
57 |
(require 'git-commit) |
|
58 |
(require 'magit-core) |
|
59 |
(require 'magit-diff) |
|
60 |
(require 'magit-apply) |
|
61 |
(require 'magit-log) |
|
62 |
(require 'magit-repos) |
|
63 |
|
|
64 |
(require 'format-spec) |
|
65 |
(require 'package nil t) ; used in `magit-version' |
|
66 |
|
|
67 |
(defconst magit--minimal-git "2.0.0") |
|
68 |
(defconst magit--minimal-emacs "25.1") |
|
69 |
|
|
70 |
;;; Faces |
|
71 |
|
|
72 |
(defface magit-header-line |
|
73 |
'((t :inherit magit-section-heading)) |
|
74 |
"Face for the `header-line' in some Magit modes. |
|
75 |
Note that some modes, such as `magit-log-select-mode', have their |
|
76 |
own faces for the `header-line', or for parts of the |
|
77 |
`header-line'." |
|
78 |
:group 'magit-faces) |
|
79 |
|
|
80 |
(defface magit-header-line-key |
|
81 |
'((t :inherit magit-popup-key)) |
|
82 |
"Face for keys in the `header-line'." |
|
83 |
:group 'magit-faces) |
|
84 |
|
|
85 |
(defface magit-dimmed |
|
86 |
'((((class color) (background light)) :foreground "grey50") |
|
87 |
(((class color) (background dark)) :foreground "grey50")) |
|
88 |
"Face for text that shouldn't stand out." |
|
89 |
:group 'magit-faces) |
|
90 |
|
|
91 |
(defface magit-hash |
|
92 |
'((((class color) (background light)) :foreground "grey60") |
|
93 |
(((class color) (background dark)) :foreground "grey40")) |
|
94 |
"Face for the sha1 part of the log output." |
|
95 |
:group 'magit-faces) |
|
96 |
|
|
97 |
(defface magit-tag |
|
98 |
'((((class color) (background light)) :foreground "Goldenrod4") |
|
99 |
(((class color) (background dark)) :foreground "LightGoldenrod2")) |
|
100 |
"Face for tag labels shown in log buffer." |
|
101 |
:group 'magit-faces) |
|
102 |
|
|
103 |
(defface magit-branch-remote |
|
104 |
'((((class color) (background light)) :foreground "DarkOliveGreen4") |
|
105 |
(((class color) (background dark)) :foreground "DarkSeaGreen2")) |
|
106 |
"Face for remote branch head labels shown in log buffer." |
|
107 |
:group 'magit-faces) |
|
108 |
|
|
109 |
(defface magit-branch-remote-head |
|
110 |
'((((class color) (background light)) :inherit magit-branch-remote :box t) |
|
111 |
(((class color) (background dark)) :inherit magit-branch-remote :box t)) |
|
112 |
"Face for current branch." |
|
113 |
:group 'magit-faces) |
|
114 |
|
|
115 |
(defface magit-branch-local |
|
116 |
'((((class color) (background light)) :foreground "SkyBlue4") |
|
117 |
(((class color) (background dark)) :foreground "LightSkyBlue1")) |
|
118 |
"Face for local branches." |
|
119 |
:group 'magit-faces) |
|
120 |
|
|
121 |
(defface magit-branch-current |
|
122 |
'((((class color) (background light)) :inherit magit-branch-local :box t) |
|
123 |
(((class color) (background dark)) :inherit magit-branch-local :box t)) |
|
124 |
"Face for current branch." |
|
125 |
:group 'magit-faces) |
|
126 |
|
|
127 |
(defface magit-branch-upstream |
|
128 |
'((t :slant italic)) |
|
129 |
"Face for upstream branch. |
|
130 |
This face is only used in logs and it gets combined |
|
131 |
with `magit-branch-local', `magit-branch-remote' |
|
132 |
and/or `magit-branch-remote-head'." |
|
133 |
:group 'magit-faces) |
|
134 |
|
|
135 |
(defface magit-head |
|
136 |
'((((class color) (background light)) :inherit magit-branch-local) |
|
137 |
(((class color) (background dark)) :inherit magit-branch-local)) |
|
138 |
"Face for the symbolic ref `HEAD'." |
|
139 |
:group 'magit-faces) |
|
140 |
|
|
141 |
(defface magit-refname |
|
142 |
'((((class color) (background light)) :foreground "grey30") |
|
143 |
(((class color) (background dark)) :foreground "grey80")) |
|
144 |
"Face for refnames without a dedicated face." |
|
145 |
:group 'magit-faces) |
|
146 |
|
|
147 |
(defface magit-refname-stash |
|
148 |
'((t :inherit magit-refname)) |
|
149 |
"Face for stash refnames." |
|
150 |
:group 'magit-faces) |
|
151 |
|
|
152 |
(defface magit-refname-wip |
|
153 |
'((t :inherit magit-refname)) |
|
154 |
"Face for wip refnames." |
|
155 |
:group 'magit-faces) |
|
156 |
|
|
157 |
(defface magit-refname-pullreq |
|
158 |
'((t :inherit magit-refname)) |
|
159 |
"Face for pullreq refnames." |
|
160 |
:group 'magit-faces) |
|
161 |
|
|
162 |
(defface magit-keyword |
|
163 |
'((t :inherit font-lock-string-face)) |
|
164 |
"Face for parts of commit messages inside brackets." |
|
165 |
:group 'magit-faces) |
|
166 |
|
|
167 |
(defface magit-keyword-squash |
|
168 |
'((t :inherit font-lock-warning-face)) |
|
169 |
"Face for squash! and fixup! keywords in commit messages." |
|
170 |
:group 'magit-faces) |
|
171 |
|
|
172 |
(defface magit-signature-good |
|
173 |
'((t :foreground "green")) |
|
174 |
"Face for good signatures." |
|
175 |
:group 'magit-faces) |
|
176 |
|
|
177 |
(defface magit-signature-bad |
|
178 |
'((t :foreground "red" :weight bold)) |
|
179 |
"Face for bad signatures." |
|
180 |
:group 'magit-faces) |
|
181 |
|
|
182 |
(defface magit-signature-untrusted |
|
183 |
'((t :foreground "cyan")) |
|
184 |
"Face for good untrusted signatures." |
|
185 |
:group 'magit-faces) |
|
186 |
|
|
187 |
(defface magit-signature-expired |
|
188 |
'((t :foreground "orange")) |
|
189 |
"Face for signatures that have expired." |
|
190 |
:group 'magit-faces) |
|
191 |
|
|
192 |
(defface magit-signature-expired-key |
|
193 |
'((t :inherit magit-signature-expired)) |
|
194 |
"Face for signatures made by an expired key." |
|
195 |
:group 'magit-faces) |
|
196 |
|
|
197 |
(defface magit-signature-revoked |
|
198 |
'((t :foreground "violet red")) |
|
199 |
"Face for signatures made by a revoked key." |
|
200 |
:group 'magit-faces) |
|
201 |
|
|
202 |
(defface magit-signature-error |
|
203 |
'((t :foreground "firebrick3")) |
|
204 |
"Face for signatures that cannot be checked (e.g. missing key)." |
|
205 |
:group 'magit-faces) |
|
206 |
|
|
207 |
(defface magit-cherry-unmatched |
|
208 |
'((t :foreground "cyan")) |
|
209 |
"Face for unmatched cherry commits." |
|
210 |
:group 'magit-faces) |
|
211 |
|
|
212 |
(defface magit-cherry-equivalent |
|
213 |
'((t :foreground "magenta")) |
|
214 |
"Face for equivalent cherry commits." |
|
215 |
:group 'magit-faces) |
|
216 |
|
|
217 |
(defface magit-filename |
|
218 |
'((t :weight normal)) |
|
219 |
"Face for filenames." |
|
220 |
:group 'magit-faces) |
|
221 |
|
|
222 |
;;; Dispatch Popup |
|
223 |
|
|
224 |
;;;###autoload (autoload 'magit-dispatch-popup "magit" nil t) |
|
225 |
(magit-define-popup magit-dispatch-popup |
|
226 |
"Popup console for dispatching other popups." |
|
227 |
:actions '("Popup and dwim commands" |
|
228 |
(?A "Cherry-picking" magit-cherry-pick-popup) |
|
229 |
(?b "Branching" magit-branch-popup) |
|
230 |
(?B "Bisecting" magit-bisect-popup) |
|
231 |
(?c "Committing" magit-commit-popup) |
|
232 |
(?d "Diffing" magit-diff-popup) |
|
233 |
(?D "Change diffs" magit-diff-refresh-popup) |
|
234 |
(?e "Ediff dwimming" magit-ediff-dwim) |
|
235 |
(?E "Ediffing" magit-ediff-popup) |
|
236 |
(?f "Fetching" magit-fetch-popup) |
|
237 |
(?F "Pulling" magit-pull-popup) |
|
238 |
(?l "Logging" magit-log-popup) |
|
239 |
(?L "Change logs" magit-log-refresh-popup) |
|
240 |
(?m "Merging" magit-merge-popup) |
|
241 |
(?M "Remoting" magit-remote-popup) |
|
242 |
(?o "Submodules" magit-submodule-popup) |
|
243 |
(?O "Subtrees" magit-subtree-popup) |
|
244 |
(?P "Pushing" magit-push-popup) |
|
245 |
(?r "Rebasing" magit-rebase-popup) |
|
246 |
(?t "Tagging" magit-tag-popup) |
|
247 |
(?T "Notes" magit-notes-popup) |
|
248 |
(?V "Reverting" magit-revert-popup) |
|
249 |
(?w "Apply patches" magit-am-popup) |
|
250 |
(?W "Format patches" magit-patch-popup) |
|
251 |
(?X "Resetting" magit-reset-popup) |
|
252 |
(?y "Show Refs" magit-show-refs-popup) |
|
253 |
(?z "Stashing" magit-stash-popup) |
|
254 |
(?! "Running" magit-run-popup) |
|
255 |
(?% "Worktree" magit-worktree-popup) |
|
256 |
(lambda () |
|
257 |
(and (with-current-buffer magit-pre-popup-buffer |
|
258 |
(derived-mode-p 'magit-mode)) |
|
259 |
(propertize "Applying changes" 'face 'magit-popup-heading))) |
|
260 |
(?a "Apply" magit-apply) |
|
261 |
(?s "Stage" magit-stage) |
|
262 |
(?u "Unstage" magit-unstage) |
|
263 |
(?v "Reverse" magit-reverse) |
|
264 |
(?S "Stage all" magit-stage-modified) |
|
265 |
(?U "Unstage all" magit-unstage-all) |
|
266 |
(?k "Discard" magit-discard) |
|
267 |
(lambda () |
|
268 |
(and (with-current-buffer magit-pre-popup-buffer |
|
269 |
(derived-mode-p 'magit-mode)) |
|
270 |
(propertize "Essential commands" 'face 'magit-popup-heading))) |
|
271 |
(?g " refresh current buffer" magit-refresh) |
|
272 |
;; These bindings only work because of :setup-function. |
|
273 |
(?\t " toggle section at point" magit-section-toggle) |
|
274 |
(?\r " visit thing at point" magit-visit-thing) |
|
275 |
;; This binding has no effect and only appears to do |
|
276 |
;; so because it is identical to the global binding. |
|
277 |
("C-h m" "show all key bindings" describe-mode)) |
|
278 |
:setup-function 'magit-dispatch-popup-setup |
|
279 |
:max-action-columns (lambda (heading) |
|
280 |
(pcase heading |
|
281 |
("Popup and dwim commands" 4) |
|
282 |
("Applying changes" 3) |
|
283 |
("Essential commands" 1)))) |
|
284 |
|
|
285 |
(defvar magit-dispatch-popup-map |
|
286 |
(let ((map (make-sparse-keymap))) |
|
287 |
(set-keymap-parent map magit-popup-mode-map) |
|
288 |
(cond ((featurep 'jkl) |
|
289 |
(define-key map [tab] 'magit-invoke-popup-action) |
|
290 |
(define-key map [return] 'magit-invoke-popup-action)) |
|
291 |
(t |
|
292 |
(define-key map (kbd "C-i") 'magit-invoke-popup-action) |
|
293 |
(define-key map (kbd "C-m") 'magit-invoke-popup-action))) |
|
294 |
map) |
|
295 |
"Keymap used by `magit-dispatch-popup'.") |
|
296 |
|
|
297 |
(defun magit-dispatch-popup-setup (val def) |
|
298 |
(magit-popup-default-setup val def) |
|
299 |
(use-local-map magit-dispatch-popup-map) |
|
300 |
;; This is necessary for users (i.e. me) who have broken the |
|
301 |
;; connection between C-i (aka TAB) and tab, and C-m (aka RET) |
|
302 |
;; and return. |
|
303 |
(magit-popup-put |
|
304 |
:actions (nconc (magit-popup-get :actions) |
|
305 |
(list (make-magit-popup-event :key 'tab |
|
306 |
:fun 'magit-section-toggle) |
|
307 |
(make-magit-popup-event :key 'return |
|
308 |
:fun 'magit-visit-thing))))) |
|
309 |
|
|
310 |
;;; Git Popup |
|
311 |
|
|
312 |
(defcustom magit-shell-command-verbose-prompt t |
|
313 |
"Whether to show the working directory when reading a command. |
|
314 |
This affects `magit-git-command', `magit-git-command-topdir', |
|
315 |
`magit-shell-command', and `magit-shell-command-topdir'." |
|
316 |
:package-version '(magit . "2.11.0") |
|
317 |
:group 'magit-commands |
|
318 |
:type 'boolean) |
|
319 |
|
|
320 |
(defvar magit-git-command-history nil) |
|
321 |
|
|
322 |
;;;###autoload (autoload 'magit-run-popup "magit" nil t) |
|
323 |
(magit-define-popup magit-run-popup |
|
324 |
"Popup console for running raw Git commands." |
|
325 |
:actions '((?! "Git Subcommand (in topdir)" magit-git-command-topdir) |
|
326 |
(?k "Gitk" magit-run-gitk) |
|
327 |
(?p "Git Subcommand (in pwd)" magit-git-command) |
|
328 |
(?a "Gitk --all" magit-run-gitk-all) |
|
329 |
(?s "Shell command (in topdir)" magit-shell-command-topdir) |
|
330 |
(?b "Gitk --branches" magit-run-gitk-branches) |
|
331 |
(?S "Shell command (in pwd)" magit-shell-command) |
|
332 |
(?g "Git Gui" magit-run-git-gui)) |
|
333 |
:default-action 'magit-git-command |
|
334 |
:max-action-columns 2) |
|
335 |
|
|
336 |
;;;###autoload |
|
337 |
(defun magit-git-command (command) |
|
338 |
"Execute COMMAND asynchronously; display output. |
|
339 |
|
|
340 |
Interactively, prompt for COMMAND in the minibuffer. \"git \" is |
|
341 |
used as initial input, but can be deleted to run another command. |
|
342 |
|
|
343 |
With a prefix argument COMMAND is run in the top-level directory |
|
344 |
of the current working tree, otherwise in `default-directory'." |
|
345 |
(interactive (list (magit-read-shell-command nil "git "))) |
|
346 |
(magit--shell-command command)) |
|
347 |
|
|
348 |
;;;###autoload |
|
349 |
(defun magit-git-command-topdir (command) |
|
350 |
"Execute COMMAND asynchronously; display output. |
|
351 |
|
|
352 |
Interactively, prompt for COMMAND in the minibuffer. \"git \" is |
|
353 |
used as initial input, but can be deleted to run another command. |
|
354 |
|
|
355 |
COMMAND is run in the top-level directory of the current |
|
356 |
working tree." |
|
357 |
(interactive (list (magit-read-shell-command t "git "))) |
|
358 |
(magit--shell-command command (magit-toplevel))) |
|
359 |
|
|
360 |
;;;###autoload |
|
361 |
(defun magit-shell-command (command) |
|
362 |
"Execute COMMAND asynchronously; display output. |
|
363 |
|
|
364 |
Interactively, prompt for COMMAND in the minibuffer. With a |
|
365 |
prefix argument COMMAND is run in the top-level directory of |
|
366 |
the current working tree, otherwise in `default-directory'." |
|
367 |
(interactive (list (magit-read-shell-command))) |
|
368 |
(magit--shell-command command)) |
|
369 |
|
|
370 |
;;;###autoload |
|
371 |
(defun magit-shell-command-topdir (command) |
|
372 |
"Execute COMMAND asynchronously; display output. |
|
373 |
|
|
374 |
Interactively, prompt for COMMAND in the minibuffer. COMMAND |
|
375 |
is run in the top-level directory of the current working tree." |
|
376 |
(interactive (list (magit-read-shell-command t))) |
|
377 |
(magit--shell-command command (magit-toplevel))) |
|
378 |
|
|
379 |
(defun magit--shell-command (command &optional directory) |
|
380 |
(let ((default-directory (or directory default-directory)) |
|
381 |
(process-environment process-environment)) |
|
382 |
(push "GIT_PAGER=cat" process-environment) |
|
383 |
(magit-start-process shell-file-name nil |
|
384 |
shell-command-switch command)) |
|
385 |
(magit-process-buffer)) |
|
386 |
|
|
387 |
(defun magit-read-shell-command (&optional toplevel initial-input) |
|
388 |
(let ((dir (abbreviate-file-name |
|
389 |
(if (or toplevel current-prefix-arg) |
|
390 |
(or (magit-toplevel) |
|
391 |
(magit--not-inside-repository-error)) |
|
392 |
default-directory)))) |
|
393 |
(read-shell-command (if magit-shell-command-verbose-prompt |
|
394 |
(format "Async shell command in %s: " dir) |
|
395 |
"Async shell command: ") |
|
396 |
initial-input 'magit-git-command-history))) |
|
397 |
|
|
398 |
;;; Font-Lock Keywords |
|
399 |
|
|
400 |
(defconst magit-font-lock-keywords |
|
401 |
(eval-when-compile |
|
402 |
`((,(concat "(\\(magit-define-section-jumper\\)\\_>" |
|
403 |
"[ \t'\(]*" |
|
404 |
"\\(\\(?:\\sw\\|\\s_\\)+\\)?") |
|
405 |
(1 'font-lock-keyword-face) |
|
406 |
(2 'font-lock-function-name-face nil t)) |
|
407 |
(,(concat "(" (regexp-opt '("magit-insert-section" |
|
408 |
"magit-section-case" |
|
409 |
"magit-bind-match-strings" |
|
410 |
"magit-with-temp-index" |
|
411 |
"magit-with-blob" |
|
412 |
"magit-with-toplevel") t) |
|
413 |
"\\_>") |
|
414 |
. 1)))) |
|
415 |
|
|
416 |
(font-lock-add-keywords 'emacs-lisp-mode magit-font-lock-keywords) |
|
417 |
|
|
418 |
;;; Version |
|
419 |
|
|
420 |
(defvar magit-version 'undefined |
|
421 |
"The version of Magit that you're using. |
|
422 |
Use the function by the same name instead of this variable.") |
|
423 |
|
|
424 |
;;;###autoload |
|
425 |
(defun magit-version (&optional print-dest) |
|
426 |
"Return the version of Magit currently in use. |
|
427 |
If optional argument PRINT-DEST is non-nil, output |
|
428 |
stream (interactively, the echo area, or the current buffer with |
|
429 |
a prefix argument), also print the used versions of Magit, Git, |
|
430 |
and Emacs to it." |
|
431 |
(interactive (list (if current-prefix-arg (current-buffer) t))) |
|
432 |
(let ((magit-git-global-arguments nil) |
|
433 |
(toplib (or load-file-name buffer-file-name)) |
|
434 |
debug) |
|
435 |
(unless (and toplib |
|
436 |
(equal (file-name-nondirectory toplib) "magit.el")) |
|
437 |
(setq toplib (locate-library "magit.el"))) |
|
438 |
(setq toplib (and toplib (file-chase-links toplib))) |
|
439 |
(push toplib debug) |
|
440 |
(when toplib |
|
441 |
(let* ((topdir (file-name-directory toplib)) |
|
442 |
(gitdir (expand-file-name |
|
443 |
".git" (file-name-directory |
|
444 |
(directory-file-name topdir)))) |
|
445 |
(static (locate-library "magit-version.el" nil (list topdir))) |
|
446 |
(static (and static (file-chase-links static)))) |
|
447 |
(or (progn |
|
448 |
(push 'repo debug) |
|
449 |
(when (and (file-exists-p gitdir) |
|
450 |
;; It is a repo, but is it the Magit repo? |
|
451 |
(file-exists-p |
|
452 |
(expand-file-name "../lisp/magit.el" gitdir))) |
|
453 |
(push t debug) |
|
454 |
;; Inside the repo the version file should only exist |
|
455 |
;; while running make. |
|
456 |
(when (and static (not noninteractive)) |
|
457 |
(ignore-errors (delete-file static))) |
|
458 |
(setq magit-version |
|
459 |
(let ((default-directory topdir)) |
|
460 |
(magit-git-string "describe" "--tags" "--dirty"))))) |
|
461 |
(progn |
|
462 |
(push 'static debug) |
|
463 |
(when (and static (file-exists-p static)) |
|
464 |
(push t debug) |
|
465 |
(load-file static) |
|
466 |
magit-version)) |
|
467 |
(when (featurep 'package) |
|
468 |
(push 'elpa debug) |
|
469 |
(ignore-errors |
|
470 |
(--when-let (assq 'magit package-alist) |
|
471 |
(push t debug) |
|
472 |
(setq magit-version |
|
473 |
(and (fboundp 'package-desc-version) |
|
474 |
(package-version-join |
|
475 |
(package-desc-version (cadr it)))))))) |
|
476 |
(progn |
|
477 |
(push 'dirname debug) |
|
478 |
(let ((dirname (file-name-nondirectory |
|
479 |
(directory-file-name topdir)))) |
|
480 |
(when (string-match "\\`magit-\\([0-9]\\{8\\}\\.[0-9]*\\)" |
|
481 |
dirname) |
|
482 |
(setq magit-version (match-string 1 dirname)))))))) |
|
483 |
(if (stringp magit-version) |
|
484 |
(when print-dest |
|
485 |
(princ (format "Magit %s, Git %s, Emacs %s, %s" |
|
486 |
(or magit-version "(unknown)") |
|
487 |
(or (let ((magit-git-debug |
|
488 |
(lambda (err) |
|
489 |
(display-warning '(magit git) |
|
490 |
err :error)))) |
|
491 |
(magit-git-version t)) |
|
492 |
"(unknown)") |
|
493 |
emacs-version |
|
494 |
system-type) |
|
495 |
print-dest)) |
|
496 |
(setq debug (reverse debug)) |
|
497 |
(setq magit-version 'error) |
|
498 |
(when magit-version |
|
499 |
(push magit-version debug)) |
|
500 |
(unless (equal (getenv "TRAVIS") "true") |
|
501 |
;; The repository is a sparse clone. |
|
502 |
(message "Cannot determine Magit's version %S" debug))) |
|
503 |
magit-version)) |
|
504 |
|
|
505 |
;;; Debugging Tools |
|
506 |
|
|
507 |
(defun magit-debug-git-executable () |
|
508 |
"Display a buffer with information about `magit-git-executable'. |
|
509 |
See info node `(magit)Debugging Tools' for more information." |
|
510 |
(interactive) |
|
511 |
(with-current-buffer (get-buffer-create "*magit-git-debug*") |
|
512 |
(pop-to-buffer (current-buffer)) |
|
513 |
(erase-buffer) |
|
514 |
(insert (concat |
|
515 |
(format "magit-git-executable: %S" magit-git-executable) |
|
516 |
(and (not (file-name-absolute-p magit-git-executable)) |
|
517 |
(format " [%S]" (executable-find magit-git-executable))) |
|
518 |
(format " (%s)\n" |
|
519 |
(let* ((errmsg nil) |
|
520 |
(magit-git-debug (lambda (err) (setq errmsg err)))) |
|
521 |
(or (magit-git-version t) errmsg))))) |
|
522 |
(insert (format "exec-path: %S\n" exec-path)) |
|
523 |
(--when-let (cl-set-difference |
|
524 |
(-filter #'file-exists-p (remq nil (parse-colon-path |
|
525 |
(getenv "PATH")))) |
|
526 |
(-filter #'file-exists-p (remq nil exec-path)) |
|
527 |
:test #'file-equal-p) |
|
528 |
(insert (format " entries in PATH, but not in exec-path: %S\n" it))) |
|
529 |
(dolist (execdir exec-path) |
|
530 |
(insert (format " %s (%s)\n" execdir (car (file-attributes execdir)))) |
|
531 |
(when (file-directory-p execdir) |
|
532 |
(dolist (exec (directory-files |
|
533 |
execdir t (concat |
|
534 |
"\\`git" (regexp-opt exec-suffixes) "\\'"))) |
|
535 |
(insert (format " %s (%s)\n" exec |
|
536 |
(let* ((magit-git-executable exec) |
|
537 |
(errmsg nil) |
|
538 |
(magit-git-debug (lambda (err) (setq errmsg err)))) |
|
539 |
(or (magit-git-version t) errmsg))))))))) |
|
540 |
|
|
541 |
;;; Startup Asserts |
|
542 |
|
|
543 |
(defun magit-startup-asserts () |
|
544 |
(when-let ((val (getenv "GIT_DIR"))) |
|
545 |
(setenv "GIT_DIR") |
|
546 |
(message "Magit unset $GIT_DIR (was %S). See \ |
|
547 |
https://github.com/magit/magit/wiki/Don't-set-$GIT_DIR-and-alike" val)) |
|
548 |
(when-let ((val (getenv "GIT_WORK_TREE"))) |
|
549 |
(setenv "GIT_WORK_TREE") |
|
550 |
(message "Magit unset $GIT_WORK_TREE (was %S). See \ |
|
551 |
https://github.com/magit/magit/wiki/Don't-set-$GIT_DIR-and-alike" val)) |
|
552 |
(let ((version (magit-git-version))) |
|
553 |
(when (and version |
|
554 |
(version< version magit--minimal-git) |
|
555 |
(not (equal (getenv "TRAVIS") "true"))) |
|
556 |
(display-warning 'magit (format "\ |
|
557 |
Magit requires Git >= %s, you are using %s. |
|
558 |
|
|
559 |
If this comes as a surprise to you, because you do actually have |
|
560 |
a newer version installed, then that probably means that the |
|
561 |
older version happens to appear earlier on the `$PATH'. If you |
|
562 |
always start Emacs from a shell, then that can be fixed in the |
|
563 |
shell's init file. If you start Emacs by clicking on an icon, |
|
564 |
or using some sort of application launcher, then you probably |
|
565 |
have to adjust the environment as seen by graphical interface. |
|
566 |
For X11 something like ~/.xinitrc should work. |
|
567 |
|
|
568 |
If you use Tramp to work inside remote Git repositories, then you |
|
569 |
have to make sure a suitable Git is used on the remote machines |
|
570 |
too.\n" magit--minimal-git version) :error))) |
|
571 |
(when (version< emacs-version magit--minimal-emacs) |
|
572 |
(display-warning 'magit (format "\ |
|
573 |
Magit requires Emacs >= %s, you are using %s. |
|
574 |
|
|
575 |
If this comes as a surprise to you, because you do actually have |
|
576 |
a newer version installed, then that probably means that the |
|
577 |
older version happens to appear earlier on the `$PATH'. If you |
|
578 |
always start Emacs from a shell, then that can be fixed in the |
|
579 |
shell's init file. If you start Emacs by clicking on an icon, |
|
580 |
or using some sort of application launcher, then you probably |
|
581 |
have to adjust the environment as seen by graphical interface. |
|
582 |
For X11 something like ~/.xinitrc should work.\n" |
|
583 |
magit--minimal-emacs emacs-version) |
|
584 |
:error))) |
|
585 |
|
|
586 |
;;; Loading Libraries |
|
587 |
|
|
588 |
(provide 'magit) |
|
589 |
|
|
590 |
(cl-eval-when (load eval) |
|
591 |
(require 'magit-status) |
|
592 |
(require 'magit-refs) |
|
593 |
(require 'magit-files) |
|
594 |
(require 'magit-collab) |
|
595 |
(require 'magit-reset) |
|
596 |
(require 'magit-branch) |
|
597 |
(require 'magit-merge) |
|
598 |
(require 'magit-tag) |
|
599 |
(require 'magit-worktree) |
|
600 |
(require 'magit-notes) |
|
601 |
(require 'magit-sequence) |
|
602 |
(require 'magit-commit) |
|
603 |
(require 'magit-remote) |
|
604 |
(require 'magit-clone) |
|
605 |
(require 'magit-fetch) |
|
606 |
(require 'magit-pull) |
|
607 |
(require 'magit-push) |
|
608 |
(require 'magit-bisect) |
|
609 |
(require 'magit-stash) |
|
610 |
(require 'magit-blame) |
|
611 |
(require 'magit-obsolete) |
|
612 |
(require 'magit-submodule) |
|
613 |
(unless (load "magit-autoloads" t t) |
|
614 |
(require 'magit-subtree) |
|
615 |
(require 'magit-ediff) |
|
616 |
(require 'magit-extras) |
|
617 |
(require 'git-rebase) |
|
618 |
(require 'magit-imenu) |
|
619 |
(require 'magit-bookmark))) |
|
620 |
|
|
621 |
(eval-after-load 'bookmark |
|
622 |
'(require 'magit-bookmark)) |
|
623 |
|
|
624 |
(if after-init-time |
|
625 |
(progn (magit-startup-asserts) |
|
626 |
(magit-version)) |
|
627 |
(add-hook 'after-init-hook #'magit-startup-asserts t) |
|
628 |
(add-hook 'after-init-hook #'magit-version t)) |
|
629 |
|
|
630 |
;;; magit.el ends here |