forked from mirrors/jj
cli: fix git-colocated working copy on Windows
This patch adds a very simple e2e test of having a working copy shared with Git. The test initially failed on Windows. The symptom was that the "master" branch did not get updated when we create a commit using `jj`. That suggested that we didn't correctly detect that the working copy was shared. After a lot of troubleshooting, I think I mostly understand what we going on here (thanks to @arxanas for suggesting https://github.com/mxschmitt/action-tmate). The path we get from `git2::Repository::workdir()` seems to not be canonicalized in the same way as `std::fs::canonicalize()` canonicalizes. Specifically, it does not have the "\\?\" prefix we get from that function. I suppose that's because libgit2 is a C library and canonicalizes the path using some other system call.
This commit is contained in:
parent
6cd4e03c25
commit
197f669976
3 changed files with 49 additions and 3 deletions
|
@ -41,6 +41,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
* `jj log` now accepts `-p`/`--patch` option.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
* When sharing the working copy with a Git repo, the automatic importing and
|
||||
exporting (sometimes?) didn't happen on Windows.
|
||||
|
||||
## [0.3.3] - 2022-03-16
|
||||
|
||||
No changes, only trying to get the automated build to work.
|
||||
|
|
|
@ -292,9 +292,12 @@ impl WorkspaceCommandHelper {
|
|||
let may_update_working_copy = loaded_at_head && !root_args.no_commit_working_copy;
|
||||
let mut working_copy_shared_with_git = false;
|
||||
let maybe_git_repo = repo.store().git_repo();
|
||||
if let Some(git_repo) = &maybe_git_repo {
|
||||
working_copy_shared_with_git =
|
||||
git_repo.workdir() == Some(workspace.workspace_root().as_path());
|
||||
if let Some(git_workdir) = maybe_git_repo
|
||||
.as_ref()
|
||||
.and_then(|git_repo| git_repo.workdir())
|
||||
.and_then(|workdir| workdir.canonicalize().ok())
|
||||
{
|
||||
working_copy_shared_with_git = git_workdir == workspace.workspace_root().as_path();
|
||||
}
|
||||
let mut helper = Self {
|
||||
string_args,
|
||||
|
|
38
tests/test_git_colocated.rs
Normal file
38
tests/test_git_colocated.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
// 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"]);
|
||||
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()
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue