Skip to content

vcs: don't panic on a git remote without a url - #2610

Open
k4lleanka wants to merge 1 commit into
chainguard-dev:mainfrom
k4lleanka:fix-vcs-remote-without-url
Open

k4lleanka wants to merge 1 commit into
chainguard-dev:mainfrom
k4lleanka:fix-vcs-remote-without-url

Conversation

@k4lleanka

Copy link
Copy Markdown

git allows a remote section without a url, for example when only remote.origin.fetch is set. getRemoteURL indexed URLs[0] unconditionally, so apko build (with --vcs, the default) panicked with index out of range [0] with length 0 when run in such a repository.

It now returns an error. ProbeVCSUrl already logs that at debug level and builds without a VCS URL.

Tested:

  • New nourl case in TestGetRemoteURL: panics on main, passes with the fix.
  • apko build --vcs in a repo whose origin has only a fetch refspec: main panics in getRemoteURL; with the fix it logs failed to probe VCS URL: fetching remote URL: git remote "origin" has no url and the build completes.
  • go test -race ./... on Linux and golangci-lint v2.15.0: no failures.

AI disclosure: I used Claude Code to help find this and write the fix and test. I reviewed and ran them myself.

git allows a remote section without a url (e.g. only a fetch refspec).
getRemoteURL indexed URLs[0] unconditionally, so apko build --vcs
(the default) panicked in such a repository. Return an error instead;
ProbeVCSUrl already logs it and builds without a VCS URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: k4lleanka <257361691+k4lleanka@users.noreply.github.com>
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.

1 participant