Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions Backend/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ pub struct General {
/// When enabled, commit hooks may not rewrite the user-entered commit summary.
#[serde(default = "default_true")]
pub restrict_commit_summary: bool,
/// When enabled, new branch creation defaults to checking out the branch.
#[serde(default = "default_true")]
pub checkout_new_branch: bool,
}
impl Default for General {
/// Returns default general settings values.
Expand All @@ -117,7 +114,6 @@ impl Default for General {
telemetry: false,
crash_reports: true,
restrict_commit_summary: true,
checkout_new_branch: true,
}
}
}
Expand Down Expand Up @@ -847,17 +843,3 @@ impl AppConfig {
self.logging.retain_archives = self.logging.retain_archives.clamp(1, 100);
}
}

#[cfg(test)]
mod tests {
use super::{AppConfig, General};

#[test]
/// Verifies new branch creation checks out by default for existing configs.
fn checkout_new_branch_defaults_true() {
assert!(General::default().checkout_new_branch);

let cfg: AppConfig = toml::from_str("schema_version = 1\n[general]\n").expect("config");
assert!(cfg.general.checkout_new_branch);
}
}
8 changes: 0 additions & 8 deletions Frontend/src/modals/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ <h3 id="settings-title" style="margin:0">Settings</h3>
</label>
</div>

<div class="group">
<label class="checkbox">
<input type="checkbox" id="set-checkout-new-branch" />
Checkout new branches after create
<span class="help-tip" title="When enabled, the Create Branch dialog checks out the new branch by default. Enabled by default.">?</span>
</label>
</div>

</form>

<!-- Diff -->
Expand Down
44 changes: 36 additions & 8 deletions Frontend/src/scripts/features/newBranch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

vi.mock('../lib/notify', () => ({ notify: vi.fn() }));
vi.mock('../ui/modals', () => ({ closeModal: vi.fn() }));
vi.mock('../plugins', () => ({ runHook: vi.fn(async () => ({ cancelled: false })) }));
vi.mock('../state/state', () => ({ state: { branch: 'main', branches: [] } }));

/** Provides a minimal `matchMedia` test shim used by state imports. */
function createMatchMediaMock(query: string) {
return { matches: false, media: query, addListener: () => {}, removeListener: () => {} };
Expand All @@ -21,13 +26,10 @@ function mountNewBranchModal() {
}

/** Installs a mocked Tauri runtime before modules capture it at import time. */
function installTauriMock(checkoutNewBranch: boolean) {
function installTauriMock() {
(window as any).__TAURI__ = {
core: {
invoke: vi.fn(async (cmd: string) => {
if (cmd === 'get_global_settings') {
return { general: { checkout_new_branch: checkoutNewBranch } };
}
invoke: vi.fn(async () => {
return null;
}),
},
Expand All @@ -53,14 +55,40 @@ afterEach(() => {
});

describe('wireNewBranch', () => {
it('uses the persisted checkout-new-branch setting as the checkbox default', async () => {
installTauriMock(false);
it('defaults the checkout checkbox to enabled', async () => {
installTauriMock();

const { wireNewBranch } = await import('./newBranch');
wireNewBranch();
await flushPromises();

const checkout = document.getElementById('new-branch-checkout') as HTMLInputElement;
expect(checkout.checked).toBe(false);
expect(checkout.checked).toBe(true);
});

it('passes the checkout choice to branch creation', async () => {
const invoke = vi.fn(async () => null);
(window as any).__TAURI__ = {
core: { invoke },
event: { listen: vi.fn() },
};

const { wireNewBranch } = await import('./newBranch');
wireNewBranch();
await flushPromises();

const name = document.getElementById('new-branch-name') as HTMLInputElement;
const checkout = document.getElementById('new-branch-checkout') as HTMLInputElement;
const create = document.getElementById('new-branch-create') as HTMLButtonElement;

name.value = 'feature/test';
name.dispatchEvent(new Event('input'));
await flushPromises();
checkout.checked = false;
create.disabled = false;
create.click();
await flushPromises();

expect(invoke).toHaveBeenCalledWith('vcs_create_branch', { name: 'feature/test', from: 'main', checkout: false });
});
});
12 changes: 3 additions & 9 deletions Frontend/src/scripts/features/newBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { notify } from "../lib/notify";
import { state } from "../state/state";
import { closeModal } from "../ui/modals";
import { runHook } from "../plugins";
import type { GlobalSettings } from "../types";

function fixBranchName(raw: string): string {
// Keep the user's input intact; only normalize for creation.
Expand Down Expand Up @@ -55,16 +54,11 @@ function populateBaseSelect(modal: HTMLElement) {
}
}

/** Applies the persisted default checkout choice to the create-branch form. */
async function loadCheckoutDefault(modal: HTMLElement) {
/** Applies the default checkout choice to the create-branch form. */
function loadCheckoutDefault(modal: HTMLElement) {
const checkoutEl = modal.querySelector<HTMLInputElement>('#new-branch-checkout');
if (!checkoutEl) return;
try {
const cfg = await TAURI.invoke<GlobalSettings>('get_global_settings');
checkoutEl.checked = cfg.general?.checkout_new_branch !== false;
} catch {
checkoutEl.checked = true;
}
checkoutEl.checked = true;
}

export function wireNewBranch() {
Expand Down
2 changes: 0 additions & 2 deletions Frontend/src/scripts/features/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@ export function wireSettings() {
telemetry: false,
crash_reports: true,
restrict_commit_summary: true,
checkout_new_branch: true,
};
cur.diff = { tab_width: 4, ignore_whitespace: 'none', max_file_size_mb: 10, intraline: true, show_binary_placeholders: true, external_diff: {enabled:false,path:'',args:''}, external_merge: {enabled:false,path:'',args:''}, binary_exts: ['png','jpg','dds','uasset'] };
cur.lfs = { enabled: true, concurrency: 4, require_lock_before_edit: false, background_fetch_on_checkout: true };
Expand Down Expand Up @@ -912,7 +911,6 @@ export async function loadSettingsIntoForm(root?: HTMLElement) {
const elIn = get<HTMLInputElement>('#set-intraline'); if (elIn) elIn.checked = !!cfg.diff?.intraline;
const elBp = get<HTMLInputElement>('#set-binary-placeholders'); if (elBp) elBp.checked = !!cfg.diff?.show_binary_placeholders;
const elRestrict = get<HTMLInputElement>('#set-restrict-commit-summary'); if (elRestrict) elRestrict.checked = cfg.general?.restrict_commit_summary !== false;
const elCheckoutNewBranch = get<HTMLInputElement>('#set-checkout-new-branch'); if (elCheckoutNewBranch) elCheckoutNewBranch.checked = cfg.general?.checkout_new_branch !== false;
const elMm = get<HTMLSelectElement>('#set-merge-mode');
const elMp = get<HTMLInputElement>('#set-merge-path');
const elMa = get<HTMLInputElement>('#set-merge-args');
Expand Down
5 changes: 0 additions & 5 deletions Frontend/src/scripts/features/settingsGeneral.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ describe('collectGeneralSettings', () => {
<input id="set-checks-on-launch" type="checkbox" checked />
<input id="set-crash-reports" type="checkbox" checked />
<input id="set-restrict-commit-summary" type="checkbox" checked />
<input id="set-checkout-new-branch" type="checkbox" checked />
</div>
`;

const root = document.body.firstElementChild as HTMLElement;
const general = collectGeneralSettings(root, {}, () => 'dark');
expect(general?.crash_reports).toBe(true);
expect(general?.restrict_commit_summary).toBe(true);
expect(general?.checkout_new_branch).toBe(true);
expect(general?.theme).toBe('system');
});
});
Expand All @@ -41,7 +39,6 @@ describe('loadGeneralSettingsIntoForm', () => {
<input id="set-checks-on-launch" type="checkbox" />
<input id="set-crash-reports" type="checkbox" />
<input id="set-restrict-commit-summary" type="checkbox" />
<input id="set-checkout-new-branch" type="checkbox" />
</div>
`;

Expand All @@ -57,7 +54,6 @@ describe('loadGeneralSettingsIntoForm', () => {
checks_on_launch: true,
crash_reports: true,
restrict_commit_summary: true,
checkout_new_branch: true,
},
},
(value) => String(value ?? ''),
Expand All @@ -68,6 +64,5 @@ describe('loadGeneralSettingsIntoForm', () => {
expect(refreshDefaultBackendOptions).toHaveBeenCalledWith(root, expect.any(Object));
expect((root.querySelector('#set-crash-reports') as HTMLInputElement).checked).toBe(true);
expect((root.querySelector('#set-restrict-commit-summary') as HTMLInputElement).checked).toBe(true);
expect((root.querySelector('#set-checkout-new-branch') as HTMLInputElement).checked).toBe(true);
});
});
3 changes: 0 additions & 3 deletions Frontend/src/scripts/features/settingsGeneral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export function collectGeneralSettings(
checks_on_launch: !!get<HTMLInputElement>('#set-checks-on-launch')?.checked,
crash_reports: !!get<HTMLInputElement>('#set-crash-reports')?.checked,
restrict_commit_summary: !!get<HTMLInputElement>('#set-restrict-commit-summary')?.checked,
checkout_new_branch: !!get<HTMLInputElement>('#set-checkout-new-branch')?.checked,
};
}

Expand Down Expand Up @@ -77,6 +76,4 @@ export async function loadGeneralSettingsIntoForm(
if (elCrash) elCrash.checked = !!cfg.general?.crash_reports;
const elRestrict = get<HTMLInputElement>('#set-restrict-commit-summary');
if (elRestrict) elRestrict.checked = cfg.general?.restrict_commit_summary !== false;
const elCheckoutNewBranch = get<HTMLInputElement>('#set-checkout-new-branch');
if (elCheckoutNewBranch) elCheckoutNewBranch.checked = cfg.general?.checkout_new_branch !== false;
}
1 change: 0 additions & 1 deletion Frontend/src/scripts/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export interface GlobalSettings {
telemetry?: boolean;
crash_reports?: boolean;
restrict_commit_summary?: boolean;
checkout_new_branch?: boolean;
};
git?: {
backend?: string;
Expand Down
2 changes: 1 addition & 1 deletion docs/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ OpenVCS is plugin-first and VCS-agnostic. Features, themes, UI changes, and VCS
</tr>
<tr><td>List local branches</td><td align="center">✅</td><td>Local branch visibility</td></tr>
<tr><td>List remote branches</td><td align="center">✅</td><td>Remote branch visibility</td></tr>
<tr><td>Create branch</td><td align="center">✅</td><td>Create from current branch; optional auto-checkout default in Settings; non-current base refs require backend support</td></tr>
<tr><td>Create branch</td><td align="center">✅</td><td>Create from current branch; optional checkout toggle in the Create Branch dialog; non-current base refs require backend support</td></tr>
<tr><td>Checkout branch</td><td align="center">✅</td><td>Switch active branch</td></tr>
<tr><td>Rename branch</td><td align="center">✅</td><td>Local branch rename</td></tr>
<tr><td>Delete branch</td><td align="center">✅</td><td>Branch cleanup</td></tr>
Expand Down
Loading