update git vendor (#4059) (#4075)

* update git vendor (#4059)

* fix errors resulting from git vendor update

* fmt
This commit is contained in:
David Schneiderbauer
2018-06-04 22:33:42 +02:00
committed by Lauris BH
parent 561f459364
commit 1b10bc0cdf
12 changed files with 265 additions and 117 deletions

View File

@@ -5,6 +5,7 @@
package git
import (
"io"
"sort"
"strconv"
"strings"
@@ -90,6 +91,45 @@ func (te *TreeEntry) Blob() *Blob {
}
}
// FollowLink returns the entry pointed to by a symlink
func (te *TreeEntry) FollowLink() (*TreeEntry, error) {
if !te.IsLink() {
return nil, ErrBadLink{te.Name(), "not a symlink"}
}
// read the link
r, err := te.Blob().Data()
if err != nil {
return nil, err
}
buf := make([]byte, te.Size())
_, err = io.ReadFull(r, buf)
if err != nil {
return nil, err
}
lnk := string(buf)
t := te.ptree
// traverse up directories
for ; t != nil && strings.HasPrefix(lnk, "../"); lnk = lnk[3:] {
t = t.ptree
}
if t == nil {
return nil, ErrBadLink{te.Name(), "points outside of repo"}
}
target, err := t.GetTreeEntryByPath(lnk)
if err != nil {
if IsErrNotExist(err) {
return nil, ErrBadLink{te.Name(), "broken link"}
}
return nil, err
}
return target, nil
}
// GetSubJumpablePathName return the full path of subdirectory jumpable ( contains only one directory )
func (te *TreeEntry) GetSubJumpablePathName() string {
if te.IsSubModule() || !te.IsDir() {