mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
cli: let the user know if there's been a concurrent modification (#111)
This commit is contained in:
parent
a38dd9d693
commit
749ea62c08
2 changed files with 53 additions and 3 deletions
|
@ -47,7 +47,7 @@ use jujutsu_lib::op_heads_store::OpHeadsStore;
|
|||
use jujutsu_lib::op_store::{OpStore, OpStoreError, OperationId, RefTarget, WorkspaceId};
|
||||
use jujutsu_lib::operation::Operation;
|
||||
use jujutsu_lib::refs::{classify_branch_push_action, BranchPushAction};
|
||||
use jujutsu_lib::repo::{MutableRepo, ReadonlyRepo, RepoRef};
|
||||
use jujutsu_lib::repo::{MutableRepo, ReadonlyRepo, RepoAtHead, RepoRef};
|
||||
use jujutsu_lib::repo_path::RepoPath;
|
||||
use jujutsu_lib::revset::{RevsetError, RevsetExpression, RevsetParseError};
|
||||
use jujutsu_lib::revset_graph_iterator::RevsetGraphEdgeType;
|
||||
|
@ -184,7 +184,7 @@ impl<'help> CommandHelper<'help> {
|
|||
&self.args
|
||||
}
|
||||
|
||||
fn workspace_helper(&self, ui: &Ui) -> Result<WorkspaceCommandHelper, CommandError> {
|
||||
fn workspace_helper(&self, ui: &mut Ui) -> Result<WorkspaceCommandHelper, CommandError> {
|
||||
let wc_path_str = self.args.repository.as_deref().unwrap_or(".");
|
||||
let wc_path = ui.cwd().join(wc_path_str);
|
||||
let workspace = match Workspace::load(ui.settings(), wc_path) {
|
||||
|
@ -211,7 +211,16 @@ jj init --git-repo=.";
|
|||
let repo_loader = workspace.repo_loader();
|
||||
let op_str = &self.args.at_operation;
|
||||
let repo = if op_str == "@" {
|
||||
repo_loader.load_at_head().resolve()
|
||||
match repo_loader.load_at_head() {
|
||||
RepoAtHead::Single(repo) => repo,
|
||||
RepoAtHead::Unresolved(unresolved) => {
|
||||
writeln!(
|
||||
ui,
|
||||
"Concurrent modification detected, resolving automatically.",
|
||||
)?;
|
||||
unresolved.resolve()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let op = resolve_single_op_from_store(
|
||||
repo_loader.op_store(),
|
||||
|
|
41
tests/test_concurrent_operations.rs
Normal file
41
tests/test_concurrent_operations.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use jujutsu::testutils::TestEnvironment;
|
||||
|
||||
#[test]
|
||||
fn test_concurrent_operations() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
|
||||
let op_id_hex = stdout[2..14].to_string();
|
||||
|
||||
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "message 1"]);
|
||||
test_env.jj_cmd_success(
|
||||
&repo_path,
|
||||
&["describe", "-m", "message 2", "--at-op", &op_id_hex],
|
||||
);
|
||||
|
||||
// We should be informed about the concurrent modification
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Concurrent modification detected, resolving automatically.
|
||||
o message 2
|
||||
| @ message 1
|
||||
|/
|
||||
o
|
||||
"###);
|
||||
}
|
Loading…
Reference in a new issue