diff --git a/app/src/lib/components/ActiveBranchStatus.svelte b/app/src/lib/components/ActiveBranchStatus.svelte index adf2efa99..ae04f5ab7 100644 --- a/app/src/lib/components/ActiveBranchStatus.svelte +++ b/app/src/lib/components/ActiveBranchStatus.svelte @@ -75,6 +75,8 @@ e.stopPropagation(); }} > - {isLaneCollapsed ? 'View branch' : `${$baseBranch.actualPushRemoteName()}/${$branch.upstreamName}`} + {isLaneCollapsed + ? 'View branch' + : `${$baseBranch.actualPushRemoteName()}/${$branch.upstreamName}`} {/if} diff --git a/app/src/lib/components/BaseBranchSwitch.svelte b/app/src/lib/components/BaseBranchSwitch.svelte index cac7eb9ab..191be3bea 100644 --- a/app/src/lib/components/BaseBranchSwitch.svelte +++ b/app/src/lib/components/BaseBranchSwitch.svelte @@ -19,143 +19,123 @@ let project = getContext(Project); - let selectedBranch = {name: $baseBranch.branchName}; - let selectedRemote = {name: $baseBranch.actualPushRemoteName()}; + let selectedBranch = { name: $baseBranch.branchName }; + let selectedRemote = { name: $baseBranch.actualPushRemoteName() }; let targetChangeDisabled = true; if ($activeBranches) { targetChangeDisabled = $activeBranches.length > 0; } let isSwitching = false; + // Fetch the remote branches reactively + let remoteBranchesPromise: Promise< + { + name: string; + }[] + >; + + $: { + if (project) { + remoteBranchesPromise = getRemoteBranches(project.id); + } + } + function uniqueRemotes(remoteBranches: { name: string }[]) { - return Array.from(new Set(remoteBranches.map((b) => b.name.split('/')[0]))).map((r) => ({ name: r })); + return Array.from(new Set(remoteBranches.map((b) => b.name.split('/')[0]))).map((r) => ({ + name: r + })); } async function onSetBaseBranchClick() { if (!selectedBranch) return; - // while target is setting, display loading - isSwitching = true; + isSwitching = true; // Indicate switching in progress - if(selectedRemote){ - await branchController - .setTarget(selectedBranch.name, selectedRemote.name) - .finally(() => { - isSwitching = false; - }); + if (selectedRemote) { + await branchController.setTarget(selectedBranch.name, selectedRemote.name).finally(() => { + isSwitching = false; + }); } else { - await branchController - .setTarget(selectedBranch.name) - .finally(() => { - isSwitching = false; - }); + await branchController.setTarget(selectedBranch.name).finally(() => { + isSwitching = false; + }); } } -
- - Current Target Branch - - Your target branch is what you consider "production". This is where you - want to integrate any branches that you create. Normally something like - 'origin/master' or 'upstream/main'. - +{#await remoteBranchesPromise} + + Loading remote branches... + +{:then remoteBranches} + {#if remoteBranches.length > 0} +
+ + Remote configuration + + Lets you choose where to push code and set the target branch for contributions. The target + branch is usually the "production" branch like 'origin/master' or 'upstream/main.' This + section helps ensure your code goes to the correct remote and branch for integration. + -
- {#if isSwitching} - - - Switching target branch... - - - {:else} - {#await getRemoteBranches(project.id)} - loading remote branches... - {:then remoteBranches} - {#if remoteBranches.length == 0} - - - You don't have any remote branches. - - - {:else} -
- - -
+ - {#if uniqueRemotes(remoteBranches).length > 1} - Create branches on remote: - - {/if} + {#if uniqueRemotes(remoteBranches).length > 1} + + {/if} - {/if} - {:catch} - - - We got an error trying to list your remote branches + {#if $activeBranches && targetChangeDisabled} + + + You have {$activeBranches.length === 1 + ? '1 active branch' + : `${$activeBranches.length} active branches`} in your workspace. Please clear the workspace + before switching the base branch. - {/await} - {/if} - - {#if $activeBranches && targetChangeDisabled} - - - You have {$activeBranches.length === 1 - ? '1 active branch' - : `${$activeBranches.length} active branches`} in your workspace. Please clear the workspace - before switching the base branch. - - - {/if} -
-
-
- - + {:else} + + {/if} +
+
+ {/if} +{:catch} + + We got an error trying to list your remote branches + +{/await} diff --git a/app/src/lib/components/Board.svelte b/app/src/lib/components/Board.svelte index ec6b670ab..da7ac680f 100644 --- a/app/src/lib/components/Board.svelte +++ b/app/src/lib/components/Board.svelte @@ -26,7 +26,6 @@ let dragHandle: any; let clone: any; - let isSwitching = false; {#if $activeBranchesError} diff --git a/app/src/lib/components/ProjectSetupTarget.svelte b/app/src/lib/components/ProjectSetupTarget.svelte index 2aedfea04..14fb8e877 100644 --- a/app/src/lib/components/ProjectSetupTarget.svelte +++ b/app/src/lib/components/ProjectSetupTarget.svelte @@ -36,35 +36,38 @@ let loading = false; let selectedBranch = getBestBranch(remoteBranches); - function getBestBranch(branches: { name: string; }[]): { name: string } { - // Function to calculate the rank of a branch - // eslint-disable-next-line func-style - const calculateRank = (branch: string): number => { - if (branch === 'upstream/main' || branch === 'upstream/master') { - return 100; // Highest preference - } - if (branch === 'origin/main' || branch === 'origin/master') { - return 90; - } - if (branch.startsWith('origin')) { - return 80; - } - if (branch.endsWith('master') || branch.endsWith('main')) { - return 70; - } - return 10; // Least preference - }; + function getBestBranch(branches: { name: string }[]): { name: string } { + // Function to calculate the rank of a branch + // eslint-disable-next-line func-style + const calculateRank = (branch: string): number => { + if (branch === 'upstream/main' || branch === 'upstream/master') { + return 100; // Highest preference + } + if (branch === 'origin/main' || branch === 'origin/master') { + return 90; + } + if (branch.startsWith('origin')) { + return 80; + } + if (branch.endsWith('master') || branch.endsWith('main')) { + return 70; + } + return 10; // Least preference + }; - // Sort the branches based on their rank - branches.sort((a, b) => calculateRank(b.name) - calculateRank(a.name)); + // Sort the branches based on their rank + branches.sort((a, b) => calculateRank(b.name) - calculateRank(a.name)); - // Return the branch with the highest rank - return branches[0]; + // Return the branch with the highest rank + return branches[0]; } // split all the branches by the first '/' and gather the unique remote names // then turn remotes into an array of objects with a 'name' and 'value' key - let remotes = Array.from(new Set(remoteBranches.map((b) => b.name.split('/')[0]))).map((r) => ({ name: r, value: r })); + let remotes = Array.from(new Set(remoteBranches.map((b) => b.name.split('/')[0]))).map((r) => ({ + name: r, + value: r + })); let selectedRemote = remotes[0]; // if there's an 'origin', select it by default @@ -95,8 +98,8 @@ {#if remotes.length > 1}

- You have branches from multiple remotes. If you want to specify a push target for - creating branches that is different from your production branch, change it here. + You have branches from multiple remotes. If you want to specify a push target for creating + branches that is different from your production branch, change it here.