Skip to content

Commit d867084

Browse files
committed
use LsTree as LsFiles is index only
Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent c822a2e commit d867084

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

modules/git/tree.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package git
77

88
import (
9+
"bytes"
910
"strings"
1011
)
1112

@@ -45,3 +46,23 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) {
4546
}
4647
return g, nil
4748
}
49+
50+
// LsTree checks if the given filenames are in the tree
51+
func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error) {
52+
cmd := NewCommand("ls-tree", "-z", "--name-only", "--", ref)
53+
for _, arg := range filenames {
54+
if arg != "" {
55+
cmd.AddArguments(arg)
56+
}
57+
}
58+
res, err := cmd.RunInDirBytes(repo.Path)
59+
if err != nil {
60+
return nil, err
61+
}
62+
filelist := make([]string, 0, len(filenames))
63+
for _, line := range bytes.Split(res, []byte{'\000'}) {
64+
filelist = append(filelist, string(line))
65+
}
66+
67+
return filelist, err
68+
}

services/wiki/wiki.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func prepareWikiFileName(gitRepo *git.Repository, wikiName string) (bool, string
8888
escaped := NameToFilename(wikiName)
8989

9090
// Look for both files
91-
filesInIndex, err := gitRepo.LsFiles(unescaped, escaped)
91+
filesInIndex, err := gitRepo.LsTree("master", unescaped, escaped)
9292
if err != nil {
9393
log.Error("%v", err)
9494
return false, escaped, err

0 commit comments

Comments
 (0)