feat(maestro): GET /api/branches — local branches and worktree occupancy (#55)
This commit is contained in:
@@ -212,6 +212,21 @@ pub struct Project {
|
||||
pub last_command: Option<String>,
|
||||
}
|
||||
|
||||
/// One local branch of a repository for `GET /api/branches` (#55). A client
|
||||
/// disables the entry when `is_head` is set or `worktree` is present — git
|
||||
/// refuses to check the same branch out in two worktrees at once.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BranchInfo {
|
||||
/// Short branch name (`main`, `feature/foo`).
|
||||
pub name: String,
|
||||
/// Whether this branch is the main checkout's current HEAD. The main
|
||||
/// checkout's occupancy reports here rather than through `worktree`.
|
||||
pub is_head: bool,
|
||||
/// Toplevel path of the linked worktree holding this branch, if any.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub worktree: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// Structured failure used everywhere we don't want to leak a string-only error.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ErrorInfo {
|
||||
|
||||
@@ -21,10 +21,12 @@ pub const RECENT_DIRS: &str = "/api/recent-dirs";
|
||||
pub const PROJECTS: &str = "/api/projects";
|
||||
/// `GET` the enclosing repository of a path. Takes a `path` query param.
|
||||
pub const GITROOT: &str = "/api/gitroot";
|
||||
/// `GET` one repository's local branches. Takes a `path` query param.
|
||||
pub const BRANCHES: &str = "/api/branches";
|
||||
/// `WS` catalog snapshot + session deltas.
|
||||
pub const EVENTS: &str = "/api/events";
|
||||
|
||||
/// Name of the query parameter [`DIRS`] and [`GITROOT`] both take.
|
||||
/// Name of the query parameter [`DIRS`], [`GITROOT`], and [`BRANCHES`] take.
|
||||
pub const PATH_QUERY: &str = "path";
|
||||
|
||||
/// `DELETE /api/sessions/:id`.
|
||||
@@ -174,7 +176,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn every_route_sits_under_the_api_prefix() {
|
||||
for path in [SESSIONS, INFO, DIRS, RECENT_DIRS, PROJECTS, GITROOT, EVENTS] {
|
||||
for path in [
|
||||
SESSIONS,
|
||||
INFO,
|
||||
DIRS,
|
||||
RECENT_DIRS,
|
||||
PROJECTS,
|
||||
GITROOT,
|
||||
BRANCHES,
|
||||
EVENTS,
|
||||
] {
|
||||
assert!(path.starts_with(API_PREFIX), "{path} escapes {API_PREFIX}");
|
||||
}
|
||||
assert!(attach(id()).starts_with(API_PREFIX));
|
||||
|
||||
Reference in New Issue
Block a user