Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/cmds/git/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,8 @@ fn run_log(
arg.starts_with("--oneline") || arg.starts_with("--pretty") || arg.starts_with("--format")
});

// Check if user provided limit flag (-N, -n N, --max-count=N, --max-count N)
let has_limit_flag = args.iter().any(|arg| {
(arg.starts_with('-') && arg.chars().nth(1).is_some_and(|c| c.is_ascii_digit()))
|| arg == "-n"
|| arg.starts_with("--max-count")
});
// Check if user provided limit flag (-N, -nN, -n N, --max-count=N, --max-count N)
let has_limit_flag = args.iter().any(|arg| is_log_limit_arg(arg));

// Apply RTK defaults only if user didn't specify them
// Use %b (body) to preserve first line of commit body for agent context
Expand Down Expand Up @@ -507,7 +503,7 @@ fn run_log(

/// Filter git log output: truncate long messages, cap lines
/// Parse the user-specified limit from git log args.
/// Handles: -20, -n 20, --max-count=20, --max-count 20
/// Handles: -20, -n20, -n 20, --max-count=20, --max-count 20
fn parse_user_limit(args: &[String]) -> Option<usize> {
let mut iter = args.iter();
while let Some(arg) = iter.next() {
Expand All @@ -520,6 +516,14 @@ fn parse_user_limit(args: &[String]) -> Option<usize> {
return Some(n);
}
}
// -n20 (combined short option form)
if let Some(rest) = arg.strip_prefix("-n") {
if !rest.is_empty() {
if let Ok(n) = rest.parse::<usize>() {
return Some(n);
}
}
}
// -n 20 (two-token form)
if arg == "-n" {
if let Some(next) = iter.next() {
Expand All @@ -546,6 +550,15 @@ fn parse_user_limit(args: &[String]) -> Option<usize> {
None
}

fn is_log_limit_arg(arg: &str) -> bool {
(arg.starts_with('-') && arg.chars().nth(1).is_some_and(|c| c.is_ascii_digit()))
|| arg == "-n"
|| arg.strip_prefix("-n").is_some_and(|rest| {
!rest.is_empty() && rest.chars().all(|c| c.is_ascii_digit())
})
|| arg.starts_with("--max-count")
}

/// When `user_set_limit` is true, the user explicitly passed `-N` to git log,
/// so we skip line capping (git already returns exactly N commits) and use a
/// wider truncation threshold (120 chars) to preserve commit context that LLMs
Expand Down Expand Up @@ -2354,6 +2367,12 @@ A added.rs
assert_eq!(parse_user_limit(&args), Some(20));
}

#[test]
fn test_parse_user_limit_n_combined() {
let args: Vec<String> = vec!["-n20".into()];
assert_eq!(parse_user_limit(&args), Some(20));
}

#[test]
fn test_parse_user_limit_n_space() {
let args: Vec<String> = vec!["-n".into(), "15".into()];
Expand Down