From daa87bae189d12c7fab30f45ec2f68a8e7ed8fc9 Mon Sep 17 00:00:00 2001 From: Thomas Castiglione Date: Wed, 20 Mar 2024 21:31:16 +0800 Subject: [PATCH] rethink immediate-push deletes --- CHANGELOG.md | 2 +- DESIGN.md | 12 ++++++------ src-tauri/src/config/gg.toml | 4 ++-- src-tauri/src/config/mod.rs | 6 +++--- src-tauri/src/menu.rs | 14 ++++++++++++-- src-tauri/src/messages/mod.rs | 4 ++-- src-tauri/src/worker/gui_util.rs | 4 ++-- src/App.svelte | 11 +++++++---- src/messages/RepoConfig.ts | 2 +- src/objects/BranchObject.svelte | 6 +++--- src/shell/Settings.ts | 3 +++ 11 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 src/shell/Settings.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 16897ea..f0f09d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ - Improved keyboard support and focus behaviour. - New config options: * `gg.queries.log-page-size` for tuning performance on large repositories. - * `gg.ui.indicate-disconnected-branches` to control whether local-only branches are marked. + * `gg.ui.mark-unpushed-branches` to control whether local-only branches are marked. ### Fixed - GG now understands divergent changes, and can act on commits that have a shared change id. diff --git a/DESIGN.md b/DESIGN.md index 67d156e..9787426 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -67,9 +67,9 @@ Consequently, the commands available for a branch as displayed in the UI have po - For a *nontracking local branch*, just renames. - For a *tracking/combined branch*, untracks first. 8) "Delete": Applies to a user-visible object, not combined objects. - - For a *local/combined branch*, untracks all remotes and then deletes the local ref. - - For an *untracked remote branch*, creates an absent local ref and then pushes to the remote. - - For an *unsynced remote branch*, untracks the remote, then creates and pushes the absent ref. + - For a *local/combined branch*, deletes the local ref. + - For an *untracked remote branch*, creates an absent local ref. + - For an *unsynced remote branch*, untracks the remote, then creates an absent ref. Multiple-dispatch commands: 1) "Move": Drop local branch onto revision. Sets the ref to a commit, potentially de- or re-syncing it. @@ -86,6 +86,6 @@ the fact that many branch states are "normal"; the mental shorthand is that add/ cause a remote to set this ref, and remove/red means the remote will no longer contain this ref (at this pointer). Additionally, a dashed border (like the dashed lines used for elided commits) has a special meaning, also -fuzzy: this ref is "disconnected" from any remote, usually meaning it's a local branch that does not but -*could* have tracked remote branches; it's also used for the cli-only state where the remote contains a -branch but your local view *of* that remote intends to, on push, delete it. \ No newline at end of file +fuzzy: this ref is "disconnected", either local-only or remote-only. Disconnected local branches are ones +which have no remotes (in a repo that does have remotes); disconnected remote branches are ones which will +be deleted on push (with an absent local ref). \ No newline at end of file diff --git a/src-tauri/src/config/gg.toml b/src-tauri/src/config/gg.toml index 43260ad..156a253 100644 --- a/src-tauri/src/config/gg.toml +++ b/src-tauri/src/config/gg.toml @@ -14,8 +14,8 @@ large-repo-heuristic = 100000 # auto-snapshot = [gg.ui] -# When set, branches that aren't pushed anywhere will be visually marked. -indicate-disconnected-branches = true +# When set, branches that are local-only or remote-only will be visually indicated. +mark-unpushed-branches = true # "light" or "dark". If not set, your OS settings will be used. # theme-override = diff --git a/src-tauri/src/config/mod.rs b/src-tauri/src/config/mod.rs index a426617..e77272e 100644 --- a/src-tauri/src/config/mod.rs +++ b/src-tauri/src/config/mod.rs @@ -6,7 +6,7 @@ pub trait GGSettings { fn query_auto_snapshot(&self) -> Option; fn query_check_immutable(&self) -> Option; fn ui_theme_override(&self) -> Option; - fn ui_indicate_disconnected_branches(&self) -> bool; + fn ui_mark_unpushed_branches(&self) -> bool; } impl GGSettings for UserSettings { @@ -34,9 +34,9 @@ impl GGSettings for UserSettings { self.config().get_string("gg.ui.theme-override").ok() } - fn ui_indicate_disconnected_branches(&self) -> bool { + fn ui_mark_unpushed_branches(&self) -> bool { self.config() - .get_bool("gg.ui.indicate-disconnected-branches") + .get_bool("gg.ui.mark-unpushed-branches") .unwrap_or(true) } } diff --git a/src-tauri/src/menu.rs b/src-tauri/src/menu.rs index 1983c72..842c570 100644 --- a/src-tauri/src/menu.rs +++ b/src-tauri/src/menu.rs @@ -395,8 +395,18 @@ pub fn handle_context(window: Window, ctx: Operand) -> Result<()> { matches!(r#ref, StoreRef::LocalBranch { .. }), )?; - // (untrack and) remove a local, or make a remote absent and push it - context_menu.enable("branch_delete", true)?; + // remove a local, or make a remote absent + context_menu.enable( + "branch_delete", + !matches!( + r#ref, + StoreRef::RemoteBranch { + is_absent: true, + is_tracked: true, + .. + } + ), + )?; window.popup_menu(context_menu)?; } diff --git a/src-tauri/src/messages/mod.rs b/src-tauri/src/messages/mod.rs index 1426f2a..63f0688 100644 --- a/src-tauri/src/messages/mod.rs +++ b/src-tauri/src/messages/mod.rs @@ -83,8 +83,8 @@ pub enum RepoConfig { default_query: String, latest_query: String, status: RepoStatus, - theme: Option, - indicate_disconnected_branches: bool, + theme_override: Option, + mark_unpushed_branches: bool, }, #[allow(dead_code)] TimeoutError, diff --git a/src-tauri/src/worker/gui_util.rs b/src-tauri/src/worker/gui_util.rs index bc4202f..0394e92 100644 --- a/src-tauri/src/worker/gui_util.rs +++ b/src-tauri/src/worker/gui_util.rs @@ -350,8 +350,8 @@ impl WorkspaceSession<'_> { default_query, latest_query, status: self.format_status(), - theme: self.settings.ui_theme_override(), - indicate_disconnected_branches: self.settings.ui_indicate_disconnected_branches() + theme_override: self.settings.ui_theme_override(), + mark_unpushed_branches: self.settings.ui_mark_unpushed_branches() }) } diff --git a/src/App.svelte b/src/App.svelte index ee8c663..b14827a 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -27,6 +27,7 @@ import InputDialog from "./shell/InputDialog.svelte"; import type { InputRequest } from "./messages/InputRequest"; import type { InputResponse } from "./messages/InputResponse"; + import type Settings from "./shell/Settings"; let selection: Query = { type: "wait", @@ -53,8 +54,10 @@ } }); - let theme = { indicate_disconnected_branches: true }; - setContext("theme", theme); + let settings: Settings = { + markUnpushedBranches: true, + }; + setContext("settings", settings); onEvent("gg://context/revision", mutateRevision); onEvent("gg://context/tree", mutateTree); @@ -72,7 +75,7 @@ $revisionSelectEvent = undefined; if (config.type == "Workspace") { - theme.indicate_disconnected_branches = config.indicate_disconnected_branches; + settings.markUnpushedBranches = config.mark_unpushed_branches; $repoStatusEvent = config.status; } } @@ -129,7 +132,7 @@ -
+
{#if $repoConfigEvent.type == "Initial"}

Loading...

diff --git a/src/messages/RepoConfig.ts b/src/messages/RepoConfig.ts index 0277260..be9ee90 100644 --- a/src/messages/RepoConfig.ts +++ b/src/messages/RepoConfig.ts @@ -2,4 +2,4 @@ import type { DisplayPath } from "./DisplayPath"; import type { RepoStatus } from "./RepoStatus"; -export type RepoConfig = { "type": "Initial" } | { "type": "Workspace", absolute_path: DisplayPath, git_remotes: Array, default_query: string, latest_query: string, status: RepoStatus, theme: string | null, indicate_disconnected_branches: boolean, } | { "type": "TimeoutError" } | { "type": "LoadError", absolute_path: DisplayPath, message: string, } | { "type": "WorkerError", message: string, }; \ No newline at end of file +export type RepoConfig = { "type": "Initial" } | { "type": "Workspace", absolute_path: DisplayPath, git_remotes: Array, default_query: string, latest_query: string, status: RepoStatus, theme_override: string | null, mark_unpushed_branches: boolean, } | { "type": "TimeoutError" } | { "type": "LoadError", absolute_path: DisplayPath, message: string, } | { "type": "WorkerError", message: string, }; \ No newline at end of file diff --git a/src/objects/BranchObject.svelte b/src/objects/BranchObject.svelte index 0478381..8ce734b 100644 --- a/src/objects/BranchObject.svelte +++ b/src/objects/BranchObject.svelte @@ -1,13 +1,13 @@ diff --git a/src/shell/Settings.ts b/src/shell/Settings.ts new file mode 100644 index 0000000..55b0c89 --- /dev/null +++ b/src/shell/Settings.ts @@ -0,0 +1,3 @@ +export default interface Settings { + markUnpushedBranches: boolean +} \ No newline at end of file