Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colocated workspaces, minimal #4644

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
54 changes: 54 additions & 0 deletions cli/tests/test_git_colocated.rs
cormacrelf marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// limitations under the License.

use std::path::Path;
use std::process::Command;

use assert_cmd::assert::OutputAssertExt;
use git2::Oid;

use crate::common::TestEnvironment;
Expand Down Expand Up @@ -921,3 +923,55 @@ fn test_git_colocated_create_workspace_moving_wc() {
◆ 0000000000000000000000000000000000000000
");
}

/// Substitute for `jj workspace add --colocate` or similar using git CLI,
/// please replace with the real thing when it lands.
fn stopgap_workspace_colocate(
test_env: &TestEnvironment,
repo_path: &Path,
original_colocated: bool,
dst: &str,
initial_head: &str,
) {
// Can't use gix/git2, as neither can repair the broken worktree we're about to
// create.
let repo_relative_path = if original_colocated {
dst.to_owned()
} else {
format!("../../../../{dst}")
};
Command::new("git")
.args(["worktree", "add", &repo_relative_path])
.arg(initial_head)
.current_dir(if original_colocated {
repo_path.to_path_buf()
} else {
repo_path.join(".jj/repo/store/git")
})
.assert()
.success()
.stderr(format!(
"Preparing worktree (detached HEAD {})\n",
&initial_head[..7]
));
let dst_path = repo_path.join(dst);
let tmp_path = test_env.env_root().join("__tmp_worktree__");
if tmp_path.exists() {
std::fs::remove_dir_all(&tmp_path).unwrap();
Copy link
Contributor

@yuja yuja Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If tmp_path.exists() is expected, it's probably better to create a temporary directory by tempdir_in. If that's unexpected, make it fail.

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Either it is jj or Jujutsu (full name) in the commit message.

std::fs::rename(&dst_path, &tmp_path).unwrap();
test_env.jj_cmd_ok(repo_path, &["workspace", "add", dst]);
std::fs::rename(tmp_path.join(".git"), dst_path.join(".git")).unwrap();
std::fs::write(dst_path.join(".jj/.gitignore"), "*\n").unwrap();
Command::new("git")
.args(["worktree", "repair"])
.current_dir(&dst_path)
.assert()
.success();
Command::new("git")
.arg("checkout")
.arg(initial_head)
.current_dir(&dst_path)
.assert()
.success();
}