summaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-02-21 23:04:20 +0000
committerGitHub <noreply@github.com>2020-02-21 17:04:20 -0600
commitc8d1c3812980573eae0a1ecd5e84c8b44457c3e4 (patch)
tree29ea510382c64bd6355588a8ac03255425338f33 /modules/git
parent6b019724f3294fd04b9a7c4d3a3e60107977eb64 (diff)
downloadgitea-c8d1c3812980573eae0a1ecd5e84c8b44457c3e4.tar.gz
gitea-c8d1c3812980573eae0a1ecd5e84c8b44457c3e4.zip
Render READMEs in docs/ .gitea or .github from root (#10361)
* Render READMEs in docs/ .gitea or .github from root
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/error.go6
-rw-r--r--modules/git/tree_entry.go32
2 files changed, 38 insertions, 0 deletions
diff --git a/modules/git/error.go b/modules/git/error.go
index 6e4f26de13..9266c41b06 100644
--- a/modules/git/error.go
+++ b/modules/git/error.go
@@ -50,6 +50,12 @@ func (err ErrBadLink) Error() string {
return fmt.Sprintf("%s: %s", err.Name, err.Message)
}
+// IsErrBadLink if some error is ErrBadLink
+func IsErrBadLink(err error) bool {
+ _, ok := err.(ErrBadLink)
+ return ok
+}
+
// ErrUnsupportedVersion error when required git version not matched
type ErrUnsupportedVersion struct {
Required string
diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go
index 4e18cc8ead..75ff37048e 100644
--- a/modules/git/tree_entry.go
+++ b/modules/git/tree_entry.go
@@ -167,6 +167,38 @@ func (te *TreeEntry) FollowLink() (*TreeEntry, error) {
return target, nil
}
+// FollowLinks returns the entry ultimately pointed to by a symlink
+func (te *TreeEntry) FollowLinks() (*TreeEntry, error) {
+ if !te.IsLink() {
+ return nil, ErrBadLink{te.Name(), "not a symlink"}
+ }
+ entry := te
+ for i := 0; i < 999; i++ {
+ if entry.IsLink() {
+ next, err := entry.FollowLink()
+ if err != nil {
+ return nil, err
+ }
+ if next.ID == entry.ID {
+ return nil, ErrBadLink{
+ entry.Name(),
+ "recursive link",
+ }
+ }
+ entry = next
+ } else {
+ break
+ }
+ }
+ if entry.IsLink() {
+ return nil, ErrBadLink{
+ te.Name(),
+ "too many levels of symbolic links",
+ }
+ }
+ return entry, nil
+}
+
// GetSubJumpablePathName return the full path of subdirectory jumpable ( contains only one directory )
func (te *TreeEntry) GetSubJumpablePathName() string {
if te.IsSubModule() || !te.IsDir() {