commit | author | age
|
5cb5f7
|
1 |
;;; magit-clone.el --- clone a repository -*- lexical-binding: t -*- |
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: Jonas Bernoulli <jonas@bernoul.li> |
|
9 |
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li> |
|
10 |
|
|
11 |
;; Magit is free software; you can redistribute it and/or modify it |
|
12 |
;; under the terms of the GNU General Public License as published by |
|
13 |
;; the Free Software Foundation; either version 3, or (at your option) |
|
14 |
;; any later version. |
|
15 |
;; |
|
16 |
;; Magit is distributed in the hope that it will be useful, but WITHOUT |
|
17 |
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
18 |
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
|
19 |
;; License for more details. |
|
20 |
;; |
|
21 |
;; You should have received a copy of the GNU General Public License |
|
22 |
;; along with Magit. If not, see http://www.gnu.org/licenses. |
|
23 |
|
|
24 |
;;; Commentary: |
|
25 |
|
|
26 |
;; This library implements clone commands. |
|
27 |
|
|
28 |
;;; Code: |
|
29 |
|
|
30 |
(require 'magit) |
|
31 |
|
|
32 |
;;; Options |
|
33 |
|
|
34 |
(defcustom magit-clone-set-remote-head nil |
|
35 |
"Whether cloning creates the symbolic-ref `<remote>/HEAD'." |
|
36 |
:package-version '(magit . "2.4.2") |
|
37 |
:group 'magit-commands |
|
38 |
:type 'boolean) |
|
39 |
|
|
40 |
(defcustom magit-clone-set-remote.pushDefault 'ask |
|
41 |
"Whether to set the value of `remote.pushDefault' after cloning. |
|
42 |
|
|
43 |
If t, then set without asking. If nil, then don't set. If |
|
44 |
`ask', then ask." |
|
45 |
:package-version '(magit . "2.4.0") |
|
46 |
:group 'magit-commands |
|
47 |
:type '(choice (const :tag "set" t) |
|
48 |
(const :tag "ask" ask) |
|
49 |
(const :tag "don't set" nil))) |
|
50 |
|
|
51 |
(defcustom magit-clone-default-directory nil |
|
52 |
"Default directory to use when `magit-clone' reads destination. |
|
53 |
If nil (the default), then use the value of `default-directory'. |
|
54 |
If a directory, then use that. If a function, then call that |
|
55 |
with the remote url as only argument and use the returned value." |
|
56 |
:package-version '(magit . "2.90.0") |
|
57 |
:group 'magit-commands |
|
58 |
:type '(choice (const :tag "value of default-directory") |
|
59 |
(directory :tag "constant directory") |
|
60 |
(function :tag "function's value"))) |
|
61 |
|
|
62 |
;;; Commands |
|
63 |
|
|
64 |
;;;###autoload |
|
65 |
(defun magit-clone (repository directory) |
|
66 |
"Clone the REPOSITORY to DIRECTORY. |
|
67 |
Then show the status buffer for the new repository." |
|
68 |
(interactive |
|
69 |
(let ((url (magit-read-string-ns "Clone repository"))) |
|
70 |
(list url (read-directory-name |
|
71 |
"Clone to: " |
|
72 |
(if (functionp magit-clone-default-directory) |
|
73 |
(funcall magit-clone-default-directory url) |
|
74 |
magit-clone-default-directory) |
|
75 |
nil nil |
|
76 |
(and (string-match "\\([^/:]+?\\)\\(/?\\.git\\)?$" url) |
|
77 |
(match-string 1 url)))))) |
|
78 |
(setq directory (file-name-as-directory (expand-file-name directory))) |
|
79 |
(magit-run-git-async "clone" repository |
|
80 |
(magit-convert-filename-for-git directory)) |
|
81 |
;; Don't refresh the buffer we're calling from. |
|
82 |
(process-put magit-this-process 'inhibit-refresh t) |
|
83 |
(set-process-sentinel |
|
84 |
magit-this-process |
|
85 |
(lambda (process event) |
|
86 |
(when (memq (process-status process) '(exit signal)) |
|
87 |
(let ((magit-process-raise-error t)) |
|
88 |
(magit-process-sentinel process event))) |
|
89 |
(when (and (eq (process-status process) 'exit) |
|
90 |
(= (process-exit-status process) 0)) |
|
91 |
(let ((default-directory directory)) |
|
92 |
(when (or (eq magit-clone-set-remote.pushDefault t) |
|
93 |
(and magit-clone-set-remote.pushDefault |
|
94 |
(y-or-n-p "Set `remote.pushDefault' to \"origin\"? "))) |
|
95 |
(setf (magit-get "remote.pushDefault") "origin")) |
|
96 |
(unless magit-clone-set-remote-head |
|
97 |
(magit-remote-unset-head "origin"))) |
|
98 |
(with-current-buffer (process-get process 'command-buf) |
|
99 |
(magit-status-internal directory)))))) |
|
100 |
|
|
101 |
;;; _ |
|
102 |
(provide 'magit-clone) |
|
103 |
;;; magit-clone.el ends here |