Add TestPrepareWikiFileName (#16487)

* Add TestPrepareWikiFileName

* use LsTree as LsFiles is index only

* ajust other tests

Co-authored-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
6543 2021-07-20 15:16:20 +02:00 committed by GitHub
parent 2635778425
commit b26c3b482f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 4 deletions

View file

@ -6,6 +6,7 @@
package git
import (
"bytes"
"strings"
)
@ -45,3 +46,23 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) {
}
return g, nil
}
// LsTree checks if the given filenames are in the tree
func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error) {
cmd := NewCommand("ls-tree", "-z", "--name-only", "--", ref)
for _, arg := range filenames {
if arg != "" {
cmd.AddArguments(arg)
}
}
res, err := cmd.RunInDirBytes(repo.Path)
if err != nil {
return nil, err
}
filelist := make([]string, 0, len(filenames))
for _, line := range bytes.Split(res, []byte{'\000'}) {
filelist = append(filelist, string(line))
}
return filelist, err
}