diff --git a/gradle/changelog/hg_default_branch.yaml b/gradle/changelog/hg_default_branch.yaml new file mode 100644 index 0000000000..e62e933c6e --- /dev/null +++ b/gradle/changelog/hg_default_branch.yaml @@ -0,0 +1,3 @@ +- type: fixed + description: Error in frontend without 'default' branch in hg repositories + diff --git a/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx b/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx index 1bd3f30680..c87806d2e6 100644 --- a/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/containers/Sources.tsx @@ -63,8 +63,10 @@ const Sources: FC = ({ repository, branches, selectedBranch, baseUrl }) = // redirect to default branch if no branch selected useEffect(() => { if (branches && branches.length > 0 && !selectedBranch) { - const defaultBranch = branches?.filter(b => b.defaultBranch === true)[0]; - history.replace(`${baseUrl}/sources/${encodeURIComponent(defaultBranch.name)}/`); + const defaultBranch = branches?.filter((b) => b.defaultBranch === true)[0]; + history.replace( + `${baseUrl}/sources/${defaultBranch ? encodeURIComponent(defaultBranch.name) : encodeURIComponent(branches[0].name)}/` + ); } }, [branches, selectedBranch, history, baseUrl]); const { isLoading, error, data: file, isFetchingNextPage, fetchNextPage } = useSources(repository, {