pub fn checkout_port(root: &Path) -> u16Expand description
The port this checkout’s server asks for first, the same on every start (I2702).
The primary checkout asks for DEFAULT_PORT. A linked worktree asks for a port derived
from its own identity (crate::repository::identity) within the block above it, so
that two checkouts of one repository ask for different ports and neither depends on which
started first. A port that is taken is still replaced by a free one and both are logged
(http::server::bind_or_fallback); the derivation decides what is asked, not what is had.
A checkout git cannot describe is treated as primary.
use majordomus_cli::cli::{checkout_port, linked_port, DEFAULT_PORT};
let dir = tempfile::tempdir().unwrap();
// not a git checkout at all: the documented default
assert_eq!(checkout_port(dir.path()), DEFAULT_PORT);
// a linked worktree's port is a function of its identity alone
let a = linked_port("0123456789abcdef0123456789abcdef");
assert_eq!(a, linked_port("0123456789abcdef0123456789abcdef"));
assert_ne!(a, linked_port("fedcba9876543210fedcba9876543210"));
assert!(a > DEFAULT_PORT && a < DEFAULT_PORT + 1000);