From 54802643046b477ae7a8f51f6d73e0739561282f Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Mon, 16 Nov 2026 06:48:19 -0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(git):=20=E5=A4=9A=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E5=85=B1=E5=90=8C=E5=88=86=E6=94=AF=20git.workspaceCommonRefer?= =?UTF-8?q?ences=EF=BC=9B=E5=9B=BE=E6=8A=95=E5=BD=B1=20checkedOutHeads=20?= =?UTF-8?q?=E6=8C=89=E5=90=84=E4=BB=93=E5=BA=93=E6=A3=80=E5=87=BA=E5=88=86?= =?UTF-8?q?=E6=94=AF=E6=A0=87=E8=AE=B0=E5=BD=93=E5=89=8D=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- rust/contracts/rust-core-api.md | 31 ++- rust/crates/core/src/protocol/command.rs | 5 + .../crates/core/src/runtime/dispatcher/git.rs | 3 + .../src/tests/git_workspace_repositories.rs | 4 + rust/crates/git/src/graph.rs | 45 +++- rust/crates/git/src/graph_tests.rs | 21 ++ rust/crates/git/src/lib.rs | 1 + rust/crates/git/src/workspace_repositories.rs | 6 +- .../common_references.rs | 210 ++++++++++++++++++ .../git/src/workspace_repositories/tests.rs | 13 +- .../git/workspace-common-references-v1.json | 93 ++++++++ 11 files changed, 417 insertions(+), 15 deletions(-) create mode 100644 rust/crates/git/src/workspace_repositories/common_references.rs create mode 100644 rust/fixtures/git/workspace-common-references-v1.json diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index f40b6ded..4250d983 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -784,6 +784,7 @@ 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, the branch they all have checked out, and each common branch's shared upstream | | `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 | @@ -1820,12 +1821,17 @@ 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, and `currentBranch` is then ignored. 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 @@ -2135,6 +2141,27 @@ 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, current?, local?, +remote? }`: `id` is the `workspace.repositories` ID, `current` the short name of +the checked-out local branch (absent when HEAD is detached or unborn), `local` +the local branches as `{ name, upstream? }` with the short name of the tracked +remote branch, and `remote` the remote branches' short names such as +`origin/main`. The response is `{ current, local, remote }`, as IntelliJ IDEA's +Common Local Branches and Common Remote Branches: `local` and `remote` are the +branches every repository has, in the first repository's order; `current` is the +branch every repository has checked out, `null` when they differ or one is +detached; each `local` entry is `{ name, upstream, current }`, where `upstream` is +the remote branch every repository tracks with it, `null` when one tracks +nothing or they track different branches, and `current` says it is the common +checked-out branch. One repository lists its own branches; an empty list has +none. A view runs an action on a common branch, such as a checkout, in every +repository. At most 10,000 repositories and 1,000,000 branch names in total are +accepted. An invalid or repeated `id`, an empty, NUL-containing or longer than +4,096-byte name, a branch listed twice in one repository, or an unknown field +fails with `invalid_request`. See +`rust/fixtures/git/workspace-common-references-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`, diff --git a/rust/crates/core/src/protocol/command.rs b/rust/crates/core/src/protocol/command.rs index 3a692c73..99980ba8 100644 --- a/rust/crates/core/src/protocol/command.rs +++ b/rust/crates/core/src/protocol/command.rs @@ -853,6 +853,8 @@ 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 Update or Pull from collected facts (`git.updatePlan`). UpdatePlan, /// Plans history refresh windows, page merges, and selection retention (`git.historyWindow`). @@ -1483,6 +1485,9 @@ impl CoreCommand { } "git.workspaceChangeGroups" => Some(Self::Git(GitCommand::WorkspaceChangeGroups)), "git.workspaceHistoryMerge" => Some(Self::Git(GitCommand::WorkspaceHistoryMerge)), + "git.workspaceCommonReferences" => { + Some(Self::Git(GitCommand::WorkspaceCommonReferences)) + } "git.updatePlan" => Some(Self::Git(GitCommand::UpdatePlan)), "git.historyWindow" => Some(Self::Git(GitCommand::HistoryWindow)), "git.graphProjection" => Some(Self::Git(GitCommand::GraphProjection)), diff --git a/rust/crates/core/src/runtime/dispatcher/git.rs b/rust/crates/core/src/runtime/dispatcher/git.rs index 27be3dc8..24735a21 100644 --- a/rust/crates/core/src/runtime/dispatcher/git.rs +++ b/rust/crates/core/src/runtime/dispatcher/git.rs @@ -449,6 +449,9 @@ pub(super) fn dispatch(command: GitCommand, id: Option, 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::UpdatePlan => plugin_response(id, payload, lithe_git::update_plan_command), GitCommand::HistoryWindow => { plugin_response(id, payload, lithe_git::history_window_command) diff --git a/rust/crates/core/src/tests/git_workspace_repositories.rs b/rust/crates/core/src/tests/git_workspace_repositories.rs index 36e286a4..5d415011 100644 --- a/rust/crates/core/src/tests/git_workspace_repositories.rs +++ b/rust/crates/core/src/tests/git_workspace_repositories.rs @@ -76,6 +76,10 @@ 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"), + ); } /// Discovery entries with the status each repository reports, as hosts send them. diff --git a/rust/crates/git/src/graph.rs b/rust/crates/git/src/graph.rs index 058258db..198e3fd7 100644 --- a/rust/crates/git/src/graph.rs +++ b/rust/crates/git/src/graph.rs @@ -56,6 +56,12 @@ struct Request { /// When present, the response lists the commits reachable from this local branch. #[serde(default)] current_branch: Option, + /// When true, the response lists the commits reachable from every commit Git decorates as a + /// checked-out branch (`HEAD -> name`), in place of `current_branch`: the current branch of + /// each repository of a log that lists several, as IntelliJ's highlighter reads the current + /// branch of each commit's own root. A detached `HEAD` starts no walk. + #[serde(default)] + checked_out_heads: bool, } #[derive(Debug, Clone, Deserialize)] @@ -903,7 +909,14 @@ fn project(request: &Request, options: DisplayOptions) -> GraphProjection { permanent_context, options, ); - if let Some(branch) = &request.current_branch { + if request.checked_out_heads { + projection.current_branch_hashes = ancestry(request, |commit| { + commit + .decorations + .split(',') + .any(|value| value.trim().starts_with("HEAD -> ")) + }); + } else if let Some(branch) = &request.current_branch { projection.current_branch_hashes = current_branch_hashes(request, branch); } projection @@ -1191,24 +1204,36 @@ fn build_rows( /// IntelliJ's `CurrentBranchHighlighter` colors ancestry, including every merge /// parent. Only the loaded graph can prove membership; a missing parent ends the walk. fn current_branch_hashes(request: &Request, branch: &str) -> Vec { + let no_remotes = HashSet::new(); + let mut found = false; + ancestry(request, |commit| { + // Only the first commit carrying the branch starts the walk. + if found { + return false; + } + found = parse_labels(&commit.decorations, &no_remotes) + .iter() + .any(|l| l.kind == GraphLabelKind::Branch && l.title == branch); + found + }) +} + +/// The commits reachable from every loaded commit `is_head` picks, scoped ones first, sorted. +fn ancestry(request: &Request, mut is_head: impl FnMut(&CommitInput) -> bool) -> Vec { let all = request .commits .iter() .chain(request.repository_commits.iter()) .collect::>(); - let no_remotes = HashSet::new(); - let Some(head) = all.iter().find(|commit| { - parse_labels(&commit.decorations, &no_remotes) - .iter() - .any(|l| l.kind == GraphLabelKind::Branch && l.title == branch) - }) else { - return Vec::new(); - }; let mut by_hash: HashMap<&str, &CommitInput> = HashMap::with_capacity(all.len()); for commit in &all { by_hash.entry(commit.hash.as_str()).or_insert(commit); } - let mut pending = vec![head.hash.as_str()]; + let mut pending = all + .iter() + .filter(|commit| is_head(commit)) + .map(|commit| commit.hash.as_str()) + .collect::>(); let mut reached = HashSet::new(); while let Some(hash) = pending.pop() { if !reached.insert(hash) { diff --git a/rust/crates/git/src/graph_tests.rs b/rust/crates/git/src/graph_tests.rs index 268e9a4e..bdcfd546 100644 --- a/rust/crates/git/src/graph_tests.rs +++ b/rust/crates/git/src/graph_tests.rs @@ -34,6 +34,7 @@ fn new_request(commits: Vec) -> Request { visible_hashes: None, display_mode: DisplayMode::Compact, current_branch: None, + checked_out_heads: false, } } @@ -755,6 +756,26 @@ fn current_branch_ancestry_follows_every_merge_parent_and_never_guesses() { assert!(project(&detached, COMPACT).current_branch_hashes.is_empty()); } +#[test] +fn checked_out_heads_walk_the_current_branch_of_every_repository() { + // A log of two repositories: each one's checked-out branch starts its own walk; a branch that + // is not checked out and a detached HEAD start none. + let mut request = new_request(vec![ + commit("a2@alpha", &["a1@alpha"], "HEAD -> main"), + commit("b3", &["b2"], "feature"), + commit("b2", &["b1"], "HEAD -> develop, origin/develop"), + commit("a1@alpha", &[], ""), + commit("b1", &[], ""), + commit("c1", &[], "HEAD"), + ]); + request.current_branch = Some("feature".to_string()); + request.checked_out_heads = true; + assert_eq!( + project(&request, COMPACT).current_branch_hashes, + ["a1@alpha", "a2@alpha", "b1", "b2"] + ); +} + #[test] fn current_branch_ancestry_is_bounded_and_prefers_the_scoped_commit() { // A cycle in malformed input is walked once. diff --git a/rust/crates/git/src/lib.rs b/rust/crates/git/src/lib.rs index 9af40a23..ef1fbe14 100644 --- a/rust/crates/git/src/lib.rs +++ b/rust/crates/git/src/lib.rs @@ -128,6 +128,7 @@ pub use shelf::shelf_command; pub use update_plan::command as update_plan_command; pub use workspace_repositories::{ change_groups_command as workspace_change_groups_command, + common_references_command as workspace_common_references_command, history_merge_command as workspace_history_merge_command, selection_command as workspace_repository_selection_command, }; diff --git a/rust/crates/git/src/workspace_repositories.rs b/rust/crates/git/src/workspace_repositories.rs index cfb38dbf..8e2ec894 100644 --- a/rust/crates/git/src/workspace_repositories.rs +++ b/rust/crates/git/src/workspace_repositories.rs @@ -5,17 +5,19 @@ //! below it. A folder without `.git` that holds several repositories lists only //! nested ones. Hosts pass those discovery entries back unchanged, together with //! what they read from each repository, and Core decides which repositories a -//! view acts on, how the repositories' changes group and stage, and how their -//! histories interleave in one log. Views keep drawing, folding, and the native +//! view acts on, how the repositories' changes group and stage, how their +//! histories interleave in one log, and which branches they all have. Views keep drawing, folding, and the native //! Git reads and writes the plans name. mod change_groups; +mod common_references; mod history_merge; mod selection; #[cfg(test)] mod tests; pub use change_groups::command as change_groups_command; +pub use common_references::command as common_references_command; pub use history_merge::command as history_merge_command; pub use selection::command as selection_command; diff --git a/rust/crates/git/src/workspace_repositories/common_references.rs b/rust/crates/git/src/workspace_repositories/common_references.rs new file mode 100644 index 00000000..f2db94dd --- /dev/null +++ b/rust/crates/git/src/workspace_repositories/common_references.rs @@ -0,0 +1,210 @@ +//! Finds the branches every repository of a workspace has in common. +//! +//! The branch popup of a folder that holds several repositories lists, below the +//! repositories, the local and remote branches that every one of them has, as +//! IntelliJ IDEA lists its Common Local Branches and Common Remote Branches. An +//! action on such a branch, a checkout or a new branch from it, runs in every +//! repository at once. A branch that one repository lacks is not common, so the +//! popup offers it only in the panels of the repositories that have it. +//! +//! The lists keep the order of the first repository, the order the host read its +//! references in. A local branch is on in the workspace when every repository has +//! it checked out, and its upstream is common when every repository tracks the +//! same remote branch with it; otherwise the popup shows no upstream. + +use super::{invalid, valid_id, MAX_REPOSITORIES}; +use lithe_protocol::CoreError; +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::collections::{HashMap, HashSet}; + +/// Bounds the branch names across one request; larger lists are host bugs. +const MAX_BRANCHES: usize = 1_000_000; +/// Git refuses longer reference names on every supported platform. +const MAX_NAME_BYTES: usize = 4096; + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct Request { + /// The repositories the popup lists, in the order it lists them. + repositories: Vec, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct RepositoryReferences { + /// The repository's `workspace.repositories` ID. + id: String, + /// The local branch the repository has checked out, absent when its HEAD is + /// detached or unborn. + #[serde(default)] + current: Option, + /// The repository's local branches by short name, in the order the host read them. + #[serde(default)] + local: Vec, + /// The repository's remote branches by short name, such as `origin/main`. + #[serde(default)] + remote: Vec, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct LocalBranch { + name: String, + /// The short name of the remote branch the branch tracks, absent when none. + #[serde(default)] + upstream: Option, +} + +#[derive(Debug, Serialize, PartialEq)] +#[serde(rename_all = "camelCase")] +struct Response { + /// The branch every repository has checked out, `null` when they differ or + /// one is detached. + current: Option, + /// The local branches every repository has, in the first repository's order. + local: Vec, + /// The remote branches every repository has, in the first repository's order. + remote: Vec, +} + +#[derive(Debug, Serialize, PartialEq)] +#[serde(rename_all = "camelCase")] +struct CommonLocalBranch { + name: String, + /// The remote branch every repository tracks with this branch, `null` when + /// one tracks nothing or they track different branches. + upstream: Option, + /// True when every repository has this branch checked out. + current: bool, +} + +/// Handles `git.workspaceCommonReferences`. +pub fn command(payload: Value) -> Result { + let request: Request = serde_json::from_value(payload).map_err(|error| { + invalid("Invalid workspace common references request").with_details(error.to_string()) + })?; + validate(&request.repositories)?; + Ok(serde_json::to_value(common(&request.repositories)) + .expect("workspace common references should encode")) +} + +/// Rejects requests a popup cannot send: too many repositories or branches, an +/// invalid or repeated ID, an empty or oversized branch name, or a branch listed +/// twice in one repository. +fn validate(repositories: &[RepositoryReferences]) -> Result<(), CoreError> { + if repositories.len() > MAX_REPOSITORIES { + return Err(invalid("Too many workspace repositories")); + } + let mut ids = HashSet::new(); + let mut total = 0usize; + for repository in repositories { + if !valid_id(&repository.id) || !ids.insert(repository.id.as_str()) { + return Err(invalid("Invalid or repeated workspace repository ID")); + } + total = total + .saturating_add(repository.local.len()) + .saturating_add(repository.remote.len()); + if total > MAX_BRANCHES { + return Err(invalid("Too many workspace branches")); + } + if repository + .current + .as_deref() + .is_some_and(|name| !valid_name(name)) + { + return Err(invalid("Invalid current branch name")); + } + let mut local = HashSet::new(); + for branch in &repository.local { + if !valid_name(&branch.name) || !local.insert(branch.name.as_str()) { + return Err(invalid("Invalid or repeated local branch name")); + } + if branch + .upstream + .as_deref() + .is_some_and(|name| !valid_name(name)) + { + return Err(invalid("Invalid upstream branch name")); + } + } + let mut remote = HashSet::new(); + for name in &repository.remote { + if !valid_name(name) || !remote.insert(name.as_str()) { + return Err(invalid("Invalid or repeated remote branch name")); + } + } + } + Ok(()) +} + +fn valid_name(name: &str) -> bool { + !name.is_empty() && name.len() <= MAX_NAME_BYTES && !name.contains('\0') +} + +/// Intersects the repositories' branches in the first repository's order. +fn common(repositories: &[RepositoryReferences]) -> Response { + let Some((first, rest)) = repositories.split_first() else { + return Response { + current: None, + local: Vec::new(), + remote: Vec::new(), + }; + }; + let current = first + .current + .as_ref() + .filter(|name| { + rest.iter() + .all(|other| other.current.as_ref() == Some(*name)) + }) + .cloned(); + // Each other repository's local branches by name, with the upstream it tracks. + let others_local: Vec>> = rest + .iter() + .map(|repository| { + repository + .local + .iter() + .map(|branch| (branch.name.as_str(), branch.upstream.as_deref())) + .collect() + }) + .collect(); + let local = first + .local + .iter() + .filter_map(|branch| { + let mut upstream = branch.upstream.as_deref(); + for other in &others_local { + let tracked = other.get(branch.name.as_str())?; + if *tracked != upstream { + upstream = None; + } + } + Some(CommonLocalBranch { + name: branch.name.clone(), + upstream: upstream.map(str::to_owned), + current: current.as_deref() == Some(branch.name.as_str()), + }) + }) + .collect(); + let others_remote: Vec> = rest + .iter() + .map(|repository| repository.remote.iter().map(String::as_str).collect()) + .collect(); + let remote = first + .remote + .iter() + .filter(|name| { + others_remote + .iter() + .all(|other| other.contains(name.as_str())) + }) + .cloned() + .collect(); + Response { + current, + local, + remote, + } +} diff --git a/rust/crates/git/src/workspace_repositories/tests.rs b/rust/crates/git/src/workspace_repositories/tests.rs index 3c58f52b..02393055 100644 --- a/rust/crates/git/src/workspace_repositories/tests.rs +++ b/rust/crates/git/src/workspace_repositories/tests.rs @@ -1,6 +1,9 @@ //! Workspace repository projections against their shared fixtures. -use super::{change_groups_command, history_merge_command, selection_command, MAX_REPOSITORIES}; +use super::{ + change_groups_command, common_references_command, history_merge_command, selection_command, + MAX_REPOSITORIES, +}; use lithe_protocol::CoreError; use serde_json::{json, Value}; @@ -31,6 +34,14 @@ fn selection_matches_the_shared_fixture() { ); } +#[test] +fn common_references_match_the_shared_fixture() { + check_fixture( + include_str!("../../../../fixtures/git/workspace-common-references-v1.json"), + common_references_command, + ); +} + #[test] fn change_groups_match_the_shared_fixture() { check_fixture( diff --git a/rust/fixtures/git/workspace-common-references-v1.json b/rust/fixtures/git/workspace-common-references-v1.json new file mode 100644 index 00000000..ea7daf9a --- /dev/null +++ b/rust/fixtures/git/workspace-common-references-v1.json @@ -0,0 +1,93 @@ +{ + "version": 1, + "description": "git.workspaceCommonReferences lists the local and remote branches every repository of a workspace has, as IntelliJ IDEA lists its Common Local Branches and Common Remote Branches, in the first repository's order. current is the branch every repository has checked out, null when they differ or one is detached; a common local branch is current when it is that branch. A common local branch's upstream is the remote branch every repository tracks with it, null when one tracks nothing or they track different branches.", + "cases": [ + { + "name": "branchesEveryRepositoryHasInTheFirstOrder", + "request": { + "repositories": [ + {"id": "backend", "current": "dev", "local": [ + {"name": "main", "upstream": "origin/main"}, + {"name": "dev", "upstream": "origin/dev"}, + {"name": "feature/login"} + ], "remote": ["origin/dev", "origin/main", "origin/feature/login"]}, + {"id": "frontend", "current": "dev", "local": [ + {"name": "dev", "upstream": "origin/dev"}, + {"name": "main", "upstream": "origin/main"} + ], "remote": ["origin/main", "origin/dev"]} + ] + }, + "response": { + "current": "dev", + "local": [ + {"name": "main", "upstream": "origin/main", "current": false}, + {"name": "dev", "upstream": "origin/dev", "current": true} + ], + "remote": ["origin/dev", "origin/main"] + } + }, + { + "name": "differentCheckoutsHaveNoCommonCurrentBranch", + "request": { + "repositories": [ + {"id": "backend", "current": "main", "local": [{"name": "main"}, {"name": "dev"}]}, + {"id": "frontend", "current": "dev", "local": [{"name": "main"}, {"name": "dev"}]}, + {"id": "shared", "local": [{"name": "dev"}, {"name": "main"}]} + ] + }, + "response": { + "current": null, + "local": [ + {"name": "main", "upstream": null, "current": false}, + {"name": "dev", "upstream": null, "current": false} + ], + "remote": [] + } + }, + { + "name": "anUpstreamOneRepositoryLacksOrTracksElsewhereIsNotCommon", + "request": { + "repositories": [ + {"id": "backend", "local": [{"name": "main", "upstream": "origin/main"}, {"name": "dev", "upstream": "origin/dev"}]}, + {"id": "frontend", "local": [{"name": "main"}, {"name": "dev", "upstream": "upstream/dev"}]}, + {"id": "shared", "local": [{"name": "main", "upstream": "origin/main"}, {"name": "dev", "upstream": "origin/dev"}]} + ] + }, + "response": { + "current": null, + "local": [ + {"name": "main", "upstream": null, "current": false}, + {"name": "dev", "upstream": null, "current": false} + ], + "remote": [] + } + }, + { + "name": "oneRepositoryListsItsOwnBranches", + "request": { + "repositories": [ + {"id": ".", "current": "main", "local": [{"name": "main", "upstream": "origin/main"}], "remote": ["origin/main"]} + ] + }, + "response": { + "current": "main", + "local": [{"name": "main", "upstream": "origin/main", "current": true}], + "remote": ["origin/main"] + } + }, + { + "name": "noRepositoryHasNoCommonBranch", + "request": {"repositories": []}, + "response": {"current": null, "local": [], "remote": []} + } + ], + "invalid": [ + {"name": "repeatedId", "request": {"repositories": [{"id": "a"}, {"id": "a"}]}}, + {"name": "absoluteId", "request": {"repositories": [{"id": "/a"}]}}, + {"name": "emptyBranchName", "request": {"repositories": [{"id": "a", "local": [{"name": ""}]}]}}, + {"name": "repeatedLocalBranch", "request": {"repositories": [{"id": "a", "local": [{"name": "main"}, {"name": "main"}]}]}}, + {"name": "repeatedRemoteBranch", "request": {"repositories": [{"id": "a", "remote": ["origin/main", "origin/main"]}]}}, + {"name": "emptyCurrentBranch", "request": {"repositories": [{"id": "a", "current": ""}]}}, + {"name": "unknownField", "request": {"repositories": [{"id": "a", "tags": []}]}} + ] +} From 680e0592e3ee5da3a171e6ad1764aff544cdfb7b Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Wed, 18 Nov 2026 10:35:04 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(git):=20=E5=85=B1=E5=90=8C=E5=88=86?= =?UTF-8?q?=E6=94=AF=E5=8E=9F=E6=A0=B7=E6=8E=A5=E6=94=B6=20git.references?= =?UTF-8?q?=20=E6=9D=A1=E7=9B=AE=E5=B9=B6=E5=90=88=E8=AE=A1=E9=A2=86?= =?UTF-8?q?=E5=85=88/=E8=90=BD=E5=90=8E=EF=BC=9B=E6=96=B0=E5=A2=9E=20git.w?= =?UTF-8?q?orkspaceBranchPlan=20=E5=A4=9A=E4=BB=93=E5=BA=93=E6=A3=80?= =?UTF-8?q?=E5=87=BA/=E6=96=B0=E5=BB=BA=E5=88=86=E6=94=AF=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E4=B8=8E=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - git.workspaceCommonReferences 输入改为各仓库 git.references 的 references 原样传回,响应用同一条目形状,ahead/behind 按仓库相加,不列标签 - 新增 git.workspaceBranchPlan:按 IDEA GitBranchOperation 规划检出、新建分支在各仓库的步骤、跳过已在该分支的仓库,并给出每步回滚动作 - graphProjection 复用 HEAD -> 解析;currentBranch 与 checkedOutHeads 同时出现时返回 invalid_request - 补齐无效测试用例(NUL、超长名、命名空间不符、重复、上游无效、多个当前分支等)和上限单测,增加真实 Git 直通测试 --- rust/contracts/rust-core-api.md | 80 +++- rust/crates/core/src/protocol/command.rs | 4 + .../crates/core/src/runtime/dispatcher/git.rs | 3 + .../src/tests/git_workspace_repositories.rs | 111 +++++ rust/crates/git/src/graph.rs | 26 +- rust/crates/git/src/graph_tests.rs | 5 +- rust/crates/git/src/lib.rs | 1 + rust/crates/git/src/workspace_repositories.rs | 5 +- .../src/workspace_repositories/branch_plan.rs | 188 ++++++++ .../common_references.rs | 299 +++++++----- .../git/src/workspace_repositories/tests.rs | 40 +- rust/fixtures/git/graph-projection-v1.json | 3 +- .../git/workspace-branch-plan-v1.json | 427 ++++++++++++++++++ .../git/workspace-common-references-v1.json | 294 ++++++++++-- 14 files changed, 1288 insertions(+), 198 deletions(-) create mode 100644 rust/crates/git/src/workspace_repositories/branch_plan.rs create mode 100644 rust/fixtures/git/workspace-branch-plan-v1.json diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index 22e938ef..35ed8dc9 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -793,7 +793,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, the branch they all have checked out, and each common branch's shared upstream | +| `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 | @@ -1840,7 +1841,8 @@ 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, and `currentBranch` is then ignored. Hosts call +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 @@ -2151,26 +2153,64 @@ hexadecimal digits, a commit repeated within one repository, a missing `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, current?, local?, -remote? }`: `id` is the `workspace.repositories` ID, `current` the short name of -the checked-out local branch (absent when HEAD is detached or unborn), `local` -the local branches as `{ name, upstream? }` with the short name of the tracked -remote branch, and `remote` the remote branches' short names such as -`origin/main`. The response is `{ current, local, remote }`, as IntelliJ IDEA's -Common Local Branches and Common Remote Branches: `local` and `remote` are the -branches every repository has, in the first repository's order; `current` is the -branch every repository has checked out, `null` when they differ or one is -detached; each `local` entry is `{ name, upstream, current }`, where `upstream` is -the remote branch every repository tracks with it, `null` when one tracks -nothing or they track different branches, and `current` says it is the common -checked-out branch. One repository lists its own branches; an empty list has -none. A view runs an action on a common branch, such as a checkout, in every -repository. At most 10,000 repositories and 1,000,000 branch names in total are -accepted. An invalid or repeated `id`, an empty, NUL-containing or longer than -4,096-byte name, a branch listed twice in one repository, or an unknown field -fails with `invalid_request`. See +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/` 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`, diff --git a/rust/crates/core/src/protocol/command.rs b/rust/crates/core/src/protocol/command.rs index a5f71629..d53ebbad 100644 --- a/rust/crates/core/src/protocol/command.rs +++ b/rust/crates/core/src/protocol/command.rs @@ -873,6 +873,9 @@ pub enum GitCommand { 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`). @@ -1522,6 +1525,7 @@ impl CoreCommand { "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)), diff --git a/rust/crates/core/src/runtime/dispatcher/git.rs b/rust/crates/core/src/runtime/dispatcher/git.rs index 24735a21..2ca1a667 100644 --- a/rust/crates/core/src/runtime/dispatcher/git.rs +++ b/rust/crates/core/src/runtime/dispatcher/git.rs @@ -452,6 +452,9 @@ pub(super) fn dispatch(command: GitCommand, id: Option, payload: Value) 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) diff --git a/rust/crates/core/src/tests/git_workspace_repositories.rs b/rust/crates/core/src/tests/git_workspace_repositories.rs index 5d415011..44245f5e 100644 --- a/rust/crates/core/src/tests/git_workspace_repositories.rs +++ b/rust/crates/core/src/tests/git_workspace_repositories.rs @@ -80,6 +80,10 @@ fn selection_change_groups_and_history_merge_match_their_shared_fixtures() { "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. @@ -243,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::>(); + 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}"); +} diff --git a/rust/crates/git/src/graph.rs b/rust/crates/git/src/graph.rs index 198e3fd7..42c47e19 100644 --- a/rust/crates/git/src/graph.rs +++ b/rust/crates/git/src/graph.rs @@ -59,7 +59,8 @@ struct Request { /// When true, the response lists the commits reachable from every commit Git decorates as a /// checked-out branch (`HEAD -> name`), in place of `current_branch`: the current branch of /// each repository of a log that lists several, as IntelliJ's highlighter reads the current - /// branch of each commit's own root. A detached `HEAD` starts no walk. + /// branch of each commit's own root. A detached `HEAD` starts no walk. Combined with + /// `current_branch` the request is invalid. #[serde(default)] checked_out_heads: bool, } @@ -245,7 +246,8 @@ pub struct GraphProjection { /// Projects one loaded history window in a single call. The request carries the /// scoped `commits`, optional `repositoryCommits` that fix the permanent layout, /// optional `visibleHashes` for a filtered graph, `remoteNames`, `displayMode` -/// (`compact` or `expanded`), and an optional `currentBranch`. +/// (`compact` or `expanded`), and either an optional `currentBranch` or +/// `checkedOutHeads`. pub fn command(payload: Value) -> Result { let request: Request = serde_json::from_value(payload).map_err(|error| { CoreError::new(ErrorCode::InvalidRequest, "Invalid Git graph request") @@ -263,6 +265,14 @@ pub fn command(payload: Value) -> Result { "Too many commits to project", )); } + if request.checked_out_heads && request.current_branch.is_some() { + // A log walks one repository's branch or every repository's own; both would let + // one silently win. + return Err(CoreError::new( + ErrorCode::InvalidRequest, + "currentBranch and checkedOutHeads cannot be combined", + )); + } serde_json::to_value(project(&request, request.display_mode.options())).map_err(|error| { CoreError::new(ErrorCode::ParseFailed, "Could not encode the Git graph") .with_details(error.to_string()) @@ -283,6 +293,12 @@ fn label(title: &str, kind: GraphLabelKind) -> GraphLabel { } } +/// The branch a `HEAD -> name` decoration says is checked out; `None` for every other +/// decoration, a detached `HEAD` included. +fn checked_out_branch(decoration: &str) -> Option<&str> { + decoration.trim().strip_prefix("HEAD -> ").map(local_name) +} + fn parse_labels(decorations: &str, remote_names: &HashSet<&str>) -> Vec { let mut labels = Vec::new(); for value in decorations.split(',') { @@ -292,9 +308,9 @@ fn parse_labels(decorations: &str, remote_names: &HashSet<&str>) -> Vec ") { + } else if let Some(branch) = checked_out_branch(raw) { labels.push(label("HEAD", GraphLabelKind::Head)); - labels.push(label(local_name(branch), GraphLabelKind::Branch)); + labels.push(label(branch, GraphLabelKind::Branch)); } else if let Some(tag) = raw.strip_prefix("tag: ") { labels.push(label(tag, GraphLabelKind::Tag)); } else if let Some(tag) = raw.strip_prefix("refs/tags/") { @@ -914,7 +930,7 @@ fn project(request: &Request, options: DisplayOptions) -> GraphProjection { commit .decorations .split(',') - .any(|value| value.trim().starts_with("HEAD -> ")) + .any(|value| checked_out_branch(value).is_some()) }); } else if let Some(branch) = &request.current_branch { projection.current_branch_hashes = current_branch_hashes(request, branch); diff --git a/rust/crates/git/src/graph_tests.rs b/rust/crates/git/src/graph_tests.rs index bdcfd546..2e577d0d 100644 --- a/rust/crates/git/src/graph_tests.rs +++ b/rust/crates/git/src/graph_tests.rs @@ -759,16 +759,15 @@ fn current_branch_ancestry_follows_every_merge_parent_and_never_guesses() { #[test] fn checked_out_heads_walk_the_current_branch_of_every_repository() { // A log of two repositories: each one's checked-out branch starts its own walk; a branch that - // is not checked out and a detached HEAD start none. + // is not checked out and a detached HEAD start none, even where the HEAD commit carries a branch. let mut request = new_request(vec![ commit("a2@alpha", &["a1@alpha"], "HEAD -> main"), commit("b3", &["b2"], "feature"), commit("b2", &["b1"], "HEAD -> develop, origin/develop"), commit("a1@alpha", &[], ""), commit("b1", &[], ""), - commit("c1", &[], "HEAD"), + commit("c1", &[], "HEAD, topic"), ]); - request.current_branch = Some("feature".to_string()); request.checked_out_heads = true; assert_eq!( project(&request, COMPACT).current_branch_hashes, diff --git a/rust/crates/git/src/lib.rs b/rust/crates/git/src/lib.rs index ef1fbe14..ab91ce8c 100644 --- a/rust/crates/git/src/lib.rs +++ b/rust/crates/git/src/lib.rs @@ -127,6 +127,7 @@ pub use rollback::{rollback_plan_command, rollback_prepare_command}; pub use shelf::shelf_command; pub use update_plan::command as update_plan_command; pub use workspace_repositories::{ + branch_plan_command as workspace_branch_plan_command, change_groups_command as workspace_change_groups_command, common_references_command as workspace_common_references_command, history_merge_command as workspace_history_merge_command, diff --git a/rust/crates/git/src/workspace_repositories.rs b/rust/crates/git/src/workspace_repositories.rs index 8e2ec894..fc32eba4 100644 --- a/rust/crates/git/src/workspace_repositories.rs +++ b/rust/crates/git/src/workspace_repositories.rs @@ -6,9 +6,11 @@ //! nested ones. Hosts pass those discovery entries back unchanged, together with //! what they read from each repository, and Core decides which repositories a //! view acts on, how the repositories' changes group and stage, how their -//! histories interleave in one log, and which branches they all have. Views keep drawing, folding, and the native +//! histories interleave in one log, which branches they all have, and how a +//! branch action runs across them. Views keep drawing, folding, and the native //! Git reads and writes the plans name. +mod branch_plan; mod change_groups; mod common_references; mod history_merge; @@ -16,6 +18,7 @@ mod selection; #[cfg(test)] mod tests; +pub use branch_plan::command as branch_plan_command; pub use change_groups::command as change_groups_command; pub use common_references::command as common_references_command; pub use history_merge::command as history_merge_command; diff --git a/rust/crates/git/src/workspace_repositories/branch_plan.rs b/rust/crates/git/src/workspace_repositories/branch_plan.rs new file mode 100644 index 00000000..f1934daa --- /dev/null +++ b/rust/crates/git/src/workspace_repositories/branch_plan.rs @@ -0,0 +1,188 @@ +//! Plans a branch action on a common branch across every repository of a workspace. +//! +//! IntelliJ IDEA runs a checkout or a new branch chosen on a Common Local or +//! Common Remote Branch in each repository in turn (`GitBranchOperation`). The +//! first repository that fails stops the action, and IDEA offers to roll back +//! the repositories that already succeeded, so the workspace does not stay split +//! between two branches. Core decides the steps and what undoes each one from the +//! `git.references` entries the popup already loaded; the host runs the writes +//! the plan names with its existing `git.write` calls and never decides itself +//! which repository to skip or how to undo one. +//! +//! A checkout skips the repositories already on the local branch, because the +//! write refuses the current branch. Undoing a checkout checks the previous local +//! branch out again; a repository whose HEAD was detached or unborn has no branch +//! to return to, so its step cannot be undone. Checking out a remote branch +//! creates or moves the local branch of the same name, which the rollback keeps: +//! returning to the previous branch loses no commit, and which local name the +//! write chose depends on the remotes, which the plan does not read. Undoing a new +//! branch deletes it, after checking the previous branch out again when the action +//! switched to it. + +use super::common_references::{self, Kind, Reference, RepositoryReferences}; +use super::invalid; +use lithe_protocol::CoreError; +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +/// The branch action the user chose on a common branch. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] +#[serde(rename_all = "camelCase")] +enum Operation { + /// Switches every repository to the common branch. + Checkout, + /// Creates a new local branch at the common branch in every repository. + CreateBranch, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct Request { + operation: Operation, + /// Full name of the common local or remote branch the action was chosen on. + reference: String, + /// The new branch's name for `createBranch`, as `git.branchNamePreview` cleaned it. + #[serde(default)] + name: Option, + /// For `createBranch`, switches every repository to the new branch. + #[serde(default)] + checkout: bool, + /// The repositories the action runs in, in the order the popup lists them, each + /// with its `git.references` entries. + repositories: Vec, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +struct Response { + /// The writes in the order they run. + steps: Vec, + /// IDs of the repositories a checkout leaves alone because they are already on + /// the branch, in request order. + skipped: Vec, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +struct Step { + /// The repository's `workspace.repositories` ID. + repository: String, + /// This repository's entry of the common branch: what a checkout switches to, + /// or where a new branch starts. + reference: ReferenceIdentity, + /// The writes that undo this step, in the order they run; `null` when nothing + /// can, because HEAD was detached or unborn before the step switched it. + rollback: Option>, +} + +/// The identity `git.write` checks before it acts on a reference. +#[derive(Debug, Clone, Serialize)] +#[serde(rename_all = "camelCase")] +struct ReferenceIdentity { + full_name: String, + short_name: String, + kind: Kind, +} + +impl From<&Reference> for ReferenceIdentity { + fn from(reference: &Reference) -> Self { + Self { + full_name: reference.full_name.clone(), + short_name: reference.short_name.clone(), + kind: reference.kind, + } + } +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +struct RollbackAction { + operation: RollbackOperation, + reference: ReferenceIdentity, +} + +/// A `git.write` operation a rollback runs. +#[derive(Debug, Clone, Copy, Serialize)] +#[serde(rename_all = "camelCase")] +enum RollbackOperation { + /// Checks the previous local branch out again. + Checkout, + /// Deletes the branch the step created. + DeleteBranch, +} + +/// Handles `git.workspaceBranchPlan`. +pub fn command(payload: Value) -> Result { + let request: Request = serde_json::from_value(payload).map_err(|error| { + invalid("Invalid workspace branch plan request").with_details(error.to_string()) + })?; + common_references::validate(&request.repositories)?; + let response = plan(&request)?; + Ok(serde_json::to_value(response).expect("workspace branch plan should encode")) +} + +/// Builds the steps, or rejects an action the popup cannot offer: no repository, +/// a branch one repository lacks or that is not a local or remote branch, a new +/// branch without a valid name or that a repository already has, or a name or +/// `checkout` on a checkout. +fn plan(request: &Request) -> Result { + if request.repositories.is_empty() { + return Err(invalid("A workspace branch action needs a repository")); + } + let new_branch = match (request.operation, request.name.as_deref()) { + (Operation::Checkout, None) if !request.checkout => None, + (Operation::CreateBranch, Some(name)) if common_references::valid_name(name) => { + Some(ReferenceIdentity { + full_name: format!("{}{name}", Kind::Local.namespace()), + short_name: name.to_owned(), + kind: Kind::Local, + }) + } + _ => return Err(invalid("Invalid workspace branch action")), + }; + let mut response = Response { + steps: Vec::new(), + skipped: Vec::new(), + }; + for repository in &request.repositories { + let Some(reference) = repository + .find(&request.reference) + .filter(|reference| reference.kind != Kind::Tag) + else { + return Err(invalid("Not every repository has the branch")); + }; + let previous = repository.current().map(|current| RollbackAction { + operation: RollbackOperation::Checkout, + reference: current.into(), + }); + let rollback = match &new_branch { + None => { + if reference.kind == Kind::Local && reference.is_current { + response.skipped.push(repository.id.clone()); + continue; + } + previous.map(|previous| vec![previous]) + } + Some(branch) => { + if repository.find(&branch.full_name).is_some() { + return Err(invalid("A repository already has the new branch")); + } + let delete = RollbackAction { + operation: RollbackOperation::DeleteBranch, + reference: branch.clone(), + }; + match (request.checkout, previous) { + (false, _) => Some(vec![delete]), + (true, Some(previous)) => Some(vec![previous, delete]), + (true, None) => None, + } + } + }; + response.steps.push(Step { + repository: repository.id.clone(), + reference: reference.into(), + rollback, + }); + } + Ok(response) +} diff --git a/rust/crates/git/src/workspace_repositories/common_references.rs b/rust/crates/git/src/workspace_repositories/common_references.rs index f2db94dd..66898ca5 100644 --- a/rust/crates/git/src/workspace_repositories/common_references.rs +++ b/rust/crates/git/src/workspace_repositories/common_references.rs @@ -4,13 +4,18 @@ //! repositories, the local and remote branches that every one of them has, as //! IntelliJ IDEA lists its Common Local Branches and Common Remote Branches. An //! action on such a branch, a checkout or a new branch from it, runs in every -//! repository at once. A branch that one repository lacks is not common, so the -//! popup offers it only in the panels of the repositories that have it. +//! repository at once (see `branch_plan`). A branch that one repository lacks is +//! not common, so the popup offers it only in the panels of the repositories that +//! have it. //! -//! The lists keep the order of the first repository, the order the host read its -//! references in. A local branch is on in the workspace when every repository has -//! it checked out, and its upstream is common when every repository tracks the -//! same remote branch with it; otherwise the popup shows no upstream. +//! Hosts pass each repository's `git.references` entries back unchanged. The +//! common branches come back in the same entry shape, so a popup draws them with +//! the rows it already draws for one repository. The lists keep the order of the +//! first repository. A common local branch is current when every repository has +//! it checked out, its upstream is common when every repository tracks the same +//! remote branch with it, and its `ahead` and `behind` add up what each +//! repository counts against its own upstream, as IDEA marks a common branch +//! with incoming or outgoing commits when any repository has them. use super::{invalid, valid_id, MAX_REPOSITORIES}; use lithe_protocol::CoreError; @@ -18,65 +23,112 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use std::collections::{HashMap, HashSet}; -/// Bounds the branch names across one request; larger lists are host bugs. -const MAX_BRANCHES: usize = 1_000_000; +/// Bounds the references across one request; larger lists are host bugs. +pub(super) const MAX_REFERENCES: usize = 1_000_000; /// Git refuses longer reference names on every supported platform. const MAX_NAME_BYTES: usize = 4096; -#[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase", deny_unknown_fields)] -struct Request { - /// The repositories the popup lists, in the order it lists them. - repositories: Vec, +/// A reference's namespace, as `git.references` names it. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub(super) enum Kind { + Local, + Remote, + Tag, } +impl Kind { + /// The prefix that turns a short name of this kind into its full name. + pub(super) fn namespace(self) -> &'static str { + match self { + Kind::Local => "refs/heads/", + Kind::Remote => "refs/remotes/", + Kind::Tag => "refs/tags/", + } + } +} + +/// One `git.references` entry, passed back unchanged; the fields Core does not +/// read, such as `peelsToCommit`, are ignored. #[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase", deny_unknown_fields)] -struct RepositoryReferences { - /// The repository's `workspace.repositories` ID. - id: String, - /// The local branch the repository has checked out, absent when its HEAD is - /// detached or unborn. +#[serde(rename_all = "camelCase")] +pub(super) struct Reference { + pub(super) full_name: String, + pub(super) short_name: String, + pub(super) kind: Kind, + /// Marks the checked-out local branch. #[serde(default)] - current: Option, - /// The repository's local branches by short name, in the order the host read them. + pub(super) is_current: bool, + /// The short name of the remote branch a local branch tracks. #[serde(default)] - local: Vec, - /// The repository's remote branches by short name, such as `origin/main`. + pub(super) upstream_short_name: Option, + /// Commits only the local branch has, compared with its upstream. #[serde(default)] - remote: Vec, + pub(super) ahead: usize, + /// Commits only the local branch's upstream has. + #[serde(default)] + pub(super) behind: usize, } +/// One repository of the popup with the `references` its `git.references` call returned. #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] -struct LocalBranch { - name: String, - /// The short name of the remote branch the branch tracks, absent when none. - #[serde(default)] - upstream: Option, +pub(super) struct RepositoryReferences { + /// The repository's `workspace.repositories` ID. + pub(super) id: String, + pub(super) references: Vec, } -#[derive(Debug, Serialize, PartialEq)] +impl RepositoryReferences { + /// The checked-out local branch; `None` when HEAD is detached or unborn. + pub(super) fn current(&self) -> Option<&Reference> { + self.references + .iter() + .find(|reference| reference.kind == Kind::Local && reference.is_current) + } + + /// The reference with this full name, when the repository has it. + pub(super) fn find(&self, full_name: &str) -> Option<&Reference> { + self.references + .iter() + .find(|reference| reference.full_name == full_name) + } +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct Request { + /// The repositories the popup lists, in the order it lists them. + repositories: Vec, +} + +#[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] struct Response { - /// The branch every repository has checked out, `null` when they differ or - /// one is detached. - current: Option, /// The local branches every repository has, in the first repository's order. - local: Vec, + local: Vec, /// The remote branches every repository has, in the first repository's order. - remote: Vec, + remote: Vec, } -#[derive(Debug, Serialize, PartialEq)] +/// A common branch in the shape of a `git.references` entry. +#[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] -struct CommonLocalBranch { - name: String, - /// The remote branch every repository tracks with this branch, `null` when - /// one tracks nothing or they track different branches. - upstream: Option, - /// True when every repository has this branch checked out. - current: bool, +struct CommonReference { + full_name: String, + short_name: String, + kind: Kind, + /// Always true: a branch names a commit. + peels_to_commit: bool, + /// True when every repository has this local branch checked out. + is_current: bool, + /// The remote branch every repository tracks with this local branch; `null` + /// when one tracks nothing or they track different branches. + upstream_short_name: Option, + /// The repositories' `ahead` counts added up. + ahead: usize, + /// The repositories' `behind` counts added up. + behind: usize, } /// Handles `git.workspaceCommonReferences`. @@ -89,10 +141,21 @@ pub fn command(payload: Value) -> Result { .expect("workspace common references should encode")) } -/// Rejects requests a popup cannot send: too many repositories or branches, an -/// invalid or repeated ID, an empty or oversized branch name, or a branch listed -/// twice in one repository. -fn validate(repositories: &[RepositoryReferences]) -> Result<(), CoreError> { +/// Rejects reference lists `git.references` cannot produce: too many repositories +/// or references, an invalid or repeated ID, a name that is empty, oversized, holds +/// NUL, or whose full name is not its short name in its kind's namespace, a +/// reference listed twice in one repository, an invalid upstream name, or a +/// current reference that is not the repository's one local branch. +pub(super) fn validate(repositories: &[RepositoryReferences]) -> Result<(), CoreError> { + validate_bounded(repositories, MAX_REFERENCES) +} + +/// [`validate`] with the reference bound as a parameter, so a test can cross it +/// without building a million entries. +pub(super) fn validate_bounded( + repositories: &[RepositoryReferences], + max_references: usize, +) -> Result<(), CoreError> { if repositories.len() > MAX_REPOSITORIES { return Err(invalid("Too many workspace repositories")); } @@ -102,109 +165,99 @@ fn validate(repositories: &[RepositoryReferences]) -> Result<(), CoreError> { if !valid_id(&repository.id) || !ids.insert(repository.id.as_str()) { return Err(invalid("Invalid or repeated workspace repository ID")); } - total = total - .saturating_add(repository.local.len()) - .saturating_add(repository.remote.len()); - if total > MAX_BRANCHES { - return Err(invalid("Too many workspace branches")); + total = total.saturating_add(repository.references.len()); + if total > max_references { + return Err(invalid("Too many workspace references")); } - if repository - .current - .as_deref() - .is_some_and(|name| !valid_name(name)) - { - return Err(invalid("Invalid current branch name")); - } - let mut local = HashSet::new(); - for branch in &repository.local { - if !valid_name(&branch.name) || !local.insert(branch.name.as_str()) { - return Err(invalid("Invalid or repeated local branch name")); + let mut names = HashSet::new(); + let mut current = false; + for reference in &repository.references { + let namespaced = reference + .full_name + .strip_prefix(reference.kind.namespace()) + .is_some_and(|short| short == reference.short_name); + if !valid_name(&reference.short_name) + || !valid_name(&reference.full_name) + || !namespaced + { + return Err(invalid("Invalid reference name")); + } + if !names.insert(reference.full_name.as_str()) { + return Err(invalid("Repeated reference")); } - if branch - .upstream + if reference + .upstream_short_name .as_deref() .is_some_and(|name| !valid_name(name)) { return Err(invalid("Invalid upstream branch name")); } - } - let mut remote = HashSet::new(); - for name in &repository.remote { - if !valid_name(name) || !remote.insert(name.as_str()) { - return Err(invalid("Invalid or repeated remote branch name")); + if reference.is_current { + if reference.kind != Kind::Local || current { + return Err(invalid("Only one local branch can be current")); + } + current = true; } } } Ok(()) } -fn valid_name(name: &str) -> bool { +pub(super) fn valid_name(name: &str) -> bool { !name.is_empty() && name.len() <= MAX_NAME_BYTES && !name.contains('\0') } /// Intersects the repositories' branches in the first repository's order. fn common(repositories: &[RepositoryReferences]) -> Response { + let mut response = Response { + local: Vec::new(), + remote: Vec::new(), + }; let Some((first, rest)) = repositories.split_first() else { - return Response { - current: None, - local: Vec::new(), - remote: Vec::new(), - }; + return response; }; - let current = first - .current - .as_ref() - .filter(|name| { - rest.iter() - .all(|other| other.current.as_ref() == Some(*name)) - }) - .cloned(); - // Each other repository's local branches by name, with the upstream it tracks. - let others_local: Vec>> = rest + // Each other repository's references by full name. + let others: Vec> = rest .iter() .map(|repository| { repository - .local + .references .iter() - .map(|branch| (branch.name.as_str(), branch.upstream.as_deref())) + .map(|reference| (reference.full_name.as_str(), reference)) .collect() }) .collect(); - let local = first - .local - .iter() - .filter_map(|branch| { - let mut upstream = branch.upstream.as_deref(); - for other in &others_local { - let tracked = other.get(branch.name.as_str())?; - if *tracked != upstream { - upstream = None; - } + for reference in &first.references { + let list = match reference.kind { + Kind::Local => &mut response.local, + Kind::Remote => &mut response.remote, + Kind::Tag => continue, + }; + let mut common = CommonReference { + full_name: reference.full_name.clone(), + short_name: reference.short_name.clone(), + kind: reference.kind, + peels_to_commit: true, + is_current: reference.is_current, + upstream_short_name: reference.upstream_short_name.clone(), + ahead: reference.ahead, + behind: reference.behind, + }; + let shared = others.iter().all(|other| { + let Some(theirs) = other.get(reference.full_name.as_str()) else { + return false; + }; + common.is_current &= theirs.is_current; + if common.upstream_short_name != theirs.upstream_short_name { + common.upstream_short_name = None; } - Some(CommonLocalBranch { - name: branch.name.clone(), - upstream: upstream.map(str::to_owned), - current: current.as_deref() == Some(branch.name.as_str()), - }) - }) - .collect(); - let others_remote: Vec> = rest - .iter() - .map(|repository| repository.remote.iter().map(String::as_str).collect()) - .collect(); - let remote = first - .remote - .iter() - .filter(|name| { - others_remote - .iter() - .all(|other| other.contains(name.as_str())) - }) - .cloned() - .collect(); - Response { - current, - local, - remote, + common.ahead = common.ahead.saturating_add(theirs.ahead); + common.behind = common.behind.saturating_add(theirs.behind); + true + }); + if shared { + list.push(common); + } } + response } diff --git a/rust/crates/git/src/workspace_repositories/tests.rs b/rust/crates/git/src/workspace_repositories/tests.rs index 02393055..b607d998 100644 --- a/rust/crates/git/src/workspace_repositories/tests.rs +++ b/rust/crates/git/src/workspace_repositories/tests.rs @@ -1,8 +1,8 @@ //! Workspace repository projections against their shared fixtures. use super::{ - change_groups_command, common_references_command, history_merge_command, selection_command, - MAX_REPOSITORIES, + branch_plan_command, change_groups_command, common_references_command, history_merge_command, + selection_command, MAX_REPOSITORIES, }; use lithe_protocol::CoreError; use serde_json::{json, Value}; @@ -42,6 +42,14 @@ fn common_references_match_the_shared_fixture() { ); } +#[test] +fn branch_plan_matches_the_shared_fixture() { + check_fixture( + include_str!("../../../../fixtures/git/workspace-branch-plan-v1.json"), + branch_plan_command, + ); +} + #[test] fn change_groups_match_the_shared_fixture() { check_fixture( @@ -143,3 +151,31 @@ fn a_repository_at_a_filesystem_root_still_parents_nested_repositories() { .unwrap(); assert_eq!(response["groups"][1]["parentReference"], "unchanged"); } + +#[test] +fn reference_lists_past_the_repository_bound_are_rejected() { + let repositories = (0..=MAX_REPOSITORIES) + .map(|index| json!({"id": format!("r{index}"), "references": []})) + .collect::>(); + assert!(common_references_command(json!({ "repositories": repositories })).is_err()); + let plan = json!({"operation": "checkout", "reference": "refs/heads/main", + "repositories": json!(repositories)}); + assert!(branch_plan_command(plan).is_err()); +} + +#[test] +fn reference_lists_past_the_reference_bound_are_rejected() { + use super::common_references::{validate_bounded, RepositoryReferences}; + let repository = |id: &str| -> RepositoryReferences { + serde_json::from_value(json!({"id": id, "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote"} + ]})) + .unwrap() + }; + // The bound counts every repository's references together, not each one's. + let repositories = [repository("a"), repository("b")]; + assert!(validate_bounded(&repositories, 4).is_ok()); + assert!(validate_bounded(&repositories, 3).is_err()); + assert_eq!(super::common_references::MAX_REFERENCES, 1_000_000); +} diff --git a/rust/fixtures/git/graph-projection-v1.json b/rust/fixtures/git/graph-projection-v1.json index e2888082..e9b8b484 100644 --- a/rust/fixtures/git/graph-projection-v1.json +++ b/rust/fixtures/git/graph-projection-v1.json @@ -3846,6 +3846,7 @@ {"name":"missingCommits","request":{}}, {"name":"unknownField","request":{"commits":[],"extra":true}}, {"name":"commitWithoutHash","request":{"commits":[{"parentHashes":[]}]}}, - {"name":"badDisplayMode","request":{"commits":[],"displayMode":"wide"}} + {"name":"badDisplayMode","request":{"commits":[],"displayMode":"wide"}}, + {"name":"currentBranchWithCheckedOutHeads","request":{"commits":[],"currentBranch":"main","checkedOutHeads":true}} ] } diff --git a/rust/fixtures/git/workspace-branch-plan-v1.json b/rust/fixtures/git/workspace-branch-plan-v1.json new file mode 100644 index 00000000..822ed71c --- /dev/null +++ b/rust/fixtures/git/workspace-branch-plan-v1.json @@ -0,0 +1,427 @@ +{ + "version": 1, + "description": "git.workspaceBranchPlan plans a checkout or a new branch chosen on a common branch across every repository of a workspace, as IntelliJ IDEA's GitBranchOperation runs it: steps run in request order and stop at the first failure; undoing the steps that already ran runs each step's rollback, the last step first. A checkout skips the repositories already on the local branch. Undoing a checkout checks the previous local branch out again, and a remote branch checkout keeps the local branch it created or moved; undoing a new branch checks the previous branch out again when the action switched to it, then deletes the new branch. A step whose repository was detached or unborn before it switched HEAD has rollback null.", + "cases": [ + { + "name": "checkoutSkipsTheRepositoriesAlreadyOnTheBranch", + "request": { + "operation": "checkout", + "reference": "refs/heads/dev", + "repositories": [ + { + "id": "backend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "frontend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "shared", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } + ] + }, + "response": { + "steps": [ + { + "repository": "backend", + "reference": {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local"}, + "rollback": [{"operation": "checkout", "reference": {"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}}] + }, + {"repository": "shared", "reference": {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local"}, "rollback": null} + ], + "skipped": ["frontend"] + } + }, + { + "name": "checkoutOfARemoteBranchRunsInEveryRepository", + "request": { + "operation": "checkout", + "reference": "refs/remotes/origin/dev", + "repositories": [ + { + "id": "backend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "frontend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "shared", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } + ] + }, + "response": { + "steps": [ + { + "repository": "backend", + "reference": {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote"}, + "rollback": [{"operation": "checkout", "reference": {"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}}] + }, + { + "repository": "frontend", + "reference": {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote"}, + "rollback": [{"operation": "checkout", "reference": {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local"}}] + }, + {"repository": "shared", "reference": {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote"}, "rollback": null} + ], + "skipped": [] + } + }, + { + "name": "checkoutWhereEveryRepositoryIsOnTheBranchHasNoStep", + "request": { + "operation": "checkout", + "reference": "refs/heads/main", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": null, "ahead": 0, "behind": 0}] + }, + { + "id": "b", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + }, + "response": {"steps": [], "skipped": ["a", "b"]} + }, + { + "name": "newBranchThatSwitchesReturnsAndDeletesOnRollback", + "request": { + "operation": "createBranch", + "reference": "refs/heads/main", + "name": "feature/login", + "checkout": true, + "repositories": [ + { + "id": "backend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "frontend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "shared", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } + ] + }, + "response": { + "steps": [ + { + "repository": "backend", + "reference": {"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}, + "rollback": [ + {"operation": "checkout", "reference": {"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}}, + {"operation": "deleteBranch", "reference": {"fullName": "refs/heads/feature/login", "shortName": "feature/login", "kind": "local"}} + ] + }, + { + "repository": "frontend", + "reference": {"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}, + "rollback": [ + {"operation": "checkout", "reference": {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local"}}, + {"operation": "deleteBranch", "reference": {"fullName": "refs/heads/feature/login", "shortName": "feature/login", "kind": "local"}} + ] + }, + {"repository": "shared", "reference": {"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}, "rollback": null} + ], + "skipped": [] + } + }, + { + "name": "newBranchThatStaysOnlyDeletesOnRollback", + "request": { + "operation": "createBranch", + "reference": "refs/remotes/origin/main", + "name": "feature/login", + "repositories": [ + { + "id": "backend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "frontend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "shared", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } + ] + }, + "response": { + "steps": [ + { + "repository": "backend", + "reference": {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote"}, + "rollback": [{"operation": "deleteBranch", "reference": {"fullName": "refs/heads/feature/login", "shortName": "feature/login", "kind": "local"}}] + }, + { + "repository": "frontend", + "reference": {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote"}, + "rollback": [{"operation": "deleteBranch", "reference": {"fullName": "refs/heads/feature/login", "shortName": "feature/login", "kind": "local"}}] + }, + { + "repository": "shared", + "reference": {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote"}, + "rollback": [{"operation": "deleteBranch", "reference": {"fullName": "refs/heads/feature/login", "shortName": "feature/login", "kind": "local"}}] + } + ], + "skipped": [] + } + } + ], + "invalid": [ + { + "name": "unknownField", + "request": { + "operation": "checkout", + "reference": "refs/heads/main", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ], + "extra": true + } + }, + { + "name": "unknownOperation", + "request": { + "operation": "merge", + "reference": "refs/heads/main", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "missingReference", + "request": { + "operation": "checkout", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + {"name": "noRepository", "request": {"operation": "checkout", "reference": "refs/heads/main", "repositories": []}}, + { + "name": "branchOneRepositoryLacks", + "request": { + "operation": "checkout", + "reference": "refs/heads/dev", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + }, + { + "id": "b", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "tag", + "request": { + "operation": "checkout", + "reference": "refs/tags/v1", + "repositories": [{"id": "a", "references": [{"fullName": "refs/tags/v1", "shortName": "v1", "kind": "tag", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}]}] + } + }, + { + "name": "checkoutWithName", + "request": { + "operation": "checkout", + "reference": "refs/heads/main", + "name": "x", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "checkoutWithCheckout", + "request": { + "operation": "checkout", + "reference": "refs/heads/main", + "checkout": true, + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "newBranchWithoutName", + "request": { + "operation": "createBranch", + "reference": "refs/heads/main", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "newBranchWithEmptyName", + "request": { + "operation": "createBranch", + "reference": "refs/heads/main", + "name": "", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "newBranchNameWithNul", + "request": { + "operation": "createBranch", + "reference": "refs/heads/main", + "name": "x\u0000", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "newBranchOneRepositoryHas", + "request": { + "operation": "createBranch", + "reference": "refs/heads/main", + "name": "dev", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + }, + { + "id": "b", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } + ] + } + }, + { + "name": "invalidReferences", + "request": { + "operation": "checkout", + "reference": "refs/heads/main", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "repeatedId", + "request": { + "operation": "checkout", + "reference": "refs/heads/main", + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + }, + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + } + ] +} diff --git a/rust/fixtures/git/workspace-common-references-v1.json b/rust/fixtures/git/workspace-common-references-v1.json index ea7daf9a..071841f4 100644 --- a/rust/fixtures/git/workspace-common-references-v1.json +++ b/rust/fixtures/git/workspace-common-references-v1.json @@ -1,45 +1,86 @@ { "version": 1, - "description": "git.workspaceCommonReferences lists the local and remote branches every repository of a workspace has, as IntelliJ IDEA lists its Common Local Branches and Common Remote Branches, in the first repository's order. current is the branch every repository has checked out, null when they differ or one is detached; a common local branch is current when it is that branch. A common local branch's upstream is the remote branch every repository tracks with it, null when one tracks nothing or they track different branches.", + "description": "git.workspaceCommonReferences lists the local and remote branches every repository of a workspace has, as IntelliJ IDEA lists its Common Local Branches and Common Remote Branches. Each repository passes its git.references entries unchanged; the common branches come back in the same entry shape, in the first repository's order, without tags. A common local branch 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.", "cases": [ { "name": "branchesEveryRepositoryHasInTheFirstOrder", "request": { "repositories": [ - {"id": "backend", "current": "dev", "local": [ - {"name": "main", "upstream": "origin/main"}, - {"name": "dev", "upstream": "origin/dev"}, - {"name": "feature/login"} - ], "remote": ["origin/dev", "origin/main", "origin/feature/login"]}, - {"id": "frontend", "current": "dev", "local": [ - {"name": "dev", "upstream": "origin/dev"}, - {"name": "main", "upstream": "origin/main"} - ], "remote": ["origin/main", "origin/dev"]} + { + "id": "backend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 1, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/dev", "ahead": 2, "behind": 1}, + {"fullName": "refs/heads/feature/login", "shortName": "feature/login", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + { + "fullName": "refs/remotes/origin/feature/login", + "shortName": "origin/feature/login", + "kind": "remote", + "peelsToCommit": true, + "isCurrent": false, + "upstreamShortName": null, + "ahead": 0, + "behind": 0 + }, + {"fullName": "refs/tags/v1.0", "shortName": "v1.0", "kind": "tag", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "frontend", + "references": [ + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 3}, + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 0, "behind": 4}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/tags/v1.0", "shortName": "v1.0", "kind": "tag", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } ] }, "response": { - "current": "dev", "local": [ - {"name": "main", "upstream": "origin/main", "current": false}, - {"name": "dev", "upstream": "origin/dev", "current": true} + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 1, "behind": 4}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/dev", "ahead": 2, "behind": 4} ], - "remote": ["origin/dev", "origin/main"] + "remote": [ + {"fullName": "refs/remotes/origin/dev", "shortName": "origin/dev", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] } }, { - "name": "differentCheckoutsHaveNoCommonCurrentBranch", + "name": "differentCheckoutsHaveNoCurrentCommonBranch", "request": { "repositories": [ - {"id": "backend", "current": "main", "local": [{"name": "main"}, {"name": "dev"}]}, - {"id": "frontend", "current": "dev", "local": [{"name": "main"}, {"name": "dev"}]}, - {"id": "shared", "local": [{"name": "dev"}, {"name": "main"}]} + { + "id": "backend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "frontend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + }, + { + "id": "shared", + "references": [ + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } ] }, "response": { - "current": null, "local": [ - {"name": "main", "upstream": null, "current": false}, - {"name": "dev", "upstream": null, "current": false} + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} ], "remote": [] } @@ -48,46 +89,213 @@ "name": "anUpstreamOneRepositoryLacksOrTracksElsewhereIsNotCommon", "request": { "repositories": [ - {"id": "backend", "local": [{"name": "main", "upstream": "origin/main"}, {"name": "dev", "upstream": "origin/dev"}]}, - {"id": "frontend", "local": [{"name": "main"}, {"name": "dev", "upstream": "upstream/dev"}]}, - {"id": "shared", "local": [{"name": "main", "upstream": "origin/main"}, {"name": "dev", "upstream": "origin/dev"}]} + { + "id": "backend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/dev", "ahead": 1, "behind": 0} + ] + }, + { + "id": "frontend", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "upstream/dev", "ahead": 2, "behind": 0} + ] + }, + { + "id": "shared", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/dev", "ahead": 0, "behind": 0} + ] + } ] }, "response": { - "current": null, "local": [ - {"name": "main", "upstream": null, "current": false}, - {"name": "dev", "upstream": null, "current": false} + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 3, "behind": 0} ], "remote": [] } }, { - "name": "oneRepositoryListsItsOwnBranches", + "name": "oneRepositoryListsItsOwnBranchesAndIgnoresFieldsCoreDoesNotRead", "request": { "repositories": [ - {"id": ".", "current": "main", "local": [{"name": "main", "upstream": "origin/main"}], "remote": ["origin/main"]} + { + "id": ".", + "references": [ + { + "fullName": "refs/heads/main", + "shortName": "main", + "kind": "local", + "peelsToCommit": false, + "isCurrent": true, + "upstreamShortName": "origin/main", + "ahead": 0, + "behind": 0, + "extra": "ignored" + }, + {"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/tags/nightly", "shortName": "nightly", "kind": "tag", "peelsToCommit": false, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } ] }, "response": { - "current": "main", - "local": [{"name": "main", "upstream": "origin/main", "current": true}], - "remote": ["origin/main"] + "local": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": "origin/main", "ahead": 0, "behind": 0}], + "remote": [{"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] } }, { - "name": "noRepositoryHasNoCommonBranch", - "request": {"repositories": []}, - "response": {"current": null, "local": [], "remote": []} - } + "name": "entriesWithoutCountsCountNothing", + "request": { + "repositories": [ + {"id": "a", "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}]}, + {"id": "b", "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local"}]} + ] + }, + "response": {"local": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}], "remote": []} + }, + {"name": "noRepositoryHasNoCommonBranch", "request": {"repositories": []}, "response": {"local": [], "remote": []}} ], "invalid": [ - {"name": "repeatedId", "request": {"repositories": [{"id": "a"}, {"id": "a"}]}}, - {"name": "absoluteId", "request": {"repositories": [{"id": "/a"}]}}, - {"name": "emptyBranchName", "request": {"repositories": [{"id": "a", "local": [{"name": ""}]}]}}, - {"name": "repeatedLocalBranch", "request": {"repositories": [{"id": "a", "local": [{"name": "main"}, {"name": "main"}]}]}}, - {"name": "repeatedRemoteBranch", "request": {"repositories": [{"id": "a", "remote": ["origin/main", "origin/main"]}]}}, - {"name": "emptyCurrentBranch", "request": {"repositories": [{"id": "a", "current": ""}]}}, - {"name": "unknownField", "request": {"repositories": [{"id": "a", "tags": []}]}} + {"name": "unknownField", "request": {"repositories": [], "extra": true}}, + {"name": "unknownRepositoryField", "request": {"repositories": [{"id": "a", "references": [], "current": "main"}]}}, + {"name": "missingReferences", "request": {"repositories": [{"id": "a"}]}}, + {"name": "emptyId", "request": {"repositories": [{"id": "", "references": []}]}}, + {"name": "absoluteId", "request": {"repositories": [{"id": "/a", "references": []}]}}, + {"name": "repeatedId", "request": {"repositories": [{"id": "a", "references": []}, {"id": "a", "references": []}]}}, + { + "name": "unknownKind", + "request": { + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "note", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + {"name": "missingFullName", "request": {"repositories": [{"id": "a", "references": [{"shortName": "main", "kind": "local"}]}]}}, + {"name": "emptyShortName", "request": {"repositories": [{"id": "a", "references": [{"fullName": "refs/heads/", "shortName": "", "kind": "local"}]}]}}, + { + "name": "nameWithNul", + "request": { + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/ma\u0000in", "shortName": "ma\u0000in", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "nameLongerThan4096Bytes", + "request": { + "repositories": [ + { + "id": "a", + "references": [ + { + "fullName": "refs/heads/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "kind": "local", + "peelsToCommit": true, + "isCurrent": false, + "upstreamShortName": null, + "ahead": 0, + "behind": 0 + } + ] + } + ] + } + }, + { + "name": "fullNameOutsideItsKindsNamespace", + "request": { + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "fullNameThatIsNotTheShortName", + "request": { + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "repeatedReference", + "request": { + "repositories": [ + { + "id": "a", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } + ] + } + }, + { + "name": "emptyUpstream", + "request": { + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "", "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "upstreamWithNul", + "request": { + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": false, "upstreamShortName": "origin/ma\u0000in", "ahead": 0, "behind": 0}] + } + ] + } + }, + { + "name": "twoCurrentBranches", + "request": { + "repositories": [ + { + "id": "a", + "references": [ + {"fullName": "refs/heads/main", "shortName": "main", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": null, "ahead": 0, "behind": 0}, + {"fullName": "refs/heads/dev", "shortName": "dev", "kind": "local", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": null, "ahead": 0, "behind": 0} + ] + } + ] + } + }, + { + "name": "currentRemoteBranch", + "request": { + "repositories": [ + { + "id": "a", + "references": [{"fullName": "refs/remotes/origin/main", "shortName": "origin/main", "kind": "remote", "peelsToCommit": true, "isCurrent": true, "upstreamShortName": null, "ahead": 0, "behind": 0}] + } + ] + } + } ] }