From 52bb65afc08ee918981c84760b4c85e338d32a69 Mon Sep 17 00:00:00 2001 From: Pardeep Singh Date: Fri, 16 Oct 2026 14:36:32 +0530 Subject: [PATCH] git checkout: suggest commits for the first argument Add the existing commits generator to checkout's first positional argument, alongside branches and tags, as reset, show and cherry-pick already do. Addresses warpdotdev/warp#691. Signed-off-by: Pardeep Singh --- command-signatures/json/git.json | 3 +- command-signatures/src/generators/git.rs | 40 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/command-signatures/json/git.json b/command-signatures/json/git.json index 06b8f122..ff451a18 100644 --- a/command-signatures/json/git.json +++ b/command-signatures/json/git.json @@ -7186,7 +7186,8 @@ "local_branches", "remote_branches", "refs_remote_branches", - "tags" + "tags", + "commits" ], "template": [ "filepaths", diff --git a/command-signatures/src/generators/git.rs b/command-signatures/src/generators/git.rs index c5af4931..4f42e91f 100644 --- a/command-signatures/src/generators/git.rs +++ b/command-signatures/src/generators/git.rs @@ -1621,6 +1621,46 @@ mod tests { ); } + /// `git checkout ` detaches HEAD at a commit, so the first argument must offer + /// commits alongside branches and tags (warpdotdev/warp#691). + #[cfg(feature = "embed-signatures")] + #[test] + fn test_checkout_first_argument_completes_commits() { + use warp_completion_metadata::ArgumentType; + + let git = crate::signature_by_name("git").expect("git signature should be bundled"); + let checkout = git + .subcommands() + .iter() + .find(|subcommand| subcommand.name == "checkout") + .expect("git should have a checkout subcommand"); + let target = checkout + .arguments() + .first() + .expect("git checkout should accept a positional argument"); + + let generator_names: Vec<&str> = target + .argument_types + .iter() + .filter_map(|argument_type| match argument_type { + ArgumentType::Generator(name) => Some(name.0.as_str()), + _ => None, + }) + .collect(); + for expected in [ + "local_branches", + "remote_branches", + "refs_remote_branches", + "tags", + "commits", + ] { + assert!( + generator_names.contains(&expected), + "git checkout's first argument should use the {expected} generator, got {generator_names:?}" + ); + } + } + #[test] fn test_push_refspec_tags_with_colon_prefix() { let command_output = "__REFSPEC_PREFIX__:\nv1.0.0\nv2.0.0";