mirror of
https://gitea.com/gitea/tea.git
synced 2024-12-04 14:46:40 -05:00
2135af0304
Fix login detection by Repo param Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/151 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
40 lines
918 B
Go
40 lines
918 B
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
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) {
|
|
repo, err := git.PlainOpenWithOptions("./", &git.PlainOpenOptions{
|
|
DetectDotGit: true,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &TeaRepo{repo}, nil
|
|
}
|
|
|
|
// RepoFromPath tries to open the git repository by path
|
|
func RepoFromPath(path string) (*TeaRepo, error) {
|
|
repo, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{
|
|
DetectDotGit: true,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &TeaRepo{repo}, nil
|
|
}
|