From 4660303e2902409f1117abd6eb92f830f2de30ee Mon Sep 17 00:00:00 2001 From: wendrul <53628737+wendrul@users.noreply.github.com> Date: Tue, 25 Nov 2025 18:26:05 +0100 Subject: [PATCH] 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 --- backend/windmill-api/src/workspaces.rs | 9 +++++++-- .../src/lib/components/git_sync/DetectionFlow.svelte | 2 +- .../lib/components/git_sync/GitSyncContext.svelte.ts | 10 ++++++---- .../lib/components/git_sync/GitSyncModeDisplay.svelte | 9 ++++++--- .../components/git_sync/GitSyncRepositoryCard.svelte | 7 ++++--- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index cea6c2ba5c..cd624e7c9d 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -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::(git_sync_settings) .map_err(|err| Error::internal_err(err.to_string()))?; diff --git a/frontend/src/lib/components/git_sync/DetectionFlow.svelte b/frontend/src/lib/components/git_sync/DetectionFlow.svelte index 817b9942f7..c4b25c8401 100644 --- a/frontend/src/lib/components/git_sync/DetectionFlow.svelte +++ b/frontend/src/lib/components/git_sync/DetectionFlow.svelte @@ -12,7 +12,7 @@ const gitSyncContext = getGitSyncContext() const repo = $derived(gitSyncContext.getRepository(idx)) - let targetBranch = $state('main') + let targetBranch = $state(undefined) // Update target branch when repository changes $effect(() => { diff --git a/frontend/src/lib/components/git_sync/GitSyncContext.svelte.ts b/frontend/src/lib/components/git_sync/GitSyncContext.svelte.ts index 33c2f2fa5c..33b299cba0 100644 --- a/frontend/src/lib/components/git_sync/GitSyncContext.svelte.ts +++ b/frontend/src/lib/components/git_sync/GitSyncContext.svelte.ts @@ -664,12 +664,13 @@ export function createGitSyncContext(workspace: string) { } // Helper to get target branch from git resource - async function getTargetBranch(repo: GitSyncRepository): Promise { + async function getTargetBranch(repo: GitSyncRepository): Promise { 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 } } diff --git a/frontend/src/lib/components/git_sync/GitSyncModeDisplay.svelte b/frontend/src/lib/components/git_sync/GitSyncModeDisplay.svelte index 599eb08f4a..94c77a5974 100644 --- a/frontend/src/lib/components/git_sync/GitSyncModeDisplay.svelte +++ b/frontend/src/lib/components/git_sync/GitSyncModeDisplay.svelte @@ -3,7 +3,7 @@ let { mode, targetBranch, repository } = $props<{ mode?: 'sync' | 'promotion' | null - targetBranch: string + targetBranch: string | undefined repository?: GitSyncRepository | null }>() @@ -11,12 +11,15 @@
{#if mode === 'promotion'}
Promotion: Creating branches whose promotion target is {targetBranch}
Promotion: Creating branches whose promotion target is {targetBranch? `'${targetBranch}'` : + "the repo's default branch"}
{#if repository?.group_by_folder}
Grouped by folder
{/if} + {:else if targetBranch} +
Sync: Syncing back to branch '{targetBranch}'
{:else} -
Sync: Syncing back to branch {targetBranch}
+
Sync: Syncing back to the repo's default branch
{/if} diff --git a/frontend/src/lib/components/git_sync/GitSyncRepositoryCard.svelte b/frontend/src/lib/components/git_sync/GitSyncRepositoryCard.svelte index c5700622d4..6d8bd34919 100644 --- a/frontend/src/lib/components/git_sync/GitSyncRepositoryCard.svelte +++ b/frontend/src/lib/components/git_sync/GitSyncRepositoryCard.svelte @@ -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(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 )