aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format
diff options
context:
space:
mode:
authorJohn Cai <johncai86@gmail.com>2021-11-04 15:02:00 -0400
committerJohn Cai <jcai@gitlab.com>2021-11-09 08:45:09 -0500
commitf92011d95f98f5deea4959c7d432704a4300d3a8 (patch)
tree6929972e94cc168ca210532954b234b55bb24165 /plumbing/format
parente4fcd078d42e945581616855ab78d8b7ed12df6c (diff)
downloadgo-git-f92011d95f98f5deea4959c7d432704a4300d3a8.tar.gz
simplified sparse checkout
This is the initial logic to support a simple sparse checkout where directories to be included can be specified in CheckoutOptions. This change doesn't fully support the sparse patterns, nor does this change include the optimization to collapse flie entries in ithe index that are excluded via the sparse checkout directory patterns included under the parent directory.
Diffstat (limited to 'plumbing/format')
-rw-r--r--plumbing/format/index/index.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/plumbing/format/index/index.go b/plumbing/format/index/index.go
index 649416a..f4c7647 100644
--- a/plumbing/format/index/index.go
+++ b/plumbing/format/index/index.go
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"path/filepath"
+ "strings"
"time"
"github.com/go-git/go-git/v5/plumbing"
@@ -211,3 +212,20 @@ type EndOfIndexEntry struct {
// their contents).
Hash plumbing.Hash
}
+
+// SkipUnless applies patterns in the form of A, A/B, A/B/C
+// to the index to prevent the files from being checked out
+func (i *Index) SkipUnless(patterns []string) {
+ for _, e := range i.Entries {
+ var include bool
+ for _, pattern := range patterns {
+ if strings.HasPrefix(e.Name, pattern) {
+ include = true
+ break
+ }
+ }
+ if !include {
+ e.SkipWorktree = true
+ }
+ }
+}