Skip to content

Commit e2a72c7

Browse files
authored
Merge pull request #152 from acunniffe/feat/mockai-pathspecs
mock_ai pathspecs
2 parents 1c5726c + 911f339 commit e2a72c7

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git-ai"
3-
version = "1.0.6"
3+
version = "1.0.7"
44
edition = "2024"
55

66

src/commands/git_ai_handlers.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn print_help() {
7979
);
8080
eprintln!(" --show-working-log Display current working log");
8181
eprintln!(" --reset Reset working log");
82+
eprintln!(" mock_ai [pathspecs...] Test preset accepting optional file pathspecs");
8283
eprintln!(" blame <file> Git blame with AI authorship overlay");
8384
eprintln!(" stats [commit] Show AI authorship statistics for a commit");
8485
eprintln!(" --json Output in JSON format");
@@ -222,6 +223,21 @@ fn handle_checkpoint(args: &[String]) {
222223
.map(|d| d.as_nanos())
223224
.unwrap_or_else(|_| 0)
224225
);
226+
227+
// Collect all remaining args (after mock_ai and flags) as pathspecs
228+
let edited_filepaths = if args.len() > 1 {
229+
let mut paths = Vec::new();
230+
for arg in &args[1..] {
231+
// Skip flags
232+
if !arg.starts_with("--") {
233+
paths.push(arg.clone());
234+
}
235+
}
236+
if paths.is_empty() { None } else { Some(paths) }
237+
} else {
238+
None
239+
};
240+
225241
agent_run_result = Some(AgentRunResult {
226242
agent_id: AgentId {
227243
tool: "mock_ai".to_string(),
@@ -231,7 +247,7 @@ fn handle_checkpoint(args: &[String]) {
231247
checkpoint_kind: CheckpointKind::AiAgent,
232248
transcript: None,
233249
repo_working_dir: None,
234-
edited_filepaths: None,
250+
edited_filepaths,
235251
will_edit_filepaths: None,
236252
});
237253
}

tests/simple_additions.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,40 @@ fn test_new_file_partial_staging_two_commits() {
539539
"Pluto (dwarf)".ai(),
540540
]);
541541
}
542+
543+
#[test]
544+
fn test_mock_ai_with_pathspecs() {
545+
let repo = TestRepo::new();
546+
let mut file1 = repo.filename("file1.txt");
547+
let mut file2 = repo.filename("file2.txt");
548+
549+
// Create initial state
550+
file1.set_contents(lines!["File1 Line 1", "File1 Line 2"]);
551+
file2.set_contents(lines!["File2 Line 1", "File2 Line 2"]);
552+
repo.stage_all_and_commit("Initial commit").unwrap();
553+
554+
// Make changes to both files
555+
file1.insert_at(2, lines!["File1 AI Line".ai()]);
556+
file2.insert_at(2, lines!["File2 Human Line"]);
557+
558+
// Use mock_ai with pathspec to only checkpoint file1.txt
559+
repo.git_ai(&["checkpoint", "mock_ai", "file1.txt"])
560+
.unwrap();
561+
562+
// Commit the changes
563+
repo.stage_all_and_commit("Second commit").unwrap();
564+
565+
// file1 should have AI attribution for the new line
566+
file1.assert_lines_and_blame(lines![
567+
"File1 Line 1".human(),
568+
"File1 Line 2".human(),
569+
"File1 AI Line".ai(),
570+
]);
571+
572+
// file2 should be all human since we didn't checkpoint it with mock_ai
573+
file2.assert_lines_and_blame(lines![
574+
"File2 Line 1".human(),
575+
"File2 Line 2".human(),
576+
"File2 Human Line".human(),
577+
]);
578+
}

0 commit comments

Comments
 (0)