ok/jj
1
0
Fork 0
forked from mirrors/jj
jj/tests/test_git_colocated.rs
Martin von Zweigbergk 034fbb47e3 cli: fix crash when initializing workspace colocated with Git repo
When initializing a workspace that shares its working copy with a Git
repo (i.e. `jj init --git-repo=.`), we import refs and HEAD when
creating the `WorkspaceCommandHelper` (as we do for all commands when
the working copy is shared). That makes the explicit import we do in
`cmd_init()` unnecessary. It also makes the checkout of HEAD I added
for the fix of #102 unnecessary. More importantly, as @yuja reported
in #177, it makes the command crash (at least if the repo is small
enough that the two checkouts happen within a second). I think the
problem is that the second checkout tries to create the same commit
except that the Change ID is different (the problem is not the
predecessors as I speculated in the issue tracker). The fix is to
simply avoid doing the redundant work. We still need a proper fix for
#27 eventually.

Closes #177.
2022-03-30 22:09:55 -07:00

40 lines
1.6 KiB
Rust

// 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_git_colocated() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
let git_repo = git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
// Create a commit from jj and check that it's reflected in git
std::fs::write(workspace_root.join("new-file"), "contents").unwrap();
test_env.jj_cmd_success(&workspace_root, &["close", "-m", "add a file"]);
test_env.jj_cmd_success(&workspace_root, &["git", "import"]);
let stdout =
test_env.jj_cmd_success(&workspace_root, &["log", "-T", "commit_id \" \" branches"]);
insta::assert_snapshot!(stdout, @r###"
@ 2588800a4ee68926773f1e9c44dcc50ada923650
o 172b1cbfe88c97cbd1b1c8a98a48e729a4540e85 master
o 0000000000000000000000000000000000000000
"###);
assert_eq!(
git_repo.head().unwrap().target().unwrap().to_string(),
"172b1cbfe88c97cbd1b1c8a98a48e729a4540e85".to_string()
);
}