mirror of
https://gitea.com/gitea/tea.git
synced 2026-02-22 14:23:30 +01:00
while looks the alibaba has not maintain [`git-repo-go`](https://github.com/alibaba/git-repo-go/) tool, to make agit flow pull requst can be create quickly. add creating agit flow pull request feature in tea tool example: ```SHELL tea pulls create --agit --remote=origin --topic=test-topic --title="hello world" --description="test1 test 2 test 3" ``` Signed-off-by: a1012112796 <1012112796@qq.com> Reviewed-on: https://gitea.com/gitea/tea/pulls/867 Co-authored-by: a1012112796 <1012112796@qq.com> Co-committed-by: a1012112796 <1012112796@qq.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"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,
|
|
EnableDotGitCommonDir: true, // Enable commondir support for worktrees
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &TeaRepo{repo}, nil
|
|
}
|
|
|
|
// RemoteURL returns the URL of the given remote
|
|
func (r TeaRepo) RemoteURL(remoteName string) (*url.URL, error) {
|
|
remote, err := r.Remote(remoteName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return url.Parse(remote.Config().URLs[0])
|
|
}
|