mirror of
https://github.com/fiatjaf/nak.git
synced 2026-10-05 15:18:23 +00:00
Merge pull request #207 from mattn/fix/git-cat-backslash-path
git: fix 'cat' returning the wrong file for paths with a backslash
This commit is contained in:
@@ -717,19 +717,43 @@ aside from those, there is also:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
entry, err := gitnaturalapi.GetObjectByPath(url, commit, path)
|
// the path is walked here instead of with GetObjectByPath()
|
||||||
|
// because that also treats '\' as a separator, while in git
|
||||||
|
// path names a backslash is just a regular character
|
||||||
|
segments := strings.Split(strings.Trim(path, "/"), "/")
|
||||||
|
name := segments[len(segments)-1]
|
||||||
|
|
||||||
|
depth := len(segments)
|
||||||
|
tree, err := gitnaturalapi.GetDirectoryTreeAt(url, commit, &depth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lastErr = err
|
lastErr = err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if entry == nil {
|
|
||||||
return fmt.Errorf("path '%s' not found", path)
|
if len(segments) > 1 {
|
||||||
}
|
tree, err = gitTreeAtPath(tree, strings.Join(segments[:len(segments)-1], "/"))
|
||||||
if entry.IsDir {
|
if err != nil {
|
||||||
return fmt.Errorf("path '%s' is a directory", path)
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err := gitnaturalapi.GetObject(url, entry.Hash)
|
hash := ""
|
||||||
|
for _, file := range tree.Files {
|
||||||
|
if file.Name == name {
|
||||||
|
hash = file.Hash
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hash == "" {
|
||||||
|
for _, dir := range tree.Directories {
|
||||||
|
if dir.Name == name {
|
||||||
|
return fmt.Errorf("path '%s' is a directory", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("path '%s' not found", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
obj, err := gitnaturalapi.GetObject(url, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lastErr = fmt.Errorf("download error: %s", err)
|
lastErr = fmt.Errorf("download error: %s", err)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user