Use git command instead of go git (#1005)

Remove go git library because it doesn't support sha256 repository but have an interface so that we could have other backend for the future.

Reviewed-on: https://gitea.com/gitea/tea/pulls/1005
Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com>
This commit is contained in:
Lunny Xiao
2026-05-23 20:24:47 +00:00
parent 8e0666ab85
commit a664449282
19 changed files with 1113 additions and 380 deletions
+11 -18
View File
@@ -6,14 +6,11 @@ package git
import (
"fmt"
"net/url"
"github.com/go-git/go-git/v5"
git_config "github.com/go-git/go-git/v5/config"
)
// GetRemote tries to match a Remote of the repo via the given URL.
// Matching is based on the normalized URL, accepting different protocols.
func (r TeaRepo) GetRemote(remoteURL string) (*git.Remote, error) {
func (r TeaRepo) GetRemote(remoteURL string) (*Remote, error) {
repoURL, err := ParseURL(remoteURL)
if err != nil {
return nil, err
@@ -23,14 +20,14 @@ func (r TeaRepo) GetRemote(remoteURL string) (*git.Remote, error) {
if err != nil {
return nil, err
}
for _, r := range remotes {
for _, u := range r.Config().URLs {
remoteURL, err := ParseURL(u)
for _, remote := range remotes {
for _, u := range remote.Config().URLs {
parsedRemoteURL, err := ParseURL(u)
if err != nil {
return nil, err
}
if remoteURL.Host == repoURL.Host && remoteURL.Path == repoURL.Path {
return r, nil
if parsedRemoteURL.Host == repoURL.Host && parsedRemoteURL.Path == repoURL.Path {
return remote, nil
}
}
}
@@ -41,27 +38,23 @@ func (r TeaRepo) GetRemote(remoteURL string) (*git.Remote, error) {
// GetOrCreateRemote tries to match a Remote of the repo via the given URL.
// If no match is found, a new Remote with `newRemoteName` is created.
// Matching is based on the normalized URL, accepting different protocols.
func (r TeaRepo) GetOrCreateRemote(remoteURL, newRemoteName string) (*git.Remote, error) {
func (r TeaRepo) GetOrCreateRemote(remoteURL, newRemoteName string) (*Remote, error) {
localRemote, err := r.GetRemote(remoteURL)
if err != nil {
return nil, err
}
// if no match found, create a new remote
if localRemote == nil {
localRemote, err = r.CreateRemote(&git_config.RemoteConfig{
Name: newRemoteName,
URLs: []string{remoteURL},
})
if err != nil {
if err := r.AddRemote(newRemoteName, remoteURL); err != nil {
return nil, err
}
return r.Remote(newRemoteName)
}
return localRemote, nil
}
// TeaRemoteURL returns the first url entry for the given remote name
// TeaRemoteURL returns the first url entry for the given remote name.
func (r TeaRepo) TeaRemoteURL(name string) (auth *url.URL, err error) {
remote, err := r.Remote(name)
if err != nil {
@@ -71,5 +64,5 @@ func (r TeaRepo) TeaRemoteURL(name string) (auth *url.URL, err error) {
if len(urls) == 0 {
return nil, fmt.Errorf("remote %s has no URL configured", name)
}
return ParseURL(remote.Config().URLs[0])
return ParseURL(urls[0])
}