mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-25 12:01:36 +01:00
4cda7e0299
Merge branch 'master' into issue-97/pulls-clean vendor terminal dependency pull/push: provide authentication method automatically select an AuthMethod according to the remote url type. If required, credentials are prompted for login: store username & optional keyfile refactor refactor GetRemote Merge branch 'master' into issue-97/pulls-clean adress code review add --ignore-sha flag When set, the local branch is not matched against the remote sha, but the remote branch name. This makes the command more flexible with diverging branches. add missing error check fix branch-not-found case Merge branch 'master' into issue-97/pulls-clean use directory namespaces for branches & remotes fix TeaCreateBranch() improve method of TeaFindBranch() now only checking .git/refs instead of looking up .git/config which may not list the branch add `tea pulls clean` fixes #97 add copyright to new files make linter happy refactor: use new git functions for old code add `tea pulls checkout` Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/105 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
// Copyright 2019 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 (
|
|
"net/url"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
protocolRe = regexp.MustCompile("^[a-zA-Z_+-]+://")
|
|
)
|
|
|
|
// URLParser represents a git URL parser
|
|
type URLParser struct {
|
|
}
|
|
|
|
// Parse parses the git URL
|
|
func (p *URLParser) Parse(rawURL string) (u *url.URL, err error) {
|
|
if !protocolRe.MatchString(rawURL) &&
|
|
strings.Contains(rawURL, ":") &&
|
|
// not a Windows path
|
|
!strings.Contains(rawURL, "\\") {
|
|
rawURL = "ssh://" + strings.Replace(rawURL, ":", "/", 1)
|
|
}
|
|
|
|
u, err = url.Parse(rawURL)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if u.Scheme == "git+ssh" {
|
|
u.Scheme = "ssh"
|
|
}
|
|
|
|
if strings.HasPrefix(u.Path, "//") {
|
|
u.Path = strings.TrimPrefix(u.Path, "/")
|
|
}
|
|
|
|
// .git suffix is optional and breaks normalization
|
|
if strings.HasSuffix(u.Path, ".git") {
|
|
u.Path = strings.TrimSuffix(u.Path, ".git")
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// ParseURL parses URL string and return URL struct
|
|
func ParseURL(rawURL string) (u *url.URL, err error) {
|
|
p := &URLParser{}
|
|
return p.Parse(rawURL)
|
|
}
|