-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git: add test to diagnose worktree gitfiles on windows
We're getting paths like this, I think. But I don't know what git does, and I don't have access to a windows machine. gitdir: \\?\C:\Users\runneradmin\AppData\Local\Temp\jj-test-fy26a2\second
- Loading branch information
1 parent
3e07532
commit 6d92f97
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ use jj_lib::object_id::ObjectId; | |
use jj_lib::op_store::RefTarget; | ||
use jj_lib::op_store::ViewId; | ||
|
||
use crate::common::get_stdout_string; | ||
use crate::common::TestEnvironment; | ||
|
||
#[test] | ||
|
@@ -1325,3 +1326,67 @@ fn test_colocated_view_proto_deprecated() { | |
~ | ||
"#); | ||
} | ||
|
||
#[test] | ||
fn test_worktrees_match_git_behaviour() { | ||
// TODO: Better way to disable the test if git command couldn't be executed | ||
if Command::new("git").arg("--version").status().is_err() { | ||
eprintln!("Skipping because git command might fail to run"); | ||
return; | ||
} | ||
|
||
let test_env = TestEnvironment::default(); | ||
let repo_path = test_env.env_root().join("repo"); | ||
let abc_path = test_env.env_root().join("abc"); | ||
|
||
let git_cmd_success = |test_env: &TestEnvironment, path: &Path, args: &[&str]| -> String { | ||
let cmd = Command::new("git") | ||
.args(args) | ||
.current_dir(path) | ||
.env("GIT_AUTHOR_NAME", "JJ Test Suite") | ||
.env("GIT_AUTHOR_EMAIL", "[email protected]") | ||
.env("GIT_AUTHOR_DATE", "2005-04-07T22:13:13Z") | ||
.env("GIT_COMMITTER_NAME", "JJ Test Suite") | ||
.env("GIT_COMMITTER_EMAIL", "[email protected]") | ||
.env("GIT_COMMITTER_DATE", "2005-04-07T22:13:13Z") | ||
.assert() | ||
.success(); | ||
let stdout = get_stdout_string(&cmd); | ||
test_env.normalize_output(&stdout) | ||
}; | ||
|
||
let read_worktree_setup = || { | ||
let gitfile = std::fs::read_to_string(abc_path.join(".git")).unwrap(); | ||
let worktree_path = repo_path.join(".git").join("worktrees").join("abc"); | ||
let gitdir = std::fs::read_to_string(worktree_path.join("gitdir")).unwrap(); | ||
let commondir = std::fs::read_to_string(worktree_path.join("commondir")).unwrap(); | ||
eprintln!(" abc/.git -> {gitfile}"); | ||
eprintln!(" repo/.git/worktrees/abc/gitdir: {gitdir}"); | ||
eprintln!(" repo/.git/worktrees/abc/commondir: {commondir}"); | ||
(gitfile, gitdir, commondir) | ||
}; | ||
|
||
git_cmd_success(&test_env, test_env.env_root(), &["init", "repo"]); | ||
std::fs::write(repo_path.join("file.txt"), "contents").unwrap(); | ||
git_cmd_success(&test_env, &repo_path, &["add", "file.txt"]); | ||
git_cmd_success(&test_env, &repo_path, &["commit", "-m", "initial commit"]); | ||
git_cmd_success(&test_env, &repo_path, &["worktree", "add", "../abc"]); | ||
|
||
eprintln!("git:"); | ||
let (git_gitfile, git_gitdir, git_commondir) = read_worktree_setup(); | ||
|
||
std::fs::remove_dir_all(&repo_path).unwrap(); | ||
std::fs::remove_dir_all(&abc_path).unwrap(); | ||
|
||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "--colocate", "repo"]); | ||
std::fs::write(repo_path.join("file.txt"), "contents").unwrap(); | ||
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "initial commit"]); | ||
test_env.jj_cmd_ok(&repo_path, &["workspace", "add", "--colocate", "../abc"]); | ||
|
||
eprintln!("jj:"); | ||
let (jj_gitfile, jj_gitdir, jj_commondir) = read_worktree_setup(); | ||
|
||
assert_eq!(jj_gitfile, git_gitfile); | ||
assert_eq!(jj_gitdir, git_gitdir); | ||
assert_eq!(jj_commondir, git_commondir); | ||
} |