Skip to content

Commit

Permalink
refactor code and fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
antoooks committed Dec 3, 2023
1 parent 0833270 commit 1985f47
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
10 changes: 7 additions & 3 deletions cmd/gorepomod/internal/git/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ func (gr *Runner) LoadRemoteTags(

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

Expand Down Expand Up @@ -381,3 +381,7 @@ func (gr *Runner) GetLatestTag(releaseBranch string) (string, error) {

return latestTag, nil
}

func (gr *Runner) GetMainBranch() string {
return string(mainBranch)
}
6 changes: 4 additions & 2 deletions cmd/gorepomod/internal/repo/dotgitdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ func getLocalPrefix(dgAbsPath string) string {
fmt.Errorf("failed extracting git information: %q", err.Error())
}

var originUrlString string = string(out)
var localPrefix string = utils.ParseGitRepositoryPath(originUrlString)
localPrefix := utils.ParseGitRepositoryPath(string(out))
if len(localPrefix) == 0 {
fmt.Errorf("parsed git repository path is empty: %q", err.Error())
}
return localPrefix
}
8 changes: 4 additions & 4 deletions cmd/gorepomod/internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ func ParseGitRepositoryPath(urlString string) string {

var repoPath string

// for ssh protocol git@github.com:path/repo.git
// TODO(antoooks): Confirm if we should handle other formats not commonly supported by Github
switch protocol {
// ssh protocol, e.g. git@github.com:path/repo.git
case "git":
repoPath = strings.Join(d[2:len(d)-1], "/") + "/" + d[3][:len(d[3])-4]
// https protocol https://github.com/path/repo.git
// https protocol, e.g. https://github.com/path/repo.git
case "https":
repoPath = strings.Join(d[2:], "/")
repoPath = repoPath[:len(repoPath)-4]
// unsupported format
// TODO: confirm if we should handle other formats not commonly supported by Github
// unsupported format
default:
_ = fmt.Errorf("protocol format is not supported: %s", protocol)
return ""
Expand Down
2 changes: 1 addition & 1 deletion cmd/gorepomod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func actualMain() error {
v := args.Version()
// Update branch history
gr := git.NewQuiet(mgr.AbsPath(), args.DoIt(), false)
gr.FetchRemote("master")
gr.FetchRemote(misc.TrackedRepo(gr.GetMainBranch()))

if v.IsZero() {
// Always use latest tag while does not removing manual usage capability
Expand Down

0 comments on commit 1985f47

Please sign in to comment.