aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/index/index.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2021-12-10 06:51:49 +0100
committerGitHub <noreply@github.com>2021-12-10 06:51:49 +0100
commitfe158cd6e176682e087efea9625ec5409f2956bf (patch)
tree63afb89d42b388316d045820b44972f54e0b8f01 /plumbing/format/index/index.go
parent589a41ceedfa89e1ff334a969d1beb28cb731de9 (diff)
parent39f97ab86a776dd8acd58a79a660d0cfdb7068c0 (diff)
downloadgo-git-fe158cd6e176682e087efea9625ec5409f2956bf.tar.gz
Merge branch 'master' into jc-push-atomic
Diffstat (limited to 'plumbing/format/index/index.go')
-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
+ }
+ }
+}