mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 08:53:16 +00:00
cli: don't commit working copy when using --at-op
The working copy is related to the current repo state; it makes little sense to commit the working copy when looking at an old repo state.
This commit is contained in:
parent
b48e06a94b
commit
b0fe2564d4
1 changed files with 25 additions and 10 deletions
|
@ -175,6 +175,7 @@ struct RepoCommandHelper {
|
||||||
string_args: Vec<String>,
|
string_args: Vec<String>,
|
||||||
settings: UserSettings,
|
settings: UserSettings,
|
||||||
repo: Arc<ReadonlyRepo>,
|
repo: Arc<ReadonlyRepo>,
|
||||||
|
may_update_working_copy: bool,
|
||||||
working_copy_committed: bool,
|
working_copy_committed: bool,
|
||||||
// Whether to evolve orphans when the transaction
|
// Whether to evolve orphans when the transaction
|
||||||
// finishes. This should generally be true for commands that rewrite commits.
|
// finishes. This should generally be true for commands that rewrite commits.
|
||||||
|
@ -191,10 +192,12 @@ impl RepoCommandHelper {
|
||||||
root_matches: &ArgMatches,
|
root_matches: &ArgMatches,
|
||||||
) -> Result<Self, CommandError> {
|
) -> Result<Self, CommandError> {
|
||||||
let repo = get_repo(ui, &root_matches)?;
|
let repo = get_repo(ui, &root_matches)?;
|
||||||
|
let may_update_working_copy = root_matches.value_of("at_op").is_none();
|
||||||
Ok(RepoCommandHelper {
|
Ok(RepoCommandHelper {
|
||||||
string_args,
|
string_args,
|
||||||
settings: ui.settings().clone(),
|
settings: ui.settings().clone(),
|
||||||
repo,
|
repo,
|
||||||
|
may_update_working_copy,
|
||||||
working_copy_committed: false,
|
working_copy_committed: false,
|
||||||
evolve_orphans: true,
|
evolve_orphans: true,
|
||||||
auto_update_checkout: true,
|
auto_update_checkout: true,
|
||||||
|
@ -276,8 +279,7 @@ impl RepoCommandHelper {
|
||||||
_ => true,
|
_ => true,
|
||||||
};
|
};
|
||||||
if mentions_checkout && !self.working_copy_committed {
|
if mentions_checkout && !self.working_copy_committed {
|
||||||
self.working_copy_committed = true;
|
self.maybe_commit_working_copy();
|
||||||
self.commit_working_copy();
|
|
||||||
}
|
}
|
||||||
Ok(expression)
|
Ok(expression)
|
||||||
}
|
}
|
||||||
|
@ -298,12 +300,25 @@ impl RepoCommandHelper {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commit_working_copy(&mut self) {
|
fn commit_working_copy(&mut self) -> Result<(), CommandError> {
|
||||||
|
if !self.may_update_working_copy {
|
||||||
|
return Err(UserError(
|
||||||
|
"Refusing to update working copy (maybe because you're using --at-op)".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
self.maybe_commit_working_copy();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn maybe_commit_working_copy(&mut self) {
|
||||||
|
if self.may_update_working_copy {
|
||||||
let (reloaded_repo, _) = self
|
let (reloaded_repo, _) = self
|
||||||
.repo
|
.repo
|
||||||
.working_copy_locked()
|
.working_copy_locked()
|
||||||
.commit(&self.settings, self.repo.clone());
|
.commit(&self.settings, self.repo.clone());
|
||||||
self.repo = reloaded_repo;
|
self.repo = reloaded_repo;
|
||||||
|
self.working_copy_committed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_transaction(&self, description: &str) -> Transaction {
|
fn start_transaction(&self, description: &str) -> Transaction {
|
||||||
|
@ -851,7 +866,7 @@ fn cmd_checkout(
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let mut repo_command = command.repo_helper(ui)?.auto_update_checkout(false);
|
let mut repo_command = command.repo_helper(ui)?.auto_update_checkout(false);
|
||||||
let new_commit = repo_command.resolve_revision_arg(sub_matches)?;
|
let new_commit = repo_command.resolve_revision_arg(sub_matches)?;
|
||||||
repo_command.commit_working_copy();
|
repo_command.commit_working_copy()?;
|
||||||
let mut tx =
|
let mut tx =
|
||||||
repo_command.start_transaction(&format!("check out commit {}", new_commit.id().hex()));
|
repo_command.start_transaction(&format!("check out commit {}", new_commit.id().hex()));
|
||||||
tx.mut_repo().check_out(ui.settings(), &new_commit);
|
tx.mut_repo().check_out(ui.settings(), &new_commit);
|
||||||
|
@ -1148,7 +1163,7 @@ fn cmd_status(
|
||||||
_sub_matches: &ArgMatches,
|
_sub_matches: &ArgMatches,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let mut repo_command = command.repo_helper(ui)?;
|
let mut repo_command = command.repo_helper(ui)?;
|
||||||
repo_command.commit_working_copy();
|
repo_command.maybe_commit_working_copy();
|
||||||
let repo = repo_command.repo();
|
let repo = repo_command.repo();
|
||||||
let commit = repo.store().get_commit(repo.view().checkout()).unwrap();
|
let commit = repo.store().get_commit(repo.view().checkout()).unwrap();
|
||||||
ui.write("Parent commit: ")?;
|
ui.write("Parent commit: ")?;
|
||||||
|
|
Loading…
Reference in a new issue