Skip to content

Commit

Permalink
reformulate delete-remote as forget
Browse files Browse the repository at this point in the history
  • Loading branch information
gulbanana committed Mar 23, 2024
1 parent 34e1843 commit b13b7bf
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 30 deletions.
4 changes: 1 addition & 3 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Consequently, the commands available for a branch as displayed in the UI have po
2) "Untrack":
- For a *tracking local/combined branch*, untracks all remotes.
- For an *unsynced remote branch*, untracks one remote.
- For a *deleting remote branch*, clears the pending delete (it was tracking absence).
3) "Push": Applies to local branches tracking any remotes.
4) "Push to remote...": Applies to local branches when any remotes exist.
5) "Fetch": Downloads for a specific branch only.
Expand All @@ -68,8 +67,7 @@ Consequently, the commands available for a branch as displayed in the UI have po
- For a *tracking/combined branch*, untracks first.
8) "Delete": Applies to a user-visible object, not combined objects.
- 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.
- For a *remote branch*, forgets the remote ref (which also clears pending deletes.)

Multiple-dispatch commands:
1) "Move": Drop local branch onto revision. Sets the ref to a commit, potentially de- or re-syncing it.
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ pub fn handle_context(window: Window, ctx: Operand) -> Result<()> {
r#ref,
StoreRef::RemoteBranch {
is_synced: false, // we can *see* the remote ref, and
is_tracked: true, // it has a local (regardless of absence)
is_tracked: true, // it has a local, and
is_absent: false, // that local is somewhere else
..
}
),
Expand Down
27 changes: 19 additions & 8 deletions src-tauri/src/worker/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use jj_lib::{
git::{self, GitBranchPushTargets, REMOTE_NAME_FOR_LOCAL_GIT_REPO},
matchers::{EverythingMatcher, FilesMatcher, Matcher},
object_id::ObjectId,
op_store::RefTarget,
op_store::{RefTarget, RemoteRef, RemoteRefState},
op_walk,
refs::{self, BranchPushAction, BranchPushUpdate, LocalAndRemoteRef},
repo::Repo,
Expand Down Expand Up @@ -582,12 +582,23 @@ impl Mutation for DeleteRef {
remote_name,
..
} => {
todo!("need to track-as-absent");
precondition!(
"{}@{} is a remote branch and cannot be deleted",
branch_name,
remote_name
);
let mut tx = ws.start_transaction()?;

// forget the branch entirely - when target is absent, it's removed from the view
let remote_ref = RemoteRef {
target: RefTarget::absent(),
state: RemoteRefState::New,
};

tx.mut_repo()
.set_remote_branch(&branch_name, &remote_name, remote_ref);

match ws
.finish_transaction(tx, format!("forget {}@{}", branch_name, remote_name))?
{
Some(new_status) => Ok(MutationResult::Updated { new_status }),
None => Ok(MutationResult::Unchanged),
}
}
StoreRef::LocalBranch { branch_name, .. } => {
let mut tx = ws.start_transaction()?;
Expand All @@ -605,7 +616,7 @@ impl Mutation for DeleteRef {

tx.mut_repo().set_tag_target(&tag_name, RefTarget::absent());

match ws.finish_transaction(tx, format!("forget {}", tag_name))? {
match ws.finish_transaction(tx, format!("forget tag {}", tag_name))? {
Some(new_status) => Ok(MutationResult::Updated { new_status }),
None => Ok(MutationResult::Unchanged),
}
Expand Down
18 changes: 18 additions & 0 deletions src/controls/BranchSpan.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
import type { StoreRef } from "../messages/StoreRef";
export let ref: Extract<StoreRef, { type: "LocalBranch" } | { type: "RemoteBranch" }>;
</script>

<span class="ref">
{ref.branch_name}{#if ref.type == "RemoteBranch"}@{ref.remote_name}{/if}
</span>

<style>
.ref {
pointer-events: auto;
user-select: text;
color: var(--ctp-subtext1);
font-family: var(--stack-code);
}
</style>
24 changes: 7 additions & 17 deletions src/mutators/BinaryMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import type { CommitId } from "../messages/CommitId";
import RevisionMutator from "./RevisionMutator";
import ChangeMutator from "./ChangeMutator";
import RefMutator from "./RefMutator";
import type { StoreRef } from "../messages/StoreRef";

export type RichHint = (string | ChangeId | CommitId)[];
export type RichHint = (string | ChangeId | CommitId | Extract<StoreRef, { type: "LocalBranch" } | { type: "RemoteBranch" }>)[];
export type Eligibility = { type: "yes", hint: RichHint } | { type: "maybe", hint: string } | { type: "no" };

export default class BinaryMutator {
Expand All @@ -36,17 +37,6 @@ export default class BinaryMutator {
return { type: "maybe", hint: "(child has only one parent)" };
}

// can't change our view of remote branches
if (from.type == "Ref" && from.ref.type == "RemoteBranch") {
if (from.ref.is_tracked && from.ref.is_absent) {
return { type: "maybe", hint: "(branch is deleted)" };
}
// we allow deleting of all other branch types, which might be a good enough reason to move them
// else {
// return { type: "maybe", hint: "(branch is remote)" };
// }
}

// can change these listed things (XXX add modes?)
if (from.type == "Revision") {
return { type: "yes", hint: ["Rebasing revision ", from.header.id.change] };
Expand All @@ -55,7 +45,7 @@ export default class BinaryMutator {
} else if (from.type == "Change") {
return { type: "yes", hint: [`Squashing changes at ${from.path.relative_path}`] };
} else if (from.type == "Ref" && from.ref.type != "Tag") {
return { type: "yes", hint: [`Moving branch ${from.ref.branch_name}`] };
return { type: "yes", hint: ["Moving branch ", from.ref] };
}

return { type: "no" };
Expand Down Expand Up @@ -121,7 +111,7 @@ export default class BinaryMutator {
if (this.#to.header.id.change.hex == this.#from.header.id.change.hex) {
return { type: "no" };
} else {
return { type: "yes", hint: [`Moving branch ${this.#from.ref.branch_name} to `, this.#to.header.id.change] };
return { type: "yes", hint: ["Moving branch ", this.#from.ref, " to ", this.#to.header.id.change] };
}
}

Expand All @@ -131,17 +121,17 @@ export default class BinaryMutator {
if (this.#from.ref.is_tracked) {
return { type: "maybe", hint: "(already tracked)" };
} else {
return { type: "yes", hint: [`Tracking remote branch ${this.#from.ref.branch_name}`] };
return { type: "yes", hint: ["Tracking remote branch ", this.#from.ref] };
}
}

// anything -> anywhere: delete
else if (this.#to.type == "Repository") {
if (this.#from.ref.type == "LocalBranch") {
return { type: "yes", hint: [`Deleting branch ${this.#from.ref.branch_name}`] };
return { type: "yes", hint: ["Deleting branch ", this.#from.ref] };
} else {
return {
type: "yes", hint: [`Deleting remote branch ${this.#from.ref.branch_name}@${this.#from.ref.remote_name}`]
type: "yes", hint: ["Forgetting remote branch ", this.#from.ref]
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/shell/InputDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
let dispatch = createEventDispatcher();
onMount(() => {
document.getElementById(`field-${fields[0]}`)?.focus();
document.getElementById(`field-${fields[0].label}`)?.focus();
});
function onCancel() {
Expand Down
3 changes: 3 additions & 0 deletions src/shell/StatusBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { RichHint } from "../mutators/BinaryMutator";
import BinaryMutator from "../mutators/BinaryMutator";
import { currentSource, currentTarget, hasModal, repoConfigEvent, repoStatusEvent } from "../stores";
import BranchSpan from "../controls/BranchSpan.svelte";
export let target: boolean;
Expand Down Expand Up @@ -93,6 +94,8 @@
{#each dropHint as run, i}
{#if typeof run == "string"}
<span>{run}{i == dropHint.length - 1 ? "." : ""}</span>
{:else if run.type == "LocalBranch" || run.type == "RemoteBranch"}
<span><BranchSpan ref={run} /></span>
{:else}
<span><IdSpan id={run} />{i == dropHint.length - 1 ? "." : ""}</span>
{/if}
Expand Down

0 comments on commit b13b7bf

Please sign in to comment.