mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:51:59 +00:00
fix default branch/changelist behavior in repository rev picker
This commit is contained in:
parent
55352a6ca8
commit
2cce0a7ae6
@ -92,11 +92,6 @@
|
||||
|
||||
function defaultHandleSelect(revision: string) {
|
||||
const urlToReplace = location.pathname + location.search + location.hash
|
||||
|
||||
if (isPerforceDepot) {
|
||||
revision = 'changelist/' + revision
|
||||
}
|
||||
|
||||
goto(replaceRevisionInURL(urlToReplace, revision))
|
||||
}
|
||||
|
||||
@ -105,8 +100,6 @@
|
||||
$: revisionLabel = revision ? (revision === commitID ? commitID.slice(0, 7) : revision) : defaultBranch ?? ''
|
||||
$: isOnSpecificRev = revisionLabel !== defaultBranch
|
||||
|
||||
$: isPerforceDepot = getDepotChangelists !== undefined
|
||||
|
||||
const buttonClass = getButtonClassName({ variant: 'secondary', outline: false, size: 'sm' })
|
||||
</script>
|
||||
|
||||
@ -114,13 +107,7 @@
|
||||
<span use:registerTarget data-repo-rev-picker-trigger>
|
||||
<ButtonGroup {display}>
|
||||
<button use:registerTrigger class="{buttonClass} rev-name" on:click={() => toggle()} {...$$restProps}>
|
||||
<!--
|
||||
Perforce does not have a "main" or "master" branch concept like Git.
|
||||
When scoped to a Perforce depot, the revision picker will default to
|
||||
the ID of the most recent changelist. For Git repositories, it will
|
||||
default to the name of the main branch.
|
||||
-->
|
||||
@{isPerforceDepot && latestChangelistID ? `changelist/${latestChangelistID}` : revisionLabel}
|
||||
@{revisionLabel}
|
||||
</button>
|
||||
|
||||
<CopyButton value={revisionLabel}>
|
||||
@ -135,7 +122,7 @@
|
||||
</CopyButton>
|
||||
|
||||
{#if isOnSpecificRev}
|
||||
<Tooltip tooltip="Go to default branch">
|
||||
<Tooltip tooltip={getDepotChangelists ? 'Go to most recent changelist' : 'Go to default branch'}>
|
||||
<button
|
||||
class="{buttonClass} close-button hoverable-button"
|
||||
on:click={() => onSelect(defaultBranch)}
|
||||
@ -226,7 +213,7 @@
|
||||
toOption={changelist => ({ value: changelist.id, label: changelist.perforceChangelist?.cid })}
|
||||
onSelect={changelist => {
|
||||
toggle(false)
|
||||
onSelect(changelist.perforceChangelist?.cid ?? '')
|
||||
onSelect(`changelist/${changelist.perforceChangelist?.cid}` ?? '')
|
||||
}}
|
||||
let:value
|
||||
>
|
||||
|
||||
@ -81,20 +81,22 @@
|
||||
<ul class="changelists">
|
||||
{#each changelists as changelistCommit (changelistCommit.perforceChangelist?.canonicalURL)}
|
||||
{@const changelist = changelistCommit.perforceChangelist}
|
||||
<li>
|
||||
<div class="changelist">
|
||||
<Changelist {changelist} />
|
||||
</div>
|
||||
<ul class="actions">
|
||||
<li>
|
||||
Changelist ID:
|
||||
<Badge variant="link">
|
||||
<a href={changelist?.canonicalURL} title="View changelist">{changelist?.cid}</a>
|
||||
</Badge>
|
||||
</li>
|
||||
<li> <a href="/{data.repoName}@changelist/{changelist?.cid}">Browse files</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{#if changelist !== null}
|
||||
<li>
|
||||
<div class="changelist">
|
||||
<Changelist {changelist} />
|
||||
</div>
|
||||
<ul class="actions">
|
||||
<li>
|
||||
Changelist ID:
|
||||
<Badge variant="link">
|
||||
<a href={changelist?.canonicalURL} title="View changelist">{changelist?.cid}</a>
|
||||
</Badge>
|
||||
</li>
|
||||
<li> <a href="/{data.repoName}@changelist/{changelist?.cid}">Browse files</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{/if}
|
||||
{:else}
|
||||
<li>
|
||||
<Alert variant="info">No changelists found</Alert>
|
||||
|
||||
@ -29,6 +29,7 @@ export const load: LayoutLoad = async ({ params, url, depends }) => {
|
||||
|
||||
// An empty revision means we are at the default branch
|
||||
const { repoName, revision = '' } = parseRepoRevision(params.repo)
|
||||
|
||||
const resolvedRepository = await resolveRepoRevision({
|
||||
client,
|
||||
repoName,
|
||||
@ -43,6 +44,9 @@ export const load: LayoutLoad = async ({ params, url, depends }) => {
|
||||
})
|
||||
.then(res => res.data?.repository?.commit?.perforceChangelist?.cid)
|
||||
|
||||
const hi = resolvedRepository.defaultBranch?.target.commit?.perforceChangelist?.cid
|
||||
? `changelist/${resolvedRepository.defaultBranch?.target.commit?.perforceChangelist?.cid}`
|
||||
: resolvedRepository.defaultBranch?.abbrevName || 'HEAD'
|
||||
return {
|
||||
repoURL: '/' + params.repo,
|
||||
repoURLWithoutRevision: '/' + repoName,
|
||||
@ -59,7 +63,9 @@ export const load: LayoutLoad = async ({ params, url, depends }) => {
|
||||
* - a symbolic revision (e.g. a branch or tag name)
|
||||
*/
|
||||
displayRevision: displayRevision(revision, resolvedRepository),
|
||||
defaultBranch: resolvedRepository.defaultBranch?.abbrevName || 'HEAD',
|
||||
defaultBranch: resolvedRepository.defaultBranch?.target.commit?.perforceChangelist?.cid
|
||||
? `changelist/${resolvedRepository.defaultBranch?.target.commit?.perforceChangelist?.cid}`
|
||||
: resolvedRepository.defaultBranch?.abbrevName || 'HEAD',
|
||||
resolvedRepository: resolvedRepository,
|
||||
isPerforceDepot: resolvedRepository.externalRepository.serviceType === 'perforce',
|
||||
latestChangelistID,
|
||||
|
||||
@ -41,6 +41,8 @@ fragment ResolvedRepository on Repository {
|
||||
}
|
||||
}
|
||||
changelist(cid: $revision) {
|
||||
cid
|
||||
canonicalURL
|
||||
commit {
|
||||
oid
|
||||
}
|
||||
@ -52,6 +54,14 @@ fragment ResolvedRepository on Repository {
|
||||
}
|
||||
defaultBranch {
|
||||
abbrevName
|
||||
target {
|
||||
commit {
|
||||
perforceChangelist {
|
||||
cid
|
||||
canonicalURL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
externalURLs {
|
||||
url
|
||||
|
||||
Loading…
Reference in New Issue
Block a user