Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#4985 from KnVerey/repospec-git-suffix
Browse files Browse the repository at this point in the history
Proposal: Remove RepoSpec manipulation of .git suffix
  • Loading branch information
k8s-ci-robot authored Jan 20, 2023
2 parents 89d3ca1 + 7e000aa commit 0a1aa7c
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 194 deletions.
42 changes: 1 addition & 41 deletions api/internal/git/repospec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ type RepoSpec struct {
// Branch or tag reference.
Ref string

// e.g. .git or empty in case of _git is present
GitSuffix string

// Submodules indicates whether or not to clone git submodules.
Submodules bool

Expand All @@ -58,10 +55,7 @@ type RepoSpec struct {

// CloneSpec returns a string suitable for "git clone {spec}".
func (x *RepoSpec) CloneSpec() string {
if isAzureHost(x.Host) || isAWSHost(x.Host) {
return x.Host + x.RepoPath
}
return x.Host + x.RepoPath + x.GitSuffix
return x.Host + x.RepoPath
}

func (x *RepoSpec) CloneDir() filesys.ConfirmedDir {
Expand Down Expand Up @@ -124,30 +118,9 @@ func NewRepoSpecFromURL(n string) (*RepoSpec, error) {
return nil, err
}

// If the repo name ends in .git, isolate it. It will be added back by the clone spec function.
if idx := strings.Index(repoSpec.RepoPath, gitSuffix); idx >= 0 {
repoSpec.GitSuffix = gitSuffix
repoSpec.RepoPath = repoSpec.RepoPath[:idx]
}
// Force the .git suffix URLs for services whose clone URL is the repo URL + .git.
// This allows us to support the repo URL as an input instead of the actual clone URL.
if legacyAddGitSuffix(repoSpec.Host, repoSpec.RepoPath) {
repoSpec.GitSuffix = gitSuffix
}

return repoSpec, nil
}

// legacyAddGitSuffix returns true if the .git suffix has historically been added to the repoSpec
// (but not necessarily the cloneSpec) for the given host and repoPath.
// TODO(@knverey): Remove repoSpec.gitSuffix entirely.
// The .git suffix is a popular convention, but not universally used. Kustomize seems to force it
// for non-local because of Github, which now handles suffix-less URLs just fine, as do Gitlab and Bitbucket.
func legacyAddGitSuffix(host, repoPath string) bool {
return !strings.Contains(repoPath, gitRootDelimiter) &&
!strings.HasPrefix(host, fileScheme)
}

const allSegments = -999999
const orgRepoSegments = 2

Expand Down Expand Up @@ -410,16 +383,3 @@ func normalizeGithubHostParts(scheme, username string) (string, string, string)
}
return httpsScheme, "", "github.com/"
}

// The format of Azure repo URL is documented
// https://docs.microsoft.com/en-us/azure/devops/repos/git/clone?view=vsts&tabs=visual-studio#clone_url
func isAzureHost(host string) bool {
return strings.Contains(host, "dev.azure.com") ||
strings.Contains(host, "visualstudio.com")
}

// The format of AWS repo URL is documented
// https://docs.aws.amazon.com/codecommit/latest/userguide/regions.html
func isAWSHost(host string) bool {
return strings.Contains(host, "amazonaws.com")
}
Loading

0 comments on commit 0a1aa7c

Please sign in to comment.