feat: implement --new flag
The new `--new` or `-n` flag allows to create a new revision after the single revision being described. Running `jj-cz --new` is the equivalent of running `jj-cz @ && jj new`. Running `jj-cz --new xs` is the equivalent of running `jj-cz xs && jj new xs`. Passing several revisions to `jj-cz` with the `--new` flag will result in an error. Refs: #6
This commit is contained in:
@@ -184,6 +184,10 @@ impl<J: JjExecutor, P: Prompter> CommitWorkflow<J, P> {
|
||||
Err(Error::Cancelled)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn new_revision(&self, revset: &str) -> Result<(), Error> {
|
||||
self.executor.new_revision(revset).await
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -762,4 +766,59 @@ mod tests {
|
||||
assert_eq!(messages.len(), 1);
|
||||
assert_eq!(messages[0], "fix: fix crash");
|
||||
}
|
||||
|
||||
/// Test workflow new_revision() records the revset
|
||||
#[tokio::test]
|
||||
async fn workflow_new_revision_records_revset() {
|
||||
let mock_executor = MockJjExecutor::new();
|
||||
let workflow = CommitWorkflow::new(mock_executor);
|
||||
|
||||
let result = workflow.new_revision("@").await;
|
||||
assert!(result.is_ok());
|
||||
|
||||
let calls = workflow.executor.new_revision_calls();
|
||||
assert_eq!(calls, vec!["@"]);
|
||||
}
|
||||
|
||||
/// Test workflow new_revision() propagates executor errors
|
||||
#[tokio::test]
|
||||
async fn workflow_new_revision_propagates_error() {
|
||||
let mock_executor =
|
||||
MockJjExecutor::new().with_new_revision_response(Err(Error::RepositoryLocked));
|
||||
let workflow = CommitWorkflow::new(mock_executor);
|
||||
|
||||
let result = workflow.new_revision("@").await;
|
||||
assert!(result.is_err());
|
||||
assert!(matches!(result.unwrap_err(), Error::RepositoryLocked));
|
||||
}
|
||||
|
||||
/// Test workflow run_for_revset() followed by new_revision() records both
|
||||
///
|
||||
/// This mirrors the actual usage pattern in main.rs.
|
||||
#[tokio::test]
|
||||
async fn workflow_describe_then_new_revision() {
|
||||
let mock_executor = MockJjExecutor::new().with_is_repo_response(Ok(true));
|
||||
let mock_prompts = MockPrompts::new()
|
||||
.with_commit_type(CommitType::Feat)
|
||||
.with_scope(Scope::empty())
|
||||
.with_description(Description::parse("add feature").unwrap())
|
||||
.with_breaking_change(BreakingChange::No)
|
||||
.with_body(Body::default())
|
||||
.with_confirm(true);
|
||||
|
||||
let workflow = CommitWorkflow::with_prompts(mock_executor, mock_prompts);
|
||||
|
||||
workflow.run_for_revset("@").await.expect("describe failed");
|
||||
workflow
|
||||
.new_revision("@")
|
||||
.await
|
||||
.expect("new_revision failed");
|
||||
|
||||
let messages = workflow.executor.describe_messages();
|
||||
assert_eq!(messages.len(), 1);
|
||||
assert!(messages[0].contains("feat:"));
|
||||
|
||||
let calls = workflow.executor.new_revision_calls();
|
||||
assert_eq!(calls, vec!["@"]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user