github-vet / github-vet/rangeloop-pointer-findings

LavaToaster/cloudsmith-sync: cmd/sync.go; 68 LoC

Open
#10,238 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [LavaToaster/cloudsmith-sync](https://www.github.com/LavaToaster/cloudsmith-sync) at [cmd/sync.go](https://github.com/LavaToaster/cloudsmith-sync/blob/526c1462499e6ac48963971b2c4857af7d500a6e/cmd/sync.go#L50-L117)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to repoCfg was used in a composite literal at line 109

[Click here to see the code in its original context.](https://github.com/LavaToaster/cloudsmith-sync/blob/526c1462499e6ac48963971b2c4857af7d500a6e/cmd/sync.go#L50-L117)

Click here to show the 68 line(s) of Go which triggered the analyzer.

```go
for _, repoCfg := range config.Repositories {
// Repo Config
repoDir, err := git.GitUrlToDirectory(repoCfg.Url)
repoPath := config.GetRepoPath(repoDir)
exitOnError(err)

processLine := "Processing repository: " + repoCfg.Url
outer := strings.Repeat("=", len(processLine))

fmt.Println(outer)
fmt.Println(processLine)
fmt.Println(outer)
fmt.Println()

// Clone Repo
repo, err := git.CloneOrOpenAndUpdate(repoCfg.Url, repoPath)
exitOnError(err)

// Get Remote
remote, err := repo.Remote("origin")
exitOnError(err)

auth, err := git.GetAuth()
exitOnError(err)

refList, err := remote.List(&git2.ListOptions{Auth: auth})
exitOnError(err)

worktree, err := repo.Worktree()
exitOnError(err)

for _, ref := range refList {
isBranch := strings.HasPrefix(ref.Name().String(), "refs/heads/")
isTag := strings.HasPrefix(ref.Name().String(), "refs/tags/")

if !isBranch && !isTag {
continue
}

// Tags
if isTag {
_, err := git.CheckoutTag(repo, worktree, ref)

if err != nil {
fmt.Printf("Skipping tag %v - %v\n", ref, err.Error())
continue
}
}

// Branch
if isBranch {
_, err := git.CheckoutBranch(repo, worktree, ref)

if err != nil {
fmt.Printf("Skipping branch %v - %v\n", ref, err.Error())
continue
}
}

processPackage(client, &repoCfg, repoPath, ref.Name().Short(), isBranch, ref.Hash().String())

worktree.Reset(&git2.ResetOptions{
Mode: git2.HardReset,
})
}

fmt.Println()
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 526c1462499e6ac48963971b2c4857af7d500a6e

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.