Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-ai"
version = "1.0.6"
version = "1.0.7"
edition = "2024"


Expand Down
18 changes: 17 additions & 1 deletion src/commands/git_ai_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn print_help() {
);
eprintln!(" --show-working-log Display current working log");
eprintln!(" --reset Reset working log");
eprintln!(" mock_ai [pathspecs...] Test preset accepting optional file pathspecs");
eprintln!(" blame <file> Git blame with AI authorship overlay");
eprintln!(" stats [commit] Show AI authorship statistics for a commit");
eprintln!(" --json Output in JSON format");
Expand Down Expand Up @@ -222,6 +223,21 @@ fn handle_checkpoint(args: &[String]) {
.map(|d| d.as_nanos())
.unwrap_or_else(|_| 0)
);

// Collect all remaining args (after mock_ai and flags) as pathspecs
let edited_filepaths = if args.len() > 1 {
let mut paths = Vec::new();
for arg in &args[1..] {
// Skip flags
if !arg.starts_with("--") {
paths.push(arg.clone());
}
}
if paths.is_empty() { None } else { Some(paths) }
} else {
None
};

agent_run_result = Some(AgentRunResult {
agent_id: AgentId {
tool: "mock_ai".to_string(),
Expand All @@ -231,7 +247,7 @@ fn handle_checkpoint(args: &[String]) {
checkpoint_kind: CheckpointKind::AiAgent,
transcript: None,
repo_working_dir: None,
edited_filepaths: None,
edited_filepaths,
will_edit_filepaths: None,
});
}
Expand Down
37 changes: 37 additions & 0 deletions tests/simple_additions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,40 @@ fn test_new_file_partial_staging_two_commits() {
"Pluto (dwarf)".ai(),
]);
}

#[test]
fn test_mock_ai_with_pathspecs() {
let repo = TestRepo::new();
let mut file1 = repo.filename("file1.txt");
let mut file2 = repo.filename("file2.txt");

// Create initial state
file1.set_contents(lines!["File1 Line 1", "File1 Line 2"]);
file2.set_contents(lines!["File2 Line 1", "File2 Line 2"]);
repo.stage_all_and_commit("Initial commit").unwrap();

// Make changes to both files
file1.insert_at(2, lines!["File1 AI Line".ai()]);
file2.insert_at(2, lines!["File2 Human Line"]);

// Use mock_ai with pathspec to only checkpoint file1.txt
repo.git_ai(&["checkpoint", "mock_ai", "file1.txt"])
.unwrap();

// Commit the changes
repo.stage_all_and_commit("Second commit").unwrap();

// file1 should have AI attribution for the new line
file1.assert_lines_and_blame(lines![
"File1 Line 1".human(),
"File1 Line 2".human(),
"File1 AI Line".ai(),
]);

// file2 should be all human since we didn't checkpoint it with mock_ai
file2.assert_lines_and_blame(lines![
"File2 Line 1".human(),
"File2 Line 2".human(),
"File2 Human Line".human(),
]);
}
Loading