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
71 changes: 69 additions & 2 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ or removing a command fails until the table changes in the same commit.
| `git.workspaceRepositorySelection` | Choose the workspace repository, or the set of repositories, a view acts on and the others it lists for switching, from discovery entries and the previous pick |
| `git.workspaceChangeGroups` | Group every workspace repository's status changes, plan each group's and the workspace line's staging, and report what a listed ancestor records for a submodule |
| `git.workspaceHistoryMerge` | Interleave the loaded history pages of several workspace repositories into one stable newest-first list with collision-safe commit keys, and name the repositories whose next page it waits on |
| `git.workspaceCommonReferences` | List the local and remote branches every workspace repository has, from each repository's `git.references` entries, in the same entry shape |
| `git.workspaceBranchPlan` | Plan a checkout or a new branch on a common branch across workspace repositories: the writes in order, the repositories skipped, and what undoes each write |
| `git.updatePlan` | Route a branch Update and gate a Pull from facts the host collected: blockers, strategy default, whether to ask, and the expected checkout |
| `git.historyWindow` | Plan a history refresh window, page merge, and selection retention over commit identities |
| `git.graphProjection` | Project a loaded history window into commit-graph lanes, color IDs, routes, print elements, and labels, optionally filtered |
Expand Down Expand Up @@ -1832,12 +1834,18 @@ commit. `rust/fixtures/git/history-window-v1.json` defines the rules.
`git.graphProjection` is a pure projection of one loaded history window; it never
starts Git. The request is `{ "commits": [{ "hash", "parentHashes", "decorations" }],
"remoteNames"?, "repositoryCommits"?, "visibleHashes"?, "displayMode"?,
"currentBranch"? }`: `commits` are in Git's child-before-parent order, `remoteNames`
"currentBranch"?, "checkedOutHeads"? }`: `commits` are in Git's child-before-parent order, `remoteNames`
are the remote short names that type a bare remote-tracking decoration,
`repositoryCommits` is the complete repository window that fixes the permanent layout
(ignored unless it is unique and covers every scoped commit), `visibleHashes` applies
a filter (omit it to show every commit), `displayMode` is `compact` (default) or
`expanded`, and `currentBranch` asks for the ancestry of that local branch. Hosts call
`expanded`, and `currentBranch` asks for the ancestry of that local branch. A log that
lists the commits of several repositories (`git.workspaceHistoryMerge`) sends
`checkedOutHeads: true` instead: the ancestry starts at every commit decorated as a
checked-out branch (`HEAD -> name`), the current branch of each repository, as IDEA's
current-branch highlighter reads the branch of each commit's own root; a detached `HEAD`
starts none, even on a commit that also carries a branch. A request with both
`currentBranch` and `checkedOutHeads: true` fails with `invalid_request`. Hosts call
it once per loaded window, never per commit, and recompute the whole window when a page
is appended or the history refreshes; lanes depend on every loaded edge, and a head
fragment's color ID is the wrapping 32-bit hash `h = 31 * h + unit` over the UTF-16
Expand Down Expand Up @@ -2147,6 +2155,65 @@ hexadecimal digits, a commit repeated within one repository, a missing
`complete`, or an unknown field fails with `invalid_request`. See
`rust/fixtures/git/workspace-history-merge-v1.json`.

`git.workspaceCommonReferences` is pure. It accepts `{ repositories }`, the
repositories a branch popup lists in its order, each `{ id, references }`: `id` is
the `workspace.repositories` ID and `references` is the `references` list of that
repository's `git.references` answer, passed back unchanged. Core reads
`fullName`, `shortName`, `kind`, `isCurrent`, `upstreamShortName`, `ahead`, and
`behind`; the last four default to `false`, `null`, and `0`, and other fields are
ignored. The response is `{ local, remote }`, as IntelliJ IDEA's Common Local
Branches and Common Remote Branches: the local and remote branches every
repository has, matched by `fullName`, in the first repository's order, as
`git.references` entries a popup draws with the rows it draws for one
repository. Tags are not listed. A common local branch has `isCurrent` when every
repository has it checked out; its `upstreamShortName` is the remote branch every
repository tracks with it, `null` when one tracks nothing or they track
different branches; its `ahead` and `behind` add up every repository's counts
against that repository's own upstream, as IDEA marks a common branch with
incoming or outgoing commits when any repository has them. `peelsToCommit` is
`true`. One repository lists its own branches; an empty list has none. At most
10,000 repositories and 1,000,000 references across the request are accepted.
An invalid or repeated `id`, a missing `references`, an unknown `kind`, a
`shortName` or `fullName` that is empty, holds NUL, or is longer than 4,096
bytes, a `fullName` that is not `shortName` under its kind's namespace
(`refs/heads/`, `refs/remotes/`, `refs/tags/`), a `fullName` listed twice in one
repository, an empty or NUL-containing `upstreamShortName`, more than one
current reference or a current one that is not a local branch, or an unknown
field outside the entries fails with `invalid_request`. See
`rust/fixtures/git/workspace-common-references-v1.json`.

`git.workspaceBranchPlan` is pure and plans an action chosen on a common branch
across every repository, as IDEA's `GitBranchOperation` runs it. It accepts
`{ operation, reference, name?, checkout?, repositories }`: `operation` is
`checkout` or `createBranch`, `reference` the `fullName` of the common local or
remote branch, `name` the new branch's name for `createBranch` as
`git.branchNamePreview` cleaned it, `checkout` (default `false`) whether
`createBranch` switches to the new branch, and `repositories` the entries
`git.workspaceCommonReferences` takes, in the order the action runs. The
response is `{ steps, skipped }`. Each step is `{ repository, reference,
rollback }`: `repository` is the ID, `reference` that repository's
`{ fullName, shortName, kind }` of the common branch, which is the
`gitReference` of the step's `git.write` (`checkout`, or `createBranch` with
`name` and `checkout`). Hosts run the steps in order and stop at the first
that fails. To undo the steps that already ran, as IDEA offers after a partial
failure, they run each step's `rollback`, the last step first, the actions of one
rollback in order; each action is `{ operation, reference }` with `operation`
`checkout` or `deleteBranch`, the `git.write` operation to run with that
`gitReference`. A checkout lists in `skipped` the repositories already on the
local branch and plans no step for them; undoing it checks the previous local
branch out again, and undoing a remote branch checkout keeps the local branch it
created or moved, because the plan does not read the remotes that name it.
Undoing a new branch checks the previous branch out again when `checkout` is set,
then deletes the new branch. `rollback` is `null` when the repository's HEAD was
detached or unborn before a step that switches it, so nothing returns it. The
`repositories` validation of `git.workspaceCommonReferences` applies; an empty
list, a `reference` that one repository lacks or that is a tag, a `createBranch`
without a non-empty, NUL-free `name` of at most 4,096 bytes or whose
`refs/heads/<name>` a repository already has, a `checkout` with `name` or
`checkout: true`, an unknown `operation`, or an unknown field outside the
entries fails with `invalid_request`. See
`rust/fixtures/git/workspace-branch-plan-v1.json`.

`git.workspaceChangeGroups` is pure and validates `repositories` the same way;
each entry also carries `changes`, the `git.status` changes read for that
repository, passed through unchanged. Core reads `path`, `originalPath`,
Expand Down
9 changes: 9 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,11 @@ pub enum GitCommand {
WorkspaceChangeGroups,
/// Interleaves the loaded histories of workspace repositories (`git.workspaceHistoryMerge`).
WorkspaceHistoryMerge,
/// Finds the branches every workspace repository has (`git.workspaceCommonReferences`).
WorkspaceCommonReferences,
/// Plans a branch action on a common branch across workspace repositories
/// (`git.workspaceBranchPlan`).
WorkspaceBranchPlan,
/// Plans a branch Update or Pull from collected facts (`git.updatePlan`).
UpdatePlan,
/// Plans history refresh windows, page merges, and selection retention (`git.historyWindow`).
Expand Down Expand Up @@ -1526,6 +1531,10 @@ impl CoreCommand {
}
"git.workspaceChangeGroups" => Some(Self::Git(GitCommand::WorkspaceChangeGroups)),
"git.workspaceHistoryMerge" => Some(Self::Git(GitCommand::WorkspaceHistoryMerge)),
"git.workspaceCommonReferences" => {
Some(Self::Git(GitCommand::WorkspaceCommonReferences))
}
"git.workspaceBranchPlan" => Some(Self::Git(GitCommand::WorkspaceBranchPlan)),
"git.updatePlan" => Some(Self::Git(GitCommand::UpdatePlan)),
"git.historyWindow" => Some(Self::Git(GitCommand::HistoryWindow)),
"git.graphProjection" => Some(Self::Git(GitCommand::GraphProjection)),
Expand Down
6 changes: 6 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@ pub(super) fn dispatch(command: GitCommand, id: Option<String>, payload: Value)
GitCommand::WorkspaceHistoryMerge => {
plugin_response(id, payload, lithe_git::workspace_history_merge_command)
}
GitCommand::WorkspaceCommonReferences => {
plugin_response(id, payload, lithe_git::workspace_common_references_command)
}
GitCommand::WorkspaceBranchPlan => {
plugin_response(id, payload, lithe_git::workspace_branch_plan_command)
}
GitCommand::UpdatePlan => plugin_response(id, payload, lithe_git::update_plan_command),
GitCommand::HistoryWindow => {
plugin_response(id, payload, lithe_git::history_window_command)
Expand Down
115 changes: 115 additions & 0 deletions rust/crates/core/src/tests/git_workspace_repositories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ fn selection_change_groups_and_history_merge_match_their_shared_fixtures() {
"git.workspaceHistoryMerge",
include_str!("../../../../fixtures/git/workspace-history-merge-v1.json"),
);
check_fixture(
"git.workspaceCommonReferences",
include_str!("../../../../fixtures/git/workspace-common-references-v1.json"),
);
check_fixture(
"git.workspaceBranchPlan",
include_str!("../../../../fixtures/git/workspace-branch-plan-v1.json"),
);
}

/// Discovery entries with the status each repository reports, as hosts send them.
Expand Down Expand Up @@ -239,3 +247,110 @@ fn history_pages_pass_through_to_the_history_merge() {
assert_eq!(order, [(0, 0), (1, 0), (0, 1)], "{merged}");
assert_eq!(merged["pending"], json!([]), "{merged}");
}

/// The `references` of `root`'s `git.references` answer, unchanged, as one repository entry.
fn repository_references(root: &Path, id: &str) -> Value {
let references = data("git.references", json!({"root": root}))["references"].clone();
json!({"id": id, "references": references})
}

/// The branch `root` has checked out.
fn current_branch(root: &Path) -> String {
let result = data(
"git.command",
json!({"root": root, "arguments": ["branch", "--show-current"]}),
);
result["stdout"].as_str().unwrap().trim().to_owned()
}

/// Runs one plan `git.write` with the reference the plan names.
fn write(root: &Path, operation: &Value, reference: &Value) {
let result = data(
"git.write",
json!({"root": root, "operation": operation, "gitReference": reference}),
);
assert_eq!(result["exitCode"], 0, "{operation} {reference}: {result}");
}

#[test]
fn references_pass_through_to_common_branches_and_the_branch_plan() {
let folder = Folder(temporary_root("workspace-common-references"));
let backend = folder.0.join("backend");
let frontend = folder.0.join("frontend");
for root in [&backend, &frontend] {
init(root);
commit_at(root, "initial", "2026-01-01T10:00:00+00:00");
git(root, &["branch", "-M", "main"]);
git(root, &["branch", "dev"]);
}
git(&backend, &["branch", "backend-only"]);
git(&backend, &["tag", "v1"]);
git(&frontend, &["switch", "-q", "dev"]);

let repositories = json!([
repository_references(&backend, "backend"),
repository_references(&frontend, "frontend")
]);
let common = data(
"git.workspaceCommonReferences",
json!({"repositories": repositories}),
);
let names = common["local"]
.as_array()
.unwrap()
.iter()
.map(|reference| reference["shortName"].as_str().unwrap())
.collect::<Vec<_>>();
assert_eq!(names, ["dev", "main"], "{common}");
assert!(
common["local"]
.as_array()
.unwrap()
.iter()
.all(|reference| reference["isCurrent"] == false),
"{common}"
);

// The plan's references are the ones git.write takes; a rollback returns each repository.
let plan = data(
"git.workspaceBranchPlan",
json!({"operation": "checkout", "reference": "refs/heads/dev", "repositories": repositories}),
);
assert_eq!(plan["skipped"], json!(["frontend"]), "{plan}");
let step = &plan["steps"][0];
assert_eq!(step["repository"], "backend", "{plan}");
write(&backend, &json!("checkout"), &step["reference"]);
assert_eq!(current_branch(&backend), "dev");
for action in step["rollback"].as_array().unwrap() {
write(&backend, &action["operation"], &action["reference"]);
}
assert_eq!(current_branch(&backend), "main");

let plan = data(
"git.workspaceBranchPlan",
json!({"operation": "createBranch", "reference": "refs/heads/main", "name": "feature",
"checkout": true, "repositories": repositories}),
);
for (root, step) in [&backend, &frontend]
.into_iter()
.zip(plan["steps"].as_array().unwrap())
{
let result = data(
"git.write",
json!({"root": root, "operation": "createBranch", "gitReference": step["reference"],
"name": "feature", "checkout": true}),
);
assert_eq!(result["exitCode"], 0, "{result}");
assert_eq!(current_branch(root), "feature");
for action in step["rollback"].as_array().unwrap() {
write(root, &action["operation"], &action["reference"]);
}
}
assert_eq!(current_branch(&backend), "main");
assert_eq!(current_branch(&frontend), "dev");
let branches = data(
"git.command",
json!({"root": frontend, "arguments": ["branch", "--list", "feature"]}),
);
assert_eq!(branches["stdout"], "", "{branches}");
}
Loading
Loading