feat: infer remotes when none configured in GitView
This commit is contained in:
@@ -925,6 +925,35 @@ export const GitView: React.FC = () => {
|
|||||||
.sort();
|
.sort();
|
||||||
}, [branches]);
|
}, [branches]);
|
||||||
|
|
||||||
|
const effectiveRemotes = React.useMemo<GitRemote[]>(() => {
|
||||||
|
if (remotes.length > 0) {
|
||||||
|
return remotes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inferredNames = new Set<string>();
|
||||||
|
const tracking = status?.tracking?.trim();
|
||||||
|
if (tracking && tracking.includes('/')) {
|
||||||
|
inferredNames.add(tracking.split('/')[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const branchName of remoteBranches) {
|
||||||
|
const slashIndex = branchName.indexOf('/');
|
||||||
|
if (slashIndex > 0) {
|
||||||
|
inferredNames.add(branchName.slice(0, slashIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inferredNames.size === 0 && remoteUrl) {
|
||||||
|
inferredNames.add('origin');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(inferredNames).map((name) => ({
|
||||||
|
name,
|
||||||
|
fetchUrl: remoteUrl ?? '',
|
||||||
|
pushUrl: remoteUrl ?? '',
|
||||||
|
}));
|
||||||
|
}, [remotes, remoteBranches, remoteUrl, status?.tracking]);
|
||||||
|
|
||||||
const baseBranch = React.useMemo(() => {
|
const baseBranch = React.useMemo(() => {
|
||||||
const fromMeta = typeof worktreeMetadata?.createdFromBranch === 'string'
|
const fromMeta = typeof worktreeMetadata?.createdFromBranch === 'string'
|
||||||
? worktreeMetadata.createdFromBranch.trim()
|
? worktreeMetadata.createdFromBranch.trim()
|
||||||
@@ -1520,7 +1549,7 @@ export const GitView: React.FC = () => {
|
|||||||
remoteBranches={remoteBranches}
|
remoteBranches={remoteBranches}
|
||||||
branchInfo={branches?.branches}
|
branchInfo={branches?.branches}
|
||||||
syncAction={syncAction}
|
syncAction={syncAction}
|
||||||
remotes={remotes}
|
remotes={effectiveRemotes}
|
||||||
onFetch={(remote) => handleSyncAction('fetch', remote)}
|
onFetch={(remote) => handleSyncAction('fetch', remote)}
|
||||||
onPull={(remote) => handleSyncAction('pull', remote)}
|
onPull={(remote) => handleSyncAction('pull', remote)}
|
||||||
onPush={(remote) => handleSyncAction('push', remote)}
|
onPush={(remote) => handleSyncAction('push', remote)}
|
||||||
@@ -1573,8 +1602,8 @@ export const GitView: React.FC = () => {
|
|||||||
<GitEmptyState
|
<GitEmptyState
|
||||||
behind={status?.behind ?? 0}
|
behind={status?.behind ?? 0}
|
||||||
onPull={() => {
|
onPull={() => {
|
||||||
if (remotes.length > 0) {
|
if (effectiveRemotes.length > 0) {
|
||||||
handleSyncAction('pull', remotes[0]);
|
handleSyncAction('pull', effectiveRemotes[0]);
|
||||||
} else {
|
} else {
|
||||||
toast.error('No remotes configured');
|
toast.error('No remotes configured');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user