Skip to content

Commit

Permalink
makke gorepomod list works with --local
Browse files Browse the repository at this point in the history
  • Loading branch information
antoooks committed Nov 21, 2023
1 parent 49e295e commit b94888f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
26 changes: 13 additions & 13 deletions cmd/gorepomod/internal/git/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ func (gr *Runner) LoadRemoteTags(

// Update latest tags from upstream
gr.comment("updating tags from upstream")
out, err = gr.run(noHarmDone, "fetch", "-t", string(remoteUpstream), "master")
_, err = gr.run(noHarmDone, "fetch", "-t", string(remoteUpstream), "master")
if err != nil {
return nil, err
// Handle if repo is not a fork
gr.run(noHarmDone, "fetch", "-t", "master")
}

gr.comment("loading remote tags")
Expand Down Expand Up @@ -353,19 +354,18 @@ func (gr *Runner) DeleteTagFromRemote(
return gr.runNoOut(undoPainful, "push", string(remote), ":"+refsTags+tag)
}

func (gr *Runner) GetLatestTag(module string) (string, error) {
func (gr *Runner) GetLatestTag(releaseBranch string) (string, error) {
var latestTag string

gr.comment("getting latest tag from upstream")
gr.run(noHarmDone, "fetch", "upstream/master", "--tags")

// Assuming release branch has this format: release/path/to/module
// and each release branch maintains tags
upstreamReleaseBranch := fmt.Sprintf("%s/release/%s", "upstream", module)
gr.comment("getting latest tag from release branch")
latestTag, err := gr.run(noHarmDone, "tag", "--merged", string(upstreamReleaseBranch), "--contains", "--sort=creatordate")
// Assuming release branch has this format: release-path/to/module-vX.Y.Z
// and each release branch maintains tags, get latest tag from `releaseBranch`
gr.comment("getting latest tags from release branch")
latestTag, err := gr.run(noHarmDone, "describe", "--tags", "--abbrev=0")
if err != nil {
fmt.Errorf("error getting latest tag for %s: %q", module, err.Error())
fmt.Errorf("error getting latest tag for %s: %q", releaseBranch, err.Error())
}
if len(latestTag) < 1 {
fmt.Errorf("latest tag not found for %s", releaseBranch)
return "", err
}
return latestTag, nil
}
3 changes: 2 additions & 1 deletion cmd/gorepomod/internal/mod/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func (m *Module) AbsPath() string {

func (m *Module) DependsOn(target misc.LaModule) (bool, semver.SemVer) {
for _, r := range m.mf.Require {
if r.Mod.Path == target.ImportPath() {
targetImportPath := fmt.Sprintf("sigs.k8s.io/kustomize/%s", string(target.ShortName()))
if r.Mod.Path == targetImportPath {
v, err := semver.Parse(r.Mod.Version)
if err != nil {
panic(err)
Expand Down
6 changes: 4 additions & 2 deletions cmd/gorepomod/internal/repo/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func (mgr *Manager) Pin(
doIt bool, target misc.LaModule, newV semver.SemVer) error {
// Always use latest tag while does not removing manual usage capability
if newV == semver.Zero() {
releaseBranch := fmt.Sprintf("release-%s", target.ShortName())
gr := git.NewLoud(mgr.AbsPath(), doIt, false)
latest, err := gr.GetLatestTag(string(target.ShortName()))
latest, err := gr.GetLatestTag(string(releaseBranch))
if err != nil {
fmt.Errorf("cannot get latest tag for %s", target)
}
Expand Down Expand Up @@ -95,7 +96,8 @@ func (mgr *Manager) List() error {
// Auto-update local tags
gr := git.NewQuiet(mgr.AbsPath(), false, false)
for _, module := range mgr.modules {
_, err := gr.GetLatestTag(string(module.ShortName()))
releaseBranch := fmt.Sprintf("release-%s", module.ShortName())
_, err := gr.GetLatestTag(string(releaseBranch))
if err != nil {
fmt.Errorf("failed getting latest tags for %s", module)
}
Expand Down

0 comments on commit b94888f

Please sign in to comment.