Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_git_colocated.rs: add a squash_push_undo test
Browse files Browse the repository at this point in the history
At this point, it works more or less correctly. However, in the next
commit adding another `jj push` breaks this test.
ilyagr committed Apr 6, 2023
1 parent 503baea commit 90890cc
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/test_git_colocated.rs
Original file line number Diff line number Diff line change
@@ -297,6 +297,62 @@ fn test_git_colocated_squash_undo() {
"###);
}

// This test is just like the above test but with a `jj git push` inserted
#[test]
fn test_git_colocated_squash_push_undo() {
let test_env = TestEnvironment::default();
let source_path = test_env.env_root().join("source");
git2::Repository::init_bare(&source_path).unwrap();
let repo_path = test_env.env_root().join("repo");
git2::Repository::clone(&source_path.as_os_str().to_string_lossy(), &repo_path).unwrap();
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_success(&repo_path, &["ci", "-m=A"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m=B"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "master"]);
// Test the setup
insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###"
@ rlvkpnrzqnoo 2a3078eda7fe B master
◉ qpvuntsmwlqt a86754f975f9 A
◉ zzzzzzzzzzzz 000000000000
"###);

test_env.jj_cmd_success(&repo_path, &["squash", "-m=A+B"]);
insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###"
@ royxmykxtrkr 83c0d8df2b78
◉ qpvuntsmwlqt 1873a0811bf5 A+B master
◉ zzzzzzzzzzzz 000000000000
"###);
test_env.jj_cmd_success(&repo_path, &["git", "push", "--all"]);
insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###"
@ royxmykxtrkr 83c0d8df2b78
◉ qpvuntsmwlqt 1873a0811bf5 A+B master
◉ zzzzzzzzzzzz 000000000000
"###);
let stdout = get_truncated_op_log(&test_env, &repo_path, 9);
insta::assert_snapshot!(stdout, @r###"
@ 92f3965076e7 test-username@host.example.com 22 years ago, lasted less than a microsecond
│ push all branches to git remote origin
│ args: jj git push --all
◉ 34f35f48e4eb test-username@host.example.com 22 years ago, lasted less than a microsecond
│ squash commit 2a3078eda7fe17eeb3cd3e390f7476dff078e35f
│ args: jj squash '-m=A+B'
◉ dfdfe3eb8a2c test-username@host.example.com 22 years ago, lasted less than a microsecond
│ point branch master to commit 2a3078eda7fe17eeb3cd3e390f7476dff078e35f
│ args: jj branch set master
"###);
// Restore to before the squash
test_env.jj_cmd_success(&repo_path, &["op", "restore", "@--"]);
// We expect `master` to be back at B while master@origin is at A+B. Here,
// master ends up conflicted. This is arguably wrong, but not too bad.
insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###"
◉ qpvuntsmwlqt 1873a0811bf5 A+B master?? master@origin !divergence!
│ @ rlvkpnrzqnoo 2a3078eda7fe B master??
│ ◉ qpvuntsmwlqt a86754f975f9 A !divergence!
├─╯
◉ zzzzzzzzzzzz 000000000000
"###);
}

fn get_truncated_op_log(test_env: &TestEnvironment, repo_path: &Path, lines: usize) -> String {
let result = test_env.jj_cmd_success(repo_path, &["op", "log"]);
result.lines().take(lines).join("\n")

0 comments on commit 90890cc

Please sign in to comment.