diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index 810b8e5a..84d52532 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -796,6 +796,8 @@ or removing a command fails until the table changes in the same commit. | `git.workspaceRepositorySelection` | Choose the workspace repository, or the set of repositories, a view acts on and the others it lists for switching, from discovery entries and the previous pick | | `git.workspaceChangeGroups` | Group every workspace repository's status changes, plan each group's and the workspace line's staging, and report what a listed ancestor records for a submodule | | `git.workspaceHistoryMerge` | Interleave the loaded history pages of several workspace repositories into one stable newest-first list with collision-safe commit keys, and name the repositories whose next page it waits on | +| `git.workspaceCommonReferences` | List the local and remote branches every workspace repository has, from each repository's `git.references` entries, in the same entry shape | +| `git.workspaceBranchPlan` | Plan a checkout or a new branch on a common branch across workspace repositories: the writes in order, the repositories skipped, and what undoes each write | | `git.updatePlan` | Route a branch Update and gate a Pull from facts the host collected: blockers, strategy default, whether to ask, and the expected checkout | | `git.historyWindow` | Plan a history refresh window, page merge, and selection retention over commit identities | | `git.graphProjection` | Project a loaded history window into commit-graph lanes, color IDs, routes, print elements, and labels, optionally filtered | @@ -1832,12 +1834,18 @@ commit. `rust/fixtures/git/history-window-v1.json` defines the rules. `git.graphProjection` is a pure projection of one loaded history window; it never starts Git. The request is `{ "commits": [{ "hash", "parentHashes", "decorations" }], "remoteNames"?, "repositoryCommits"?, "visibleHashes"?, "displayMode"?, -"currentBranch"? }`: `commits` are in Git's child-before-parent order, `remoteNames` +"currentBranch"?, "checkedOutHeads"? }`: `commits` are in Git's child-before-parent order, `remoteNames` are the remote short names that type a bare remote-tracking decoration, `repositoryCommits` is the complete repository window that fixes the permanent layout (ignored unless it is unique and covers every scoped commit), `visibleHashes` applies a filter (omit it to show every commit), `displayMode` is `compact` (default) or -`expanded`, and `currentBranch` asks for the ancestry of that local branch. Hosts call +`expanded`, and `currentBranch` asks for the ancestry of that local branch. A log that +lists the commits of several repositories (`git.workspaceHistoryMerge`) sends +`checkedOutHeads: true` instead: the ancestry starts at every commit decorated as a +checked-out branch (`HEAD -> name`), the current branch of each repository, as IDEA's +current-branch highlighter reads the branch of each commit's own root; a detached `HEAD` +starts none, even on a commit that also carries a branch. A request with both +`currentBranch` and `checkedOutHeads: true` fails with `invalid_request`. Hosts call it once per loaded window, never per commit, and recompute the whole window when a page is appended or the history refreshes; lanes depend on every loaded edge, and a head fragment's color ID is the wrapping 32-bit hash `h = 31 * h + unit` over the UTF-16 @@ -2147,6 +2155,65 @@ hexadecimal digits, a commit repeated within one repository, a missing `complete`, or an unknown field fails with `invalid_request`. See `rust/fixtures/git/workspace-history-merge-v1.json`. +`git.workspaceCommonReferences` is pure. It accepts `{ repositories }`, the +repositories a branch popup lists in its order, each `{ id, references }`: `id` is +the `workspace.repositories` ID and `references` is the `references` list of that +repository's `git.references` answer, passed back unchanged. Core reads +`fullName`, `shortName`, `kind`, `isCurrent`, `upstreamShortName`, `ahead`, and +`behind`; the last four default to `false`, `null`, and `0`, and other fields are +ignored. The response is `{ local, remote }`, as IntelliJ IDEA's Common Local +Branches and Common Remote Branches: the local and remote branches every +repository has, matched by `fullName`, in the first repository's order, as +`git.references` entries a popup draws with the rows it draws for one +repository. Tags are not listed. A common local branch has `isCurrent` when every +repository has it checked out; its `upstreamShortName` is the remote branch every +repository tracks with it, `null` when one tracks nothing or they track +different branches; its `ahead` and `behind` add up every repository's counts +against that repository's own upstream, as IDEA marks a common branch with +incoming or outgoing commits when any repository has them. `peelsToCommit` is +`true`. One repository lists its own branches; an empty list has none. At most +10,000 repositories and 1,000,000 references across the request are accepted. +An invalid or repeated `id`, a missing `references`, an unknown `kind`, a +`shortName` or `fullName` that is empty, holds NUL, or is longer than 4,096 +bytes, a `fullName` that is not `shortName` under its kind's namespace +(`refs/heads/`, `refs/remotes/`, `refs/tags/`), a `fullName` listed twice in one +repository, an empty or NUL-containing `upstreamShortName`, more than one +current reference or a current one that is not a local branch, or an unknown +field outside the entries fails with `invalid_request`. See +`rust/fixtures/git/workspace-common-references-v1.json`. + +`git.workspaceBranchPlan` is pure and plans an action chosen on a common branch +across every repository, as IDEA's `GitBranchOperation` runs it. It accepts +`{ operation, reference, name?, checkout?, repositories }`: `operation` is +`checkout` or `createBranch`, `reference` the `fullName` of the common local or +remote branch, `name` the new branch's name for `createBranch` as +`git.branchNamePreview` cleaned it, `checkout` (default `false`) whether +`createBranch` switches to the new branch, and `repositories` the entries +`git.workspaceCommonReferences` takes, in the order the action runs. The +response is `{ steps, skipped }`. Each step is `{ repository, reference, +rollback }`: `repository` is the ID, `reference` that repository's +`{ fullName, shortName, kind }` of the common branch, which is the +`gitReference` of the step's `git.write` (`checkout`, or `createBranch` with +`name` and `checkout`). Hosts run the steps in order and stop at the first +that fails. To undo the steps that already ran, as IDEA offers after a partial +failure, they run each step's `rollback`, the last step first, the actions of one +rollback in order; each action is `{ operation, reference }` with `operation` +`checkout` or `deleteBranch`, the `git.write` operation to run with that +`gitReference`. A checkout lists in `skipped` the repositories already on the +local branch and plans no step for them; undoing it checks the previous local +branch out again, and undoing a remote branch checkout keeps the local branch it +created or moved, because the plan does not read the remotes that name it. +Undoing a new branch checks the previous branch out again when `checkout` is set, +then deletes the new branch. `rollback` is `null` when the repository's HEAD was +detached or unborn before a step that switches it, so nothing returns it. The +`repositories` validation of `git.workspaceCommonReferences` applies; an empty +list, a `reference` that one repository lacks or that is a tag, a `createBranch` +without a non-empty, NUL-free `name` of at most 4,096 bytes or whose +`refs/heads/` 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 8a243b99..44b9d8a6 100644 --- a/rust/crates/core/src/protocol/command.rs +++ b/rust/crates/core/src/protocol/command.rs @@ -877,6 +877,11 @@ pub enum GitCommand { WorkspaceChangeGroups, /// Interleaves the loaded histories of workspace repositories (`git.workspaceHistoryMerge`). WorkspaceHistoryMerge, + /// Finds the branches every workspace repository has (`git.workspaceCommonReferences`). + WorkspaceCommonReferences, + /// Plans a branch action on a common branch across workspace repositories + /// (`git.workspaceBranchPlan`). + WorkspaceBranchPlan, /// Plans a branch Update or Pull from collected facts (`git.updatePlan`). UpdatePlan, /// Plans history refresh windows, page merges, and selection retention (`git.historyWindow`). @@ -1526,6 +1531,10 @@ impl CoreCommand { } "git.workspaceChangeGroups" => Some(Self::Git(GitCommand::WorkspaceChangeGroups)), "git.workspaceHistoryMerge" => Some(Self::Git(GitCommand::WorkspaceHistoryMerge)), + "git.workspaceCommonReferences" => { + Some(Self::Git(GitCommand::WorkspaceCommonReferences)) + } + "git.workspaceBranchPlan" => Some(Self::Git(GitCommand::WorkspaceBranchPlan)), "git.updatePlan" => Some(Self::Git(GitCommand::UpdatePlan)), "git.historyWindow" => Some(Self::Git(GitCommand::HistoryWindow)), "git.graphProjection" => Some(Self::Git(GitCommand::GraphProjection)), diff --git a/rust/crates/core/src/runtime/dispatcher/git.rs b/rust/crates/core/src/runtime/dispatcher/git.rs index 27be3dc8..2ca1a667 100644 --- a/rust/crates/core/src/runtime/dispatcher/git.rs +++ b/rust/crates/core/src/runtime/dispatcher/git.rs @@ -449,6 +449,12 @@ 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::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 36e286a4..44245f5e 100644 --- a/rust/crates/core/src/tests/git_workspace_repositories.rs +++ b/rust/crates/core/src/tests/git_workspace_repositories.rs @@ -76,6 +76,14 @@ fn selection_change_groups_and_history_merge_match_their_shared_fixtures() { "git.workspaceHistoryMerge", include_str!("../../../../fixtures/git/workspace-history-merge-v1.json"), ); + check_fixture( + "git.workspaceCommonReferences", + include_str!("../../../../fixtures/git/workspace-common-references-v1.json"), + ); + check_fixture( + "git.workspaceBranchPlan", + include_str!("../../../../fixtures/git/workspace-branch-plan-v1.json"), + ); } /// Discovery entries with the status each repository reports, as hosts send them. @@ -239,3 +247,110 @@ fn history_pages_pass_through_to_the_history_merge() { assert_eq!(order, [(0, 0), (1, 0), (0, 1)], "{merged}"); assert_eq!(merged["pending"], json!([]), "{merged}"); } + +/// The `references` of `root`'s `git.references` answer, unchanged, as one repository entry. +fn repository_references(root: &Path, id: &str) -> Value { + let references = data("git.references", json!({"root": root}))["references"].clone(); + json!({"id": id, "references": references}) +} + +/// The branch `root` has checked out. +fn current_branch(root: &Path) -> String { + let result = data( + "git.command", + json!({"root": root, "arguments": ["branch", "--show-current"]}), + ); + result["stdout"].as_str().unwrap().trim().to_owned() +} + +/// Runs one plan `git.write` with the reference the plan names. +fn write(root: &Path, operation: &Value, reference: &Value) { + let result = data( + "git.write", + json!({"root": root, "operation": operation, "gitReference": reference}), + ); + assert_eq!(result["exitCode"], 0, "{operation} {reference}: {result}"); +} + +#[test] +fn references_pass_through_to_common_branches_and_the_branch_plan() { + let folder = Folder(temporary_root("workspace-common-references")); + let backend = folder.0.join("backend"); + let frontend = folder.0.join("frontend"); + for root in [&backend, &frontend] { + init(root); + commit_at(root, "initial", "2026-01-01T10:00:00+00:00"); + git(root, &["branch", "-M", "main"]); + git(root, &["branch", "dev"]); + } + git(&backend, &["branch", "backend-only"]); + git(&backend, &["tag", "v1"]); + git(&frontend, &["switch", "-q", "dev"]); + + let repositories = json!([ + repository_references(&backend, "backend"), + repository_references(&frontend, "frontend") + ]); + let common = data( + "git.workspaceCommonReferences", + json!({"repositories": repositories}), + ); + let names = common["local"] + .as_array() + .unwrap() + .iter() + .map(|reference| reference["shortName"].as_str().unwrap()) + .collect::>(); + 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 058258db..42c47e19 100644 --- a/rust/crates/git/src/graph.rs +++ b/rust/crates/git/src/graph.rs @@ -56,6 +56,13 @@ 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. Combined with + /// `current_branch` the request is invalid. + #[serde(default)] + checked_out_heads: bool, } #[derive(Debug, Clone, Deserialize)] @@ -239,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") @@ -257,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()) @@ -277,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(',') { @@ -286,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/") { @@ -903,7 +925,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| checked_out_branch(value).is_some()) + }); + } else if let Some(branch) = &request.current_branch { projection.current_branch_hashes = current_branch_hashes(request, branch); } projection @@ -1191,24 +1220,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..2e577d0d 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,25 @@ 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, 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, topic"), + ]); + 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..ab91ce8c 100644 --- a/rust/crates/git/src/lib.rs +++ b/rust/crates/git/src/lib.rs @@ -127,7 +127,9 @@ 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, 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..fc32eba4 100644 --- a/rust/crates/git/src/workspace_repositories.rs +++ b/rust/crates/git/src/workspace_repositories.rs @@ -5,17 +5,22 @@ //! 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, 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; 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; pub use selection::command as selection_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 new file mode 100644 index 00000000..66898ca5 --- /dev/null +++ b/rust/crates/git/src/workspace_repositories/common_references.rs @@ -0,0 +1,263 @@ +//! 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 (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. +//! +//! 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; +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::collections::{HashMap, HashSet}; + +/// 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; + +/// 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")] +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)] + pub(super) is_current: bool, + /// The short name of the remote branch a local branch tracks. + #[serde(default)] + pub(super) upstream_short_name: Option, + /// Commits only the local branch has, compared with its upstream. + #[serde(default)] + 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)] +pub(super) struct RepositoryReferences { + /// The repository's `workspace.repositories` ID. + pub(super) id: String, + pub(super) references: Vec, +} + +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 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, +} + +/// A common branch in the shape of a `git.references` entry. +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +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`. +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 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")); + } + 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.references.len()); + if total > max_references { + return Err(invalid("Too many workspace references")); + } + 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 reference + .upstream_short_name + .as_deref() + .is_some_and(|name| !valid_name(name)) + { + return Err(invalid("Invalid upstream 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(()) +} + +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; + }; + // Each other repository's references by full name. + let others: Vec> = rest + .iter() + .map(|repository| { + repository + .references + .iter() + .map(|reference| (reference.full_name.as_str(), reference)) + .collect() + }) + .collect(); + 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; + } + 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 3c58f52b..b607d998 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::{ + 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}; @@ -31,6 +34,22 @@ 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 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( @@ -132,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 new file mode 100644 index 00000000..071841f4 --- /dev/null +++ b/rust/fixtures/git/workspace-common-references-v1.json @@ -0,0 +1,301 @@ +{ + "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. 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", + "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": { + "local": [ + {"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": [ + {"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": "differentCheckoutsHaveNoCurrentCommonBranch", + "request": { + "repositories": [ + { + "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": { + "local": [ + {"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": [] + } + }, + { + "name": "anUpstreamOneRepositoryLacksOrTracksElsewhereIsNotCommon", + "request": { + "repositories": [ + { + "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": { + "local": [ + {"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": "oneRepositoryListsItsOwnBranchesAndIgnoresFieldsCoreDoesNotRead", + "request": { + "repositories": [ + { + "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": { + "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": "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": "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/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "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}] + } + ] + } + } + ] +}