forked from mirrors/jj
test_git_fetch: move a fetch test from test_git_import_export
This commit is contained in:
parent
08d147be32
commit
ee4f8f2876
2 changed files with 61 additions and 61 deletions
|
@ -890,3 +890,64 @@ fn test_git_fetch_removed_parent_branch() {
|
||||||
◉ 000000000000
|
◉ 000000000000
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_git_fetch_remote_only_branch() {
|
||||||
|
let test_env = TestEnvironment::default();
|
||||||
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||||
|
let repo_path = test_env.env_root().join("repo");
|
||||||
|
|
||||||
|
// Create non-empty git repo to add as a remote
|
||||||
|
let git_repo_path = test_env.env_root().join("git-repo");
|
||||||
|
let git_repo = git2::Repository::init(git_repo_path).unwrap();
|
||||||
|
let signature =
|
||||||
|
git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap();
|
||||||
|
let mut tree_builder = git_repo.treebuilder(None).unwrap();
|
||||||
|
let file_oid = git_repo.blob(b"content").unwrap();
|
||||||
|
tree_builder
|
||||||
|
.insert("file", file_oid, git2::FileMode::Blob.into())
|
||||||
|
.unwrap();
|
||||||
|
let tree_oid = tree_builder.write().unwrap();
|
||||||
|
let tree = git_repo.find_tree(tree_oid).unwrap();
|
||||||
|
test_env.jj_cmd_success(
|
||||||
|
&repo_path,
|
||||||
|
&["git", "remote", "add", "origin", "../git-repo"],
|
||||||
|
);
|
||||||
|
// Create a commit and a branch in the git repo
|
||||||
|
git_repo
|
||||||
|
.commit(
|
||||||
|
Some("refs/heads/feature1"),
|
||||||
|
&signature,
|
||||||
|
&signature,
|
||||||
|
"message",
|
||||||
|
&tree,
|
||||||
|
&[],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Fetch normally
|
||||||
|
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
|
||||||
|
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
|
||||||
|
feature1: 9f01a0e04879 message
|
||||||
|
"###);
|
||||||
|
|
||||||
|
git_repo
|
||||||
|
.commit(
|
||||||
|
Some("refs/heads/feature2"),
|
||||||
|
&signature,
|
||||||
|
&signature,
|
||||||
|
"message",
|
||||||
|
&tree,
|
||||||
|
&[],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Fetch using git.auto_local_branch = false
|
||||||
|
test_env.add_config("git.auto-local-branch = false");
|
||||||
|
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
|
||||||
|
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
|
||||||
|
feature1: 9f01a0e04879 message
|
||||||
|
feature2 (deleted)
|
||||||
|
@origin: 9f01a0e04879 message
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
|
@ -89,67 +89,6 @@ fn test_git_export_conflicting_git_refs() {
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_git_fetch_remote_only_branch() {
|
|
||||||
let test_env = TestEnvironment::default();
|
|
||||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
||||||
let repo_path = test_env.env_root().join("repo");
|
|
||||||
|
|
||||||
// Create non-empty git repo to add as a remote
|
|
||||||
let git_repo_path = test_env.env_root().join("git-repo");
|
|
||||||
let git_repo = git2::Repository::init(git_repo_path).unwrap();
|
|
||||||
let signature =
|
|
||||||
git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap();
|
|
||||||
let mut tree_builder = git_repo.treebuilder(None).unwrap();
|
|
||||||
let file_oid = git_repo.blob(b"content").unwrap();
|
|
||||||
tree_builder
|
|
||||||
.insert("file", file_oid, git2::FileMode::Blob.into())
|
|
||||||
.unwrap();
|
|
||||||
let tree_oid = tree_builder.write().unwrap();
|
|
||||||
let tree = git_repo.find_tree(tree_oid).unwrap();
|
|
||||||
test_env.jj_cmd_success(
|
|
||||||
&repo_path,
|
|
||||||
&["git", "remote", "add", "origin", "../git-repo"],
|
|
||||||
);
|
|
||||||
// Create a commit and a branch in the git repo
|
|
||||||
git_repo
|
|
||||||
.commit(
|
|
||||||
Some("refs/heads/feature1"),
|
|
||||||
&signature,
|
|
||||||
&signature,
|
|
||||||
"message",
|
|
||||||
&tree,
|
|
||||||
&[],
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Fetch normally
|
|
||||||
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
|
|
||||||
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
|
|
||||||
feature1: 9f01a0e04879 message
|
|
||||||
"###);
|
|
||||||
|
|
||||||
git_repo
|
|
||||||
.commit(
|
|
||||||
Some("refs/heads/feature2"),
|
|
||||||
&signature,
|
|
||||||
&signature,
|
|
||||||
"message",
|
|
||||||
&tree,
|
|
||||||
&[],
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Fetch using git.auto_local_branch = false
|
|
||||||
test_env.add_config("git.auto-local-branch = false");
|
|
||||||
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
|
|
||||||
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
|
|
||||||
feature1: 9f01a0e04879 message
|
|
||||||
feature2 (deleted)
|
|
||||||
@origin: 9f01a0e04879 message
|
|
||||||
"###);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_git_export_undo() {
|
fn test_git_export_undo() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
|
Loading…
Reference in a new issue