F1: remote checkout without a remote, git.lastMessage, shared git status store

- vcs: checking out a remote-tracking branch reads remote.<name>.fetch;
  without a matching refspec it creates the local branch with --no-track
  instead of leaving a dirty tree after git fails to set up tracking.
- vcs + engine: git.lastMessage returns HEAD's full message (null before
  the first commit); the Changes window prefills Amend with it.
- ui: stores/vcsStatus.ts is the only git.status caller; the Changes
  window, tree/tab colours and the branch item read its snapshot, so a
  gitChanged costs one status query. RepoSummary carries upstream,
  ahead and behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-27 17:16:53 +01:00
parent d567f3957d
commit 4bdfe521f2
14 changed files with 649 additions and 314 deletions

View file

@ -1,6 +1,6 @@
//! Git commands (M4.1, owner decision D20): status, stage, unstage, commit,
//! file contents at HEAD or in the index, branches, checkout and branch
//! creation, through the user's installed git (`lutra-vcs`).
//! the last commit message, file contents at HEAD or in the index,
//! branches, checkout and branch creation, through the user's installed git (`lutra-vcs`).
//!
//! **Off the lock.** git can take seconds (a big status, a commit hook), so
//! every command returns a pending outcome ([`crate::Pending`]): under the
@ -60,6 +60,7 @@ pub fn register(registry: &mut Registry) -> Result<(), EngineError> {
registry.register(Box::new(Stage))?;
registry.register(Box::new(Unstage))?;
registry.register(Box::new(Commit))?;
registry.register(Box::new(LastMessage))?;
registry.register(Box::new(Show))?;
registry.register(Box::new(BranchesCommand))?;
registry.register(Box::new(Checkout))?;
@ -188,6 +189,8 @@ enum Op {
/// Amend the last commit.
amend: bool,
},
/// `git.lastMessage`.
LastMessage,
/// `git.show`.
Show(String, Rev),
/// `git.branches`.
@ -208,7 +211,10 @@ enum Op {
impl Op {
/// Whether the call changes the repository (and sends `gitChanged`).
fn mutates(&self) -> bool {
!matches!(self, Self::Status | Self::Show(..) | Self::Branches)
!matches!(
self,
Self::Status | Self::LastMessage | Self::Show(..) | Self::Branches
)
}
}
@ -406,6 +412,7 @@ fn run_op(repo: &Repo, op: &Op) -> Result<Value, VcsError> {
let info = repo.commit(message, *amend)?;
Ok(json!({"commit": info.commit, "summary": info.summary}))
}
Op::LastMessage => Ok(json!({"message": repo.last_message()?})),
Op::Show(path, rev) => {
let contents = repo.show(path, *rev)?;
Ok(json!({
@ -714,6 +721,31 @@ impl Command for Commit {
}
}
/// `git.lastMessage`.
struct LastMessage;
impl Command for LastMessage {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "git.lastMessage",
label: "Git: Last Commit Message",
menu_path: None,
default_shortcut: None,
params: "none; returns { message: string | null }: the full message of HEAD (trailing line breaks removed), null before the first commit; for prefilling an amend",
}
}
fn enabled(&self, state: &State) -> bool {
state.has_project()
}
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let _: serde_json::Map<String, Value> = parse(command, params)?;
start(state, command, Op::LastMessage)
}
}
/// Which version `git.show` returns.
#[derive(Debug, Clone, Copy, Deserialize)]
enum RefParam {