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 --new @`, describing the current revision and creating a new revision after it. Passing several revisions to `jj-cz` with the `--new` flag will result in an error.
This commit is contained in:
@@ -263,6 +263,33 @@ impl JjExecutor for JjLib {
|
||||
})?;
|
||||
Ok(commit.description().trim_end().to_string())
|
||||
}
|
||||
|
||||
async fn new_revision(&self, revset: &str) -> Result<(), Error> {
|
||||
let commit_id = self.get_commit_id(revset).await?;
|
||||
let repo = self.repo.lock()?.clone();
|
||||
let mut tx = repo.start_transaction();
|
||||
let parent_commit =
|
||||
tx.repo()
|
||||
.store()
|
||||
.get_commit(&commit_id)
|
||||
.map_err(|e| Error::JjOperation {
|
||||
context: e.to_string(),
|
||||
})?;
|
||||
tx.repo_mut()
|
||||
.check_out(self.workspace_name.clone(), &parent_commit)
|
||||
.await
|
||||
.map_err(|e| Error::JjOperation {
|
||||
context: e.to_string(),
|
||||
})?;
|
||||
let new_repo =
|
||||
tx.commit("jj-cz: create new revision")
|
||||
.await
|
||||
.map_err(|e| Error::JjOperation {
|
||||
context: e.to_string(),
|
||||
})?;
|
||||
*self.repo.lock()? = new_repo;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user