Skip to content

Commit

Permalink
rethink immediate-push deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
gulbanana committed Mar 21, 2024
1 parent 6880c57 commit daa87ba
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
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).
4 changes: 2 additions & 2 deletions src-tauri/src/config/gg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
6 changes: 3 additions & 3 deletions src-tauri/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub trait GGSettings {
fn query_auto_snapshot(&self) -> Option<bool>;
fn query_check_immutable(&self) -> Option<bool>;
fn ui_theme_override(&self) -> Option<String>;
fn ui_indicate_disconnected_branches(&self) -> bool;
fn ui_mark_unpushed_branches(&self) -> bool;
}

impl GGSettings for UserSettings {
Expand Down Expand Up @@ -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)
}
}
14 changes: 12 additions & 2 deletions src-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ pub enum RepoConfig {
default_query: String,
latest_query: String,
status: RepoStatus,
theme: Option<String>,
indicate_disconnected_branches: bool,
theme_override: Option<String>,
mark_unpushed_branches: bool,
},
#[allow(dead_code)]
TimeoutError,
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/worker/gui_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}

Expand Down
11 changes: 7 additions & 4 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<RevResult> = {
type: "wait",
Expand All @@ -53,8 +54,10 @@
}
});
let theme = { indicate_disconnected_branches: true };
setContext("theme", theme);
let settings: Settings = {
markUnpushedBranches: true,
};
setContext<Settings>("settings", settings);
onEvent("gg://context/revision", mutateRevision);
onEvent("gg://context/tree", mutateTree);
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -129,7 +132,7 @@
</script>

<Zone operand={{ type: "Repository" }} alwaysTarget let:target>
<div id="shell" class={$repoConfigEvent?.type == "Workspace" ? $repoConfigEvent.theme : ""}>
<div id="shell" class={$repoConfigEvent?.type == "Workspace" ? $repoConfigEvent.theme_override : ""}>
{#if $repoConfigEvent.type == "Initial"}
<Pane>
<h2 slot="header">Loading...</h2>
Expand Down
2 changes: 1 addition & 1 deletion src/messages/RepoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>, 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, };
export type RepoConfig = { "type": "Initial" } | { "type": "Workspace", absolute_path: DisplayPath, git_remotes: Array<string>, 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, };
6 changes: 3 additions & 3 deletions src/objects/BranchObject.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts">
import { getContext } from "svelte";
import type { RevHeader } from "../messages/RevHeader";
import type { StoreRef } from "../messages/StoreRef";
import type { Operand } from "../messages/Operand";
import type Settings from "../shell/Settings";
import Icon from "../controls/Icon.svelte";
import Chip from "../controls/Chip.svelte";
import Object from "./Object.svelte";
import Zone from "./Zone.svelte";
import { getContext } from "svelte";
import { repoConfigEvent } from "../stores";
export let header: RevHeader;
export let ref: Extract<StoreRef, { type: "LocalBranch" | "RemoteBranch" }>;
Expand Down Expand Up @@ -63,7 +63,7 @@
break;
}
if (!getContext<any>("theme").indicate_disconnected_branches) {
if (!getContext<Settings>("settings").markUnpushedBranches) {
disconnected = false;
}
</script>
Expand Down
3 changes: 3 additions & 0 deletions src/shell/Settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default interface Settings {
markUnpushedBranches: boolean
}

0 comments on commit daa87ba

Please sign in to comment.