Skip to content

Commit 4f35eba

Browse files
pjbgfkane8n
authored andcommitted
Merge pull request #1484 from patricsss/patricsss/fix-1455
utils: fix diff so subpaths work for sparse checkouts, fixes 1455
1 parent fd1a836 commit 4f35eba

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

utils/merkletrie/change.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (l *Changes) addRecursive(root noder.Path, ctor noderToChangeFn) error {
150150
}
151151
return err
152152
}
153-
if current.IsDir() {
153+
if current.IsDir() || current.Skip() {
154154
continue
155155
}
156156
l.Add(ctor(current))

utils/merkletrie/index/node.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ func NewRootNode(idx *index.Index) noder.Noder {
3636
parent := fullpath
3737
fullpath = path.Join(fullpath, part)
3838

39-
if _, ok := m[fullpath]; ok {
39+
// It's possible that the first occurrence of subdirectory is skipped.
40+
// The parent node can be created with SkipWorktree set to true, but
41+
// if any future children do not skip their subtree, the entire lineage
42+
// of the tree needs to have this value set to false so that subdirectories
43+
// are not ignored.
44+
if parentNode, ok := m[fullpath]; ok {
45+
if e.SkipWorktree == false {
46+
parentNode.skip = false
47+
}
4048
continue
4149
}
4250

utils/merkletrie/index/node_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package index
22

33
import (
44
"bytes"
5-
"path/filepath"
5+
"path"
66
"testing"
77

88
"github.com/go-git/go-git/v5/plumbing"
@@ -46,14 +46,14 @@ func (s *NoderSuite) TestDiff(c *C) {
4646
func (s *NoderSuite) TestDiffChange(c *C) {
4747
indexA := &index.Index{
4848
Entries: []*index.Entry{{
49-
Name: filepath.Join("bar", "baz", "bar"),
49+
Name: path.Join("bar", "baz", "bar"),
5050
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
5151
}},
5252
}
5353

5454
indexB := &index.Index{
5555
Entries: []*index.Entry{{
56-
Name: filepath.Join("bar", "baz", "foo"),
56+
Name: path.Join("bar", "baz", "foo"),
5757
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
5858
}},
5959
}
@@ -63,6 +63,32 @@ func (s *NoderSuite) TestDiffChange(c *C) {
6363
c.Assert(ch, HasLen, 2)
6464
}
6565

66+
func (s *NoderSuite) TestDiffSkipIssue1455(c *C) {
67+
indexA := &index.Index{
68+
Entries: []*index.Entry{
69+
{
70+
Name: path.Join("bar", "baz", "bar"),
71+
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
72+
SkipWorktree: true,
73+
},
74+
{
75+
Name: path.Join("bar", "biz", "bat"),
76+
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
77+
SkipWorktree: false,
78+
},
79+
},
80+
}
81+
82+
indexB := &index.Index{}
83+
84+
ch, err := merkletrie.DiffTree(NewRootNode(indexB), NewRootNode(indexA), isEquals)
85+
c.Assert(err, IsNil)
86+
c.Assert(ch, HasLen, 1)
87+
a, err := ch[0].Action()
88+
c.Assert(err, IsNil)
89+
c.Assert(a, Equals, merkletrie.Insert)
90+
}
91+
6692
func (s *NoderSuite) TestDiffDir(c *C) {
6793
indexA := &index.Index{
6894
Entries: []*index.Entry{{
@@ -73,7 +99,7 @@ func (s *NoderSuite) TestDiffDir(c *C) {
7399

74100
indexB := &index.Index{
75101
Entries: []*index.Entry{{
76-
Name: filepath.Join("foo", "bar"),
102+
Name: path.Join("foo", "bar"),
77103
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
78104
}},
79105
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy