diff --git a/git/githistory/fixtures_test.go b/git/githistory/fixtures_test.go index b7eee22b..25f8c466 100644 --- a/git/githistory/fixtures_test.go +++ b/git/githistory/fixtures_test.go @@ -44,7 +44,7 @@ func AssertBlobContents(t *testing.T, db *odb.ObjectDatabase, tree, path, conten // Then, iterating through each part of the filepath (i.e., a/b/c.txt -> // []string{"a", "b", "c.txt"}). - parts := strings.Split(path, string(os.PathSeparator)) + parts := strings.Split(path, "/") for i := 0; i < len(parts)-1; i++ { part := parts[i] diff --git a/git/githistory/rewriter.go b/git/githistory/rewriter.go index fc17519d..c118a2ed 100644 --- a/git/githistory/rewriter.go +++ b/git/githistory/rewriter.go @@ -4,8 +4,7 @@ import ( "encoding/hex" "fmt" "io" - "os" - "path/filepath" + "strings" "sync" "github.com/git-lfs/git-lfs/errors" @@ -311,9 +310,14 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn entries := make([]*odb.TreeEntry, 0, len(tree.Entries)) for _, entry := range tree.Entries { - path := filepath.Join(path, entry.Name) + var epath string + if len(path) > 0 { + epath = strings.Join([]string{path, entry.Name}, "/") + } else { + epath = entry.Name + } - if !r.allows(entry.Type(), path) { + if !r.allows(entry.Type(), epath) { entries = append(entries, entry) continue } @@ -327,9 +331,9 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn switch entry.Type() { case odb.BlobObjectType: - oid, err = r.rewriteBlob(commitOID, entry.Oid, path, fn, perc) + oid, err = r.rewriteBlob(commitOID, entry.Oid, epath, fn, perc) case odb.TreeObjectType: - oid, err = r.rewriteTree(commitOID, entry.Oid, path, fn, tfn, perc) + oid, err = r.rewriteTree(commitOID, entry.Oid, epath, fn, tfn, perc) default: oid = entry.Oid @@ -345,7 +349,7 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn })) } - rewritten, err := tfn(string(os.PathSeparator)+path, &odb.Tree{Entries: entries}) + rewritten, err := tfn("/"+path, &odb.Tree{Entries: entries}) if err != nil { return nil, err } @@ -359,7 +363,7 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn func (r *Rewriter) allows(typ odb.ObjectType, abs string) bool { switch typ { case odb.BlobObjectType: - return r.Filter().Allows(abs) + return r.Filter().Allows(strings.TrimPrefix(abs, "/")) case odb.CommitObjectType, odb.TreeObjectType: return true default: diff --git a/git/githistory/rewriter_test.go b/git/githistory/rewriter_test.go index 4133bb68..0d570baf 100644 --- a/git/githistory/rewriter_test.go +++ b/git/githistory/rewriter_test.go @@ -3,9 +3,9 @@ package githistory import ( "bytes" "encoding/hex" + "fmt" "io" "io/ioutil" - "path/filepath" "reflect" "strconv" "strings" @@ -165,7 +165,7 @@ func TestRewriterDoesntVisitUnchangedSubtrees(t *testing.T) { assert.Nil(t, err) assert.Equal(t, 2, seen["a.txt"]) - assert.Equal(t, 1, seen[filepath.Join("subdir", "b.txt")]) + assert.Equal(t, 1, seen["subdir/b.txt"]) } func TestRewriterVisitsUniqueEntriesWithIdenticalContents(t *testing.T) { @@ -189,6 +189,10 @@ func TestRewriterVisitsUniqueEntriesWithIdenticalContents(t *testing.T) { tree := "bbbe0a7676523ae02234bfe874784ca2380c2d4b" + fmt.Println(hex.EncodeToString(tip)) + root, _ := db.Root() + fmt.Println(root) + AssertCommitTree(t, db, hex.EncodeToString(tip), tree) // After rewriting, the HEAD state of the repository should contain a