fix: workspace forks shouldn't inherit promotion mode repo (#7223)

* fix: workspace forks shouldn't inherit promotion mode repo

* fix: git sync: don't default to main when talking about target branches in git
This commit is contained in:
wendrul
2025-11-25 18:26:05 +01:00
committed by GitHub
parent 914ee6c881
commit 4660303e29
5 changed files with 24 additions and 13 deletions
+7 -2
View File
@@ -2566,9 +2566,14 @@ async fn update_workspace_settings(
WorkspaceGitSyncSettings::default()
};
// We only keep the first git sync repo, since it is considered the main one
// We only keep the first git sync repo that is sync mode (use_individual_branch = false), since it is considered the main one
// Context: see WIN-1559
git_sync_settings.repositories.truncate(1);
git_sync_settings.repositories = git_sync_settings
.repositories
.into_iter()
.filter(|r| !r.use_individual_branch.unwrap_or(false))
.take(1)
.collect();
let serialized_config = serde_json::to_value::<WorkspaceGitSyncSettings>(git_sync_settings)
.map_err(|err| Error::internal_err(err.to_string()))?;
@@ -12,7 +12,7 @@
const gitSyncContext = getGitSyncContext()
const repo = $derived(gitSyncContext.getRepository(idx))
let targetBranch = $state('main')
let targetBranch = $state<string | undefined>(undefined)
// Update target branch when repository changes
$effect(() => {
@@ -664,12 +664,13 @@ export function createGitSyncContext(workspace: string) {
}
// Helper to get target branch from git resource
async function getTargetBranch(repo: GitSyncRepository): Promise<string> {
async function getTargetBranch(repo: GitSyncRepository): Promise<string | undefined> {
if (!repo.git_repo_resource_path) {
return 'main'
return undefined
}
if (repo._targetBranch) {
if (repo._targetBranch === '') return undefined
return repo._targetBranch
}
@@ -681,14 +682,15 @@ export function createGitSyncContext(workspace: string) {
// Extract branch from git resource value
const resourceValue = resource.value as any
const targetBranch = resourceValue?.branch || 'main'
const targetBranch = resourceValue?.branch
// Cache the result
repo._targetBranch = targetBranch
if (targetBranch === '') return undefined
return targetBranch
} catch (error) {
console.warn('Failed to fetch git resource for branch info:', error)
return 'main'
return undefined
}
}
@@ -3,7 +3,7 @@
let { mode, targetBranch, repository } = $props<{
mode?: 'sync' | 'promotion' | null
targetBranch: string
targetBranch: string | undefined
repository?: GitSyncRepository | null
}>()
</script>
@@ -11,12 +11,15 @@
<div class="text-base">
{#if mode === 'promotion'}
<div
><span class="font-bold">Promotion:</span> Creating branches whose promotion target is {targetBranch}</div
><span class="font-bold">Promotion:</span> Creating branches whose promotion target is {targetBranch? `'${targetBranch}'` :
"the repo's default branch"}</div
>
{#if repository?.group_by_folder}
<div class="text-sm text-primary mt-1">Grouped by folder</div>
{/if}
{:else if targetBranch}
<div><span class="font-bold">Sync:</span> Syncing back to branch '{targetBranch}'</div>
{:else}
<div><span class="font-bold">Sync:</span> Syncing back to branch {targetBranch}</div>
<div><span class="font-bold">Sync:</span> Syncing back to the repo's default branch</div>
{/if}
</div>
@@ -50,7 +50,7 @@
const validation = $derived(idx !== null ? gitSyncContext.getValidation(idx) : null)
const gitSyncTestJob = $derived(idx !== null ? gitSyncContext.gitSyncTestJobs?.[idx] : null)
let confirmingDelete = $state(false)
let targetBranch = $state('main') // Default to main, will be updated when resource is available
let targetBranch = $state<string | undefined>(undefined) // Default to main, will be updated when resource is available
// Update target branch when repository changes
$effect(() => {
@@ -108,12 +108,13 @@
)
// Determine display description based on variant and mode
const targetOrDefaultBranch = $derived(targetBranch ? `'${targetBranch}'` : 'repo\'s default' )
const displayDescription = $derived(
variant === 'primary-sync' || variant === 'primary-promotion'
? mode === 'sync'
? `Changes will be committed directly to the ${targetBranch} branch`
? `Changes will be committed directly to the ${targetOrDefaultBranch} branch`
: mode === 'promotion'
? `Changes will be made to new branches whose promotion target is ${targetBranch}`
? `Changes will be made to new branches whose promotion target is the ${targetOrDefaultBranch} branch`
: null
: null
)