[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/git-commit f8f938352d 5/7: magit-clone-sparse: New command
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/git-commit f8f938352d 5/7: magit-clone-sparse: New command |
Date: |
Sun, 23 Jan 2022 16:58:08 -0500 (EST) |
branch: elpa/git-commit
commit f8f938352d71680b533a8cf21dcada0809cdb51a
Author: Kyle Meyer <kyle@kyleam.com>
Commit: Kyle Meyer <kyle@kyleam.com>
magit-clone-sparse: New command
When the goal is to do a sparse checkout after cloning a repo, it's
possible to avoid checking out undesired files on the initial clone:
$ git clone --no-checkout ...
$ git sparse-checkout init --cone
$ git checkout $BRANCH
Doing that probably isn't very common, so it's tempting to add
--no-checkout to the magit-clone transient and then let users handle
the sequence themselves. However
* it seems unlikely that many people would remember that sequence
* those steps don't work well in Magit because, after the `clone
--no-checkout` step, refreshing the status buffer will get hung up
on all the "deleted" files. That's true even with a repo of
normal size, but it seems reasonable to expect larger target repos
in the sparse checkout context.
Add a dedicated command that hooks into magit-clone-internal to enable
a sparse checkout before a refresh is attempted.
---
docs/RelNotes/3.4.0.org | 4 ++++
docs/magit.org | 11 +++++++++++
lisp/magit-clone.el | 19 ++++++++++++++++++-
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/docs/RelNotes/3.4.0.org b/docs/RelNotes/3.4.0.org
index 3572db3b33..86fa3c34de 100644
--- a/docs/RelNotes/3.4.0.org
+++ b/docs/RelNotes/3.4.0.org
@@ -16,6 +16,10 @@
- New transient ~magit-sparse-checkout~ provides an interface to the
~git sparse-checkout~ command, introduced in Git v2.25. #4102
+- New command ~magit-clone-sparse~ makes it possible to clone a
+ repository and then immediately enable a sparse checkout, avoiding a
+ checkout of the full working tree. #4102
+
** Fixes since v3.3.0
- Automatic saving of file-visiting buffers was broken inside remote
diff --git a/docs/magit.org b/docs/magit.org
index a1c766c001..4432e34bfd 100644
--- a/docs/magit.org
+++ b/docs/magit.org
@@ -4141,6 +4141,13 @@ argument is used and on the value of
~magit-clone-always-transient~.
By default the depth of the cloned history is a single commit,
but with a prefix argument the depth is read from the user.
+- Key: C > (magit-clone-sparse) ::
+
+ This command creates a clone of an existing repository and
+ initializes a sparse checkout, avoiding a checkout of the full
+ working tree. To add more directories, use the
+ ~magit-sparse-checkout~ transient (see [[*Sparse checkouts]]).
+
- Key: C b (magit-clone-bare) ::
This command creates a bare clone of an existing repository.
@@ -7045,6 +7052,10 @@ version.
This command restores the full checkout. To return to the previous
sparse checkout, call ~magit-sparse-checkout-enable~.
+A sparse checkout can also be initiated when cloning a repository by
+using the ~magit-clone-sparse~ command in the ~magit-clone~ transient
+(see [[*Cloning Repository]]).
+
If you want the status buffer to indicate when a sparse checkout is
enabled, add the function ~magit-sparse-checkout-insert-header~ to
~magit-status-headers-hook~.
diff --git a/lisp/magit-clone.el b/lisp/magit-clone.el
index f2813cb88a..91e06ce8d6 100644
--- a/lisp/magit-clone.el
+++ b/lisp/magit-clone.el
@@ -129,6 +129,9 @@ the name of the owner. Also see `magit-clone-name-alist'."
("s" "shallow" magit-clone-shallow)
("d" "shallow since date" magit-clone-shallow-since :level 7)
("e" "shallow excluding" magit-clone-shallow-exclude :level 7)
+ (">" "sparse checkout" magit-clone-sparse
+ :if (lambda () (magit-git-version>= "2.25.0"))
+ :level 6)
("b" "bare" magit-clone-bare)
("m" "mirror" magit-clone-mirror)]
(interactive (list (or magit-clone-always-transient current-prefix-arg)))
@@ -193,7 +196,14 @@ Then show the status buffer for the new repository."
(interactive (magit-clone-read-args))
(magit-clone-internal repository directory (cons "--mirror" args)))
-(defun magit-clone-internal (repository directory args)
+;;;###autoload
+(defun magit-clone-sparse (repository directory args)
+ "Clone REPOSITORY into DIRECTORY and create a sparse checkout."
+ (interactive (magit-clone-read-args))
+ (magit-clone-internal repository directory (cons "--no-checkout" args)
+ 'sparse))
+
+(defun magit-clone-internal (repository directory args &optional sparse)
(let* ((checkout (not (memq (car args) '("--bare" "--mirror"))))
(remote (or (transient-arg-value "--origin" args)
(magit-get "clone.defaultRemote")
@@ -234,6 +244,13 @@ Then show the status buffer for the new repository."
(setf (magit-get "remote.pushDefault") remote))
(unless magit-clone-set-remote-head
(magit-remote-unset-head remote))))
+ (when (and sparse checkout)
+ (when (magit-git-version< "2.25.0")
+ (user-error
+ "`git sparse-checkout' not available until Git v2.25"))
+ (let ((default-directory directory))
+ (magit-call-git "sparse-checkout" "init" "--cone")
+ (magit-call-git "checkout" (magit-get-current-branch))))
(with-current-buffer (process-get process 'command-buf)
(magit-status-setup-buffer directory)))))))
- [nongnu] elpa/git-commit updated (ed7a4b24a2 -> 2a6b51b7f1), ELPA Syncer, 2022/01/23
- [nongnu] elpa/git-commit d1a3c60a9e 4/7: sparse-checkout: Add insert-header function, ELPA Syncer, 2022/01/23
- [nongnu] elpa/git-commit f8f938352d 5/7: magit-clone-sparse: New command,
ELPA Syncer <=
- [nongnu] elpa/git-commit c7fd760d99 1/7: magit-revision-directories: New function, ELPA Syncer, 2022/01/23
- [nongnu] elpa/git-commit ae3770306d 3/7: magit-sparse-checkout: Add --sparse-index, ELPA Syncer, 2022/01/23
- [nongnu] elpa/git-commit 2a6b51b7f1 7/7: manual: Regenerate, ELPA Syncer, 2022/01/23
- [nongnu] elpa/git-commit eb56b14bcb 6/7: magit-clone: Add --filter to support partial clones, ELPA Syncer, 2022/01/23
- [nongnu] elpa/git-commit 2d94a9b363 2/7: Add interface to 'git sparse-checkout', ELPA Syncer, 2022/01/23