diff options
| author | Kyle Meyer <kyle@kyleam.com> | 2022-01-17 21:08:31 -0500 |
|---|---|---|
| committer | Kyle Meyer <kyle@kyleam.com> | 2022-01-23 16:30:36 -0500 |
| commit | eb56b14bcb61b8131a45e6113da770b2ef92c160 (patch) | |
| tree | c19774c9c77e37e9294584fb6372edfe16801ae7 | |
| parent | f8f938352d71680b533a8cf21dcada0809cdb51a (diff) | |
magit-clone: Add --filter to support partial clones
Git gained partial clone support via its --filter argument in v2.17
(undocumented until v2.27.0). Add the option to the clone transient,
along with a custom reader that offers the two mostly likely values of
interest (blobless and treeless clones). See git-rev-list's manpage
for a complete description of the filter specification.
Note that users should probably expect to hit into rough edges when
working with a partial clone. For example, without a connection,
checking out a commit for which blobs need to be downloaded will
"fail" in the sense that it the checkout command will emit errors and
`git status' from the command line will show deleted files for files
that couldn't be downloaded. While that's not surprising, the
checkout command has an exit status of 0 [*], so Magit users won't see
an indication of the failure. And worse, the deleted files won't show
up in the status buffer because the underlying git-diff commands fail
(for the same reason as the checkout: the required objects can't be
downloaded).
[*] I haven't yet reported this upstream, but it seems like a bug to
me.
| -rw-r--r-- | docs/RelNotes/3.4.0.org | 4 | ||||
| -rw-r--r-- | lisp/magit-clone.el | 15 |
2 files changed, 19 insertions, 0 deletions
diff --git a/docs/RelNotes/3.4.0.org b/docs/RelNotes/3.4.0.org index 86fa3c3..a46e266 100644 --- a/docs/RelNotes/3.4.0.org +++ b/docs/RelNotes/3.4.0.org @@ -20,6 +20,10 @@ repository and then immediately enable a sparse checkout, avoiding a checkout of the full working tree. #4102 +- The ~magit-clone~ transient now includes ~--filter~ (hidden by + default) to support partial cloning, a feature that is available as + of Git v2.17. #4102 + ** Fixes since v3.3.0 - Automatic saving of file-visiting buffers was broken inside remote diff --git a/lisp/magit-clone.el b/lisp/magit-clone.el index 91e06ce..8f5e910 100644 --- a/lisp/magit-clone.el +++ b/lisp/magit-clone.el @@ -117,6 +117,9 @@ the name of the owner. Also see `magit-clone-name-alist'." ["Setup arguments" ("-o" "Set name of remote" ("-o" "--origin=")) ("-b" "Set HEAD branch" ("-b" "--branch=")) + (magit-clone:--filter + :if (lambda () (magit-git-version>= "2.17.0")) + :level 7) ("-g" "Separate git directory" "--separate-git-dir=" transient-read-directory :level 7) ("-t" "Use template directory" "--template=" @@ -139,6 +142,18 @@ the name of the owner. Also see `magit-clone-name-alist'." (transient-setup #'magit-clone) (call-interactively #'magit-clone-regular))) +(transient-define-argument magit-clone:--filter () + :description "Filter some objects" + :class 'transient-option + :key "-f" + :argument "--filter=" + :reader 'magit-clone-read-filter) + +(defun magit-clone-read-filter (prompt initial-input history) + (magit-completing-read prompt + (list "blob:none" "tree:0") + nil nil initial-input history)) + ;;;###autoload (defun magit-clone-regular (repository directory args) "Create a clone of REPOSITORY in DIRECTORY. |
