1
1
mirror of https://gitea.com/gitea/tea synced 2024-11-22 16:02:01 +01:00
tea/modules/git/repo.go
techknowlogick b868d30434 spdx (#581)
Co-authored-by: techknowlogick <hello@techknowlogick.com>
Co-committed-by: techknowlogick <hello@techknowlogick.com>
2023-09-08 01:40:02 +00:00

35 lines
748 B
Go

// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package git
import (
"github.com/go-git/go-git/v5"
)
// TeaRepo is a go-git Repository, with an extended high level interface.
type TeaRepo struct {
*git.Repository
}
// RepoForWorkdir tries to open the git repository in the local directory
// for reading or modification.
func RepoForWorkdir() (*TeaRepo, error) {
return RepoFromPath("")
}
// RepoFromPath tries to open the git repository by path
func RepoFromPath(path string) (*TeaRepo, error) {
if len(path) == 0 {
path = "./"
}
repo, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{
DetectDotGit: true,
})
if err != nil {
return nil, err
}
return &TeaRepo{repo}, nil
}