mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
cli: don't commit no-op transaction
If nothing changed in a transaction, it's rarely useful to commit it, so let's avoid that. For example, if you run `jj git import` without changing the anything in the Git repo, we now just print "Nothing changed.".
This commit is contained in:
parent
a27e77205a
commit
0c441d9558
3 changed files with 15 additions and 1 deletions
|
@ -456,6 +456,10 @@ impl MutableRepo {
|
||||||
&self.view
|
&self.view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_changes(&self) -> bool {
|
||||||
|
self.view != self.base_repo.view
|
||||||
|
}
|
||||||
|
|
||||||
pub fn consume(self) -> (MutableIndex, View) {
|
pub fn consume(self) -> (MutableIndex, View) {
|
||||||
(self.index, self.view)
|
(self.index, self.view)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ pub enum RefName {
|
||||||
GitRef(String),
|
GitRef(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct View {
|
pub struct View {
|
||||||
data: op_store::View,
|
data: op_store::View,
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,6 +441,11 @@ impl WorkspaceCommandHelper {
|
||||||
|
|
||||||
fn finish_transaction(&mut self, ui: &mut Ui, mut tx: Transaction) -> Result<(), CommandError> {
|
fn finish_transaction(&mut self, ui: &mut Ui, mut tx: Transaction) -> Result<(), CommandError> {
|
||||||
let mut_repo = tx.mut_repo();
|
let mut_repo = tx.mut_repo();
|
||||||
|
if !mut_repo.has_changes() {
|
||||||
|
tx.discard();
|
||||||
|
writeln!(ui, "Nothing changed.")?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
if self.rebase_descendants {
|
if self.rebase_descendants {
|
||||||
let num_rebased = rebase_descendants(ui.settings(), mut_repo);
|
let num_rebased = rebase_descendants(ui.settings(), mut_repo);
|
||||||
if num_rebased > 0 {
|
if num_rebased > 0 {
|
||||||
|
@ -1390,7 +1395,11 @@ fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &ArgMatches) -> Result<(
|
||||||
git::import_refs(tx.mut_repo(), &git_repo).unwrap();
|
git::import_refs(tx.mut_repo(), &git_repo).unwrap();
|
||||||
// TODO: Check out a recent commit. Maybe one with the highest generation
|
// TODO: Check out a recent commit. Maybe one with the highest generation
|
||||||
// number.
|
// number.
|
||||||
workspace_command.finish_transaction(ui, tx)?;
|
if tx.mut_repo().has_changes() {
|
||||||
|
workspace_command.finish_transaction(ui, tx)?;
|
||||||
|
} else {
|
||||||
|
tx.discard();
|
||||||
|
}
|
||||||
} else if args.is_present("git") {
|
} else if args.is_present("git") {
|
||||||
Workspace::init_internal_git(ui.settings(), wc_path.clone())?;
|
Workspace::init_internal_git(ui.settings(), wc_path.clone())?;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue