feat: set message for multiple revsets

Allows to set the revision message of multiple revisions by passing
them as arguments. This only supports simple revisions, such as `@`,
`@-`, `xs`, and so on. Comple revisions such as `@..@-` are not
supported.

Fixes: #5
This commit is contained in:
2026-04-05 23:02:14 +02:00
parent 3da214ae4c
commit c65e493571
16 changed files with 390 additions and 166 deletions

View File

@@ -1,28 +1,13 @@
use assert_fs::TempDir;
#[cfg(feature = "test-utils")]
use jj_cz::{Body, BreakingChange, CommitType, Description, MockPrompts, Scope};
use jj_cz::{Body, BreakingChange, CommitType, Description, MockJjExecutor, MockPrompts, Scope};
use jj_cz::{CommitWorkflow, Error, JjLib};
#[cfg(feature = "test-utils")]
use jj_lib::{config::StackedConfig, settings::UserSettings, workspace::Workspace};
/// Helper to initialize a temporary jj repository using jj-lib directly (no CLI required)
#[cfg(feature = "test-utils")]
async fn init_jj_repo(temp_dir: &TempDir) {
let config = StackedConfig::with_defaults();
let settings = UserSettings::from_config(config).expect("Failed to create settings");
Workspace::init_internal_git(&settings, temp_dir.path())
.await
.expect("Failed to initialize jj repository");
}
#[cfg(feature = "test-utils")]
#[tokio::test]
async fn test_happy_path_integration() {
// T037: Happy path integration test
let temp_dir = TempDir::new().unwrap();
init_jj_repo(&temp_dir).await;
// Create mock prompts that simulate a successful workflow
let mock_executor = MockJjExecutor::new();
let mock_prompts = MockPrompts::new()
.with_commit_type(CommitType::Feat)
.with_scope(Scope::empty())
@@ -31,13 +16,9 @@ async fn test_happy_path_integration() {
.with_body(Body::default())
.with_confirm(true);
// Create a mock executor that tracks calls
let executor = JjLib::with_working_dir(temp_dir.path());
let workflow = CommitWorkflow::with_prompts(executor, mock_prompts);
let workflow = CommitWorkflow::with_prompts(mock_executor, mock_prompts);
let result = workflow.run_for_revset("@").await;
let result = workflow.run().await;
// The workflow should complete successfully
assert!(
result.is_ok(),
"Workflow should complete successfully: {:?}",
@@ -47,17 +28,11 @@ async fn test_happy_path_integration() {
#[tokio::test]
async fn test_not_in_repo() {
// T038: Not-in-repo integration test
// T038: Not-in-repo integration test - with_working_dir itself returns the error
let temp_dir = TempDir::new().unwrap();
// Don't initialize jj repo
// Create executor with the temp directory (which is not a jj repo)
let executor = JjLib::with_working_dir(temp_dir.path());
let workflow = CommitWorkflow::new(executor);
let result = JjLib::with_working_dir(temp_dir.path()).await;
let result = workflow.run().await;
// Should fail with NotARepository error
assert!(matches!(result, Err(Error::NotARepository)));
}
@@ -77,9 +52,13 @@ async fn test_cancellation() {
Ok(true)
}
async fn describe(&self, _message: &str) -> Result<(), Error> {
async fn describe(&self, _revset: &str, _message: &str) -> Result<(), Error> {
Err(Error::Cancelled)
}
async fn get_description(&self, _revset: &str) -> Result<String, Error> {
Ok(String::new())
}
}
let executor = CancelMock;
@@ -92,7 +71,7 @@ async fn test_cancellation() {
.with_confirm(true);
let workflow = CommitWorkflow::with_prompts(executor, mock_prompts);
let result = workflow.run().await;
let result = workflow.run_for_revset("@").await;
// Should fail with Cancelled error
assert!(matches!(result, Err(Error::Cancelled)));