-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dirty repository check with --allow-dirty flag (#243)
This pull request includes changes to ensure that Kwaak does not start the TUI or run the agent if the current directory contains uncommitted changes ("dirty" state), unless overridden with the `--allow-dirty` flag. - Added `--allow-dirty` flag for command-line parsing in `src/cli.rs`. - Implemented logic in `src/main.rs` to check for a dirty git directory and prevent command execution unless `--allow-dirty` is specified. - Adjusted test cases in `tests/cli_init.rs` to commit changes or incorporate the `--allow-dirty` flag where appropriate. - All existing and new tests are passing. Fixes #167 --- _This pull request was created by [kwaak](https://github.com/bosun-ai/kwaak), a free, open-source, autonomous coding agent tool. Pull requests are tracked in bosun-ai/kwaak#48_ --------- Co-authored-by: kwaak <[email protected]>
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ use predicates::prelude::*; | |
use rexpect::{process::wait::WaitStatus, spawn}; | ||
use std::process::Command; | ||
use tempfile::TempDir; | ||
|
||
struct Context { | ||
dir: TempDir, | ||
} | ||
|
@@ -60,6 +61,41 @@ impl Context { | |
|
||
self | ||
} | ||
|
||
fn commit_changes(self) -> Self { | ||
// set the git author | ||
let user_email = std::process::Command::new("git") | ||
.arg("config") | ||
.arg("user.email") | ||
.arg("\"[email protected]\"") | ||
.current_dir(&self.dir) | ||
.output() | ||
.unwrap(); | ||
|
||
assert!(user_email.status.success(), "failed to set git user email"); | ||
|
||
let user_name = std::process::Command::new("git") | ||
.arg("config") | ||
.arg("user.name") | ||
.arg("\"kwaak\"") | ||
.current_dir(&self.dir) | ||
.output() | ||
.unwrap(); | ||
|
||
assert!(user_name.status.success(), "failed to set git user name"); | ||
Command::new("git") | ||
.args(["add", "."]) | ||
.current_dir(&self.dir) | ||
.assert() | ||
.success(); | ||
Command::new("git") | ||
.args(["commit", "-m", "Test commit"]) | ||
.current_dir(&self.dir) | ||
.assert() | ||
.success(); | ||
|
||
self | ||
} | ||
} | ||
|
||
#[test_log::test(tokio::test)] | ||
|
@@ -113,14 +149,14 @@ async fn test_fails_config_present() { | |
|
||
#[test_log::test(tokio::test)] | ||
async fn test_print_config() { | ||
let mut context = setup().with_git().with_config(); | ||
let mut context = setup().with_git().with_config().commit_changes(); | ||
|
||
context.cmd().arg("print-config").assert().success(); | ||
} | ||
|
||
#[test_log::test(tokio::test)] | ||
async fn test_self_fixing_after_clear_cache() { | ||
let mut context = setup().with_git().with_config(); | ||
let mut context = setup().with_git().with_config().commit_changes(); | ||
|
||
context.cmd().arg("clear-cache").assert().success(); | ||
context.cmd().arg("print-config").assert().success(); | ||
|