Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARSE] sparse-checkout builtin V0 #178

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
/git-show-branch
/git-show-index
/git-show-ref
/git-sparse-checkout
/git-stage
/git-stash
/git-status
Expand Down
4 changes: 3 additions & 1 deletion Documentation/config/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,9 @@ core.gvfs::
--

core.sparseCheckout::
Enable "sparse checkout" feature. See section "Sparse checkout" in
Enable "sparse checkout" feature. Use "true" to enable the full pattern
set, or "cone" to enable the restricted cone-based patterns. Defaults to
"false", where the feature is disabled. See section "Sparse checkout" in
linkgit:git-read-tree[1] for more information.

core.abbrev::
Expand Down
120 changes: 120 additions & 0 deletions Documentation/git-sparse-checkout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
git-sparse-checkout(1)
=======================

NAME
----
git-sparse-checkout - Initialize and modify the sparse-checkout
configuration, which reduces the checkout to a set of directories
given by a list of prefixes.


SYNOPSIS
--------
[verse]
'git sparse-checkout [init|add|list]'


DESCRIPTION
-----------

Initialize and modify the sparse-checkout configuration, which reduces
the checkout to a set of directories given by a list of prefixes.


COMMANDS
--------
'init'::
Enable the `core.sparseCheckout` setting and clear all folders not
included by the sparse-checkout file. Typically, no sparse-checkout
file will exist when this command is run, so all directories in the
working directory will be removed.

'add'::
Given a list of paths over stdin, add those paths to the
sparse-checkout file. Refresh the index and working directory to
place the necessary files on disk.

'list'::
Provide a list of the contents in the sparse-checkout file.


SPARSE CHECKOUT
----------------

The sparse-checkout feature provides simple way to reduce the "cone" of files
in the working directory which are populated by Git. The sparse-checkout file
specifies a list of directories from the working directory root, and the list
of paths included are as follows:

1. Any path that is contained in a folder listed in the sparse-checkout file.
For example, if `A/B/C` is in the sparse-checkout file, then `A/B/C/D/e.txt`
will exist in the working directory.

2. Any path whose immediate parent folder is an ancestor of a folder listed in
the sparse-checkout file. For example, all files in the root directory are
included -- even if the sparse-checkout file is empty. As another example,
if `A/B/C` is in the sparse-checkout file, then `A/foo.txt` and `A/B/bar.c`
would be included. Note that `A/F/xyz.h` would not be included, as its
immediate parent (`A/F`) is not a prefix of `A/B/C`.

Note that the pattern matching in the sparse-checkout feature is very restricted,
unlike the sparse-checkout feature. The sparse-checkout and sparse-checkout
features both use the skip-worktree bits in the index file to interact with
other features in Git, but otherwise are incompatible. Creating a sparse-checkout
file to include files according to the rules above is difficult, and the
pattern matching required by the sparse-checkout feature leads to quadratic
growth: for N patterns and M index entries, we must check O(N * M) patterns.

Conversely, the sparse-checkout feature does not allow negative patterns or
file-name based patterns. If you want to exclude all files ending in ".exe"
you could include the line `!*.exe` in the sparse-checkout file. This is not
available in the sparse-checkout feature.

To use the sparse-checkout feature, you must enable the `core.partialCheckout`
config setting. This setting will override the `core.sparseCheckout` setting,
so any values in the sparse-checkout file will be ignored.

To initialize an existing repo to use the sparse-checkout feature, run
`git sparse-checkout init`. This will enable `core.partialCheckout`, remove
all directories in the root of the working directory, and then update the
working directory to contain the folders that may already exist in the
sparse-checkout file. In the usual case, the sparse-checkout file will be
empty and you will only see files in the working directory root.

To add folders to the sparse-checkout file, run the `add` subcommand, and
provide the list over standard-in:

```
$git sparse-checkout add
A/B/C
Docs
tests
^D
```

Since these folders do not exist in your working directory, you can use
`git ls-tree HEAD -- <path>` to help discover folders that exist in your
repo.

After adding the folders to the sparse-checkout file, Git will update the index
and run `git reset --hard` to place the files on disk. Due to the use of
`git reset --hard`, the command will halt with an error before doing any work
if you do not have a clean `git status`.

If you wish to reduce your working directory, you can use the
`git sparse-checkout remove` subcommand. It takes a list of folders from
standard in, removes them from the sparse-checkout file and deletes them from
your working directory, then runs `git reset --hard` to ensure the index is
up to date.

To check which folders are included in the sparse-checkout file, run the
`git sparse-checkout list` subcommand.

SEE ALSO
--------

linkgit:git-read-tree[1]

GIT
---
Part of the linkgit:git[1] suite
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ BUILTIN_OBJS += builtin/shortlog.o
BUILTIN_OBJS += builtin/show-branch.o
BUILTIN_OBJS += builtin/show-index.o
BUILTIN_OBJS += builtin/show-ref.o
BUILTIN_OBJS += builtin/sparse-checkout.o
BUILTIN_OBJS += builtin/stash.o
BUILTIN_OBJS += builtin/stripspace.o
BUILTIN_OBJS += builtin/submodule--helper.o
Expand Down
1 change: 1 addition & 0 deletions builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix);
int cmd_show(int argc, const char **argv, const char *prefix);
int cmd_show_branch(int argc, const char **argv, const char *prefix);
int cmd_show_index(int argc, const char **argv, const char *prefix);
int cmd_sparse_checkout(int argc, const char **argv, const char *prefix);
int cmd_status(int argc, const char **argv, const char *prefix);
int cmd_stash(int argc, const char **argv, const char *prefix);
int cmd_stripspace(int argc, const char **argv, const char *prefix);
Expand Down
Loading