-
Notifications
You must be signed in to change notification settings - Fork 363
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. gitdir: \\?\C:\Users\runneradmin\AppData\Local\Temp\jj-test-fy26a2\second But I don't know what git does, and I don't have access to a windows machine. Adding this so the CI windows build can tell us what's wrong.
- Loading branch information
1 parent
40ebf4f
commit fda403e
Showing
1 changed file
with
65 additions
and
14 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 |
---|---|---|
|
@@ -18,6 +18,7 @@ use std::process::Command; | |
use assert_cmd::assert::OutputAssertExt; | ||
use git2::Oid; | ||
|
||
use crate::common::get_stdout_string; | ||
use crate::common::TestEnvironment; | ||
|
||
#[test] | ||
|
@@ -931,20 +932,6 @@ fn test_colocated_workspace_independent_heads() { | |
initial_commit | ||
); | ||
} | ||
|
||
// Now that the functionality is tested, check we wrote a nice .git file | ||
let dot_git = std::fs::read_to_string(second_path.join(".git")).expect("reading .git failed"); | ||
assert_eq!( | ||
dot_git, | ||
format!( | ||
"gitdir: {}\n", | ||
repo_path | ||
.join(".git") | ||
.join("worktrees") | ||
.join("second") | ||
.display() | ||
) | ||
); | ||
} | ||
|
||
#[test] | ||
|
@@ -1105,3 +1092,67 @@ fn test_colocated_workspace_forget_locked() { | |
|
||
let _ = test_env.jj_cmd_ok(&repo_path, &["workspace", "forget", "second"]); | ||
} | ||
|
||
#[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); | ||
} |