Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #631 where slight differences seen in Kptfile upstream format… #165

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/kpt/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func UpdateUpstream(kptfileContents string, name string, upstream kptfilev1.Upst
return "", fmt.Errorf("cannot parse Kptfile: %w", err)
}

// Normalize the repository URL and directory path
normalizeGitFields(&upstream)
normalizeGitLockFields(&lock) // Use separate function for lock

// populate the cloneFrom values so we know where the package came from
kptfile.UpstreamLock = &lock
kptfile.Upstream = &upstream
Expand All @@ -46,6 +50,31 @@ func UpdateUpstream(kptfileContents string, name string, upstream kptfilev1.Upst
return string(b), nil
}

// normalizeGitFields ensures consistent formatting of git repository URLs and directory paths
func normalizeGitFields(u *kptfilev1.Upstream) {
if u.Git != nil {
// Ensure .git suffix is present
if !strings.HasSuffix(u.Git.Repo, ".git") {
u.Git.Repo = u.Git.Repo + ".git"
}

// Ensure directory doesn't start with a slash
u.Git.Directory = strings.TrimPrefix(u.Git.Directory, "/")
}
}

// normalizeGitLockFields ensures consistent formatting for UpstreamLock git fields
func normalizeGitLockFields(l *kptfilev1.UpstreamLock) {
if l.Git != nil {
// Ensure .git suffix is present
if !strings.HasSuffix(l.Git.Repo, ".git") {
l.Git.Repo = l.Git.Repo + ".git"
}

// Ensure directory doesn't start with a slash
l.Git.Directory = strings.TrimPrefix(l.Git.Directory, "/")
}
}
func UpdateName(kptfileContents string, name string) (string, error) {
kptfile, err := internalpkg.DecodeKptfile(strings.NewReader(kptfileContents))
if err != nil {
Expand Down
Loading