Skip to content

Duplicate repo name#6276

Open
DharunMR wants to merge 2 commits intomindersec:mainfrom
DharunMR:duplicate-repo-name
Open

Duplicate repo name#6276
DharunMR wants to merge 2 commits intomindersec:mainfrom
DharunMR:duplicate-repo-name

Conversation

@DharunMR
Copy link
Copy Markdown
Contributor

@DharunMR DharunMR commented Apr 4, 2026

Summary

This PR fixes a state management bug in the minder repo register command where selecting a repository while a search filter is active causes UI duplication and incorrect state updates.

The issue stemmed from using m.list.Index() which returns the index of the item relative to the currently visible filtered list. When a filter is active this index does not match the item position in the underlying data slice. Passing this relative index to m.list.SetItem() caused the wrong record in the base data to be overwritten or duplicated.

Fixes #5051

After Changes

swappy-20260404_184023 No duplicate repo after selecting

DharunMR added 2 commits April 4, 2026 18:33
Signed-off-by: DharunMR <maddharun56@gmail.com>
Signed-off-by: DharunMR <maddharun56@gmail.com>
@DharunMR DharunMR requested a review from a team as a code owner April 4, 2026 13:11
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 58.288% (-0.01%) from 58.298%
when pulling b559496 on DharunMR:duplicate-repo-name
into 63a6a8e on mindersec:main.

@krrish175-byte
Copy link
Copy Markdown
Contributor

Thanks for the fix, this addresses the root cause (using a page-relative index with SetItem caused the wrong item to be toggled). Before it is reviewed and merged by @evankanderson, please make 2 small improvements and update the PR description/tests:

  • Match on a stable unique identifier instead of title (titles can collide).
  • Add a safe fallback in case the selected item isn't found in the underlying Items slice.
  • Expand the PR description to briefly describe the bug, the change, and how you tested it. If possible add a unit/integration test that exercises toggling across pages (manual steps are fine if tests are difficult).

Suggested message to include in your PR and a minimal code example to apply in internal/util/cli/multi_select.go:

// Add a stable id field to the item if not already present:
type item struct {
    id      string // e.g. repo full name or repo ID
    title   string
    checked bool
}

// In the space-key handler, find by id and handle not-found:
var absoluteIdx int
found := false
for i, listItem := range m.list.Items() {
    if listItem.(item).id == oldItem.id {
        absoluteIdx = i
        found = true
        break
    }
}
if !found {
    // safe fallback: log or ignore the toggle to avoid out-of-range errors
    return m, nil
}

cmd := m.list.SetItem(absoluteIdx, item{
    id:      oldItem.id,
    title:   oldItem.title,
    checked: !oldItem.checked,
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Registering a repo in the CLI after search duplicates repo name

3 participants