-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: when initializing repo backed by Git repo, check out Git's HEAD
Closes #102.
- Loading branch information
1 parent
f0ee74d
commit 003c489
Showing
2 changed files
with
48 additions
and
3 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
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 |
---|---|---|
|
@@ -43,7 +43,31 @@ fn test_init_git_internal() { | |
fn test_init_git_external() { | ||
let test_env = TestEnvironment::default(); | ||
let git_repo_path = test_env.env_root().join("git-repo"); | ||
git2::Repository::init(&git_repo_path).unwrap(); | ||
let git_repo = git2::Repository::init(&git_repo_path).unwrap(); | ||
let git_blob_oid = git_repo.blob(b"some content").unwrap(); | ||
let mut git_tree_builder = git_repo.treebuilder(None).unwrap(); | ||
git_tree_builder | ||
.insert("some-file", git_blob_oid, 0o100644) | ||
.unwrap(); | ||
let git_tree_id = git_tree_builder.write().unwrap(); | ||
let git_tree = git_repo.find_tree(git_tree_id).unwrap(); | ||
let git_signature = git2::Signature::new( | ||
"Git User", | ||
"[email protected]", | ||
&git2::Time::new(123, 60), | ||
) | ||
.unwrap(); | ||
git_repo | ||
.commit( | ||
Some("refs/heads/my-branch"), | ||
&git_signature, | ||
&git_signature, | ||
"My commit message", | ||
&git_tree, | ||
&[], | ||
) | ||
.unwrap(); | ||
git_repo.set_head("refs/heads/my-branch").unwrap(); | ||
|
||
let assert = test_env | ||
.jj_cmd( | ||
|
@@ -57,8 +81,11 @@ fn test_init_git_external() { | |
) | ||
.assert() | ||
.success(); | ||
insta::assert_snapshot!(get_stdout_string(&assert), @r###"Initialized repo in "repo" | ||
"###); | ||
insta::assert_snapshot!(get_stdout_string(&assert), @r###" | ||
Working copy now at: f6950fc115ae | ||
Added 1 files, modified 0 files, removed 0 files | ||
Initialized repo in "repo" | ||
"###); | ||
|
||
let workspace_root = test_env.env_root().join("repo"); | ||
let jj_path = workspace_root.join(".jj"); | ||
|
@@ -73,6 +100,16 @@ fn test_init_git_external() { | |
assert!(git_target_file_contents | ||
.replace('\\', "/") | ||
.ends_with("/git-repo/.git")); | ||
|
||
// Check that the Git repo's HEAD got checked out | ||
let assert = test_env | ||
.jj_cmd(&repo_path, &["log", "-r", "@-"]) | ||
.assert() | ||
.success(); | ||
insta::assert_snapshot!(get_stdout_string(&assert), @r###" | ||
o 8d698d4a8ee1 d3866db7e30a [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git | ||
~ My commit message | ||
"###); | ||
} | ||
|
||
#[test] | ||
|