diff --git a/CHANGELOG.md b/CHANGELOG.md index d5c2d39a6..5bffba064 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/commands.rs b/src/commands.rs index 24d06a298..39d27560c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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, diff --git a/tests/test_git_colocated.rs b/tests/test_git_colocated.rs new file mode 100644 index 000000000..bffdd09b5 --- /dev/null +++ b/tests/test_git_colocated.rs @@ -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() + ); +}