ok/jj
1
0
Fork 0
forked from mirrors/jj

tests: replace jj_cmd_success() involving mutation to allow stderr output

This commit is contained in:
Yuya Nishihara 2023-10-10 20:59:18 +09:00
parent 98bf0836bf
commit 58acc1d111
51 changed files with 1580 additions and 1278 deletions

View file

@ -20,20 +20,20 @@ pub mod common;
fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, parents: &[&str]) {
if parents.is_empty() {
test_env.jj_cmd_success(repo_path, &["new", "root()", "-m", name]);
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", name]);
} else {
let mut args = vec!["new", "-m", name];
args.extend(parents);
test_env.jj_cmd_success(repo_path, &args);
test_env.jj_cmd_ok(repo_path, &args);
}
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
}
#[test]
fn test_rebase_branch_with_merge() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -54,7 +54,7 @@ fn test_rebase_branch_with_merge() {
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "d"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "d"]);
insta::assert_snapshot!(stdout, @r###"
Abandoned commit vruxwmqv b7c62f28 d | d
Rebased 1 descendant commits onto parents of abandoned commits
@ -63,6 +63,7 @@ fn test_rebase_branch_with_merge() {
Parent commit : royxmykx fe2e8e8b c d | c
Added 0 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ e
@ -74,14 +75,15 @@ fn test_rebase_branch_with_merge() {
"###);
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon"] /* abandons `e` */);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon"] /* abandons `e` */);
insta::assert_snapshot!(stdout, @r###"
Abandoned commit znkkpsqq 5557ece3 e | e
Working copy now at: nkmrtpmo 6b527513 (empty) (no description set)
Parent commit : rlvkpnrz 2443ea76 a e?? | a
Added 0 files, modified 0 files, removed 3 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
b
@ -93,8 +95,8 @@ fn test_rebase_branch_with_merge() {
"###);
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "descendants(c)"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "descendants(c)"]);
// TODO(ilyagr): Minor Bug: The branch `e` should be shown next
// to the commit with description `e` below. This is because the commits are
// printed in the state *after* abandonment. This will be fixed together with
@ -109,6 +111,7 @@ fn test_rebase_branch_with_merge() {
Parent commit : rlvkpnrz 2443ea76 a e?? | a
Added 0 files, modified 0 files, removed 3 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
b
@ -118,11 +121,12 @@ fn test_rebase_branch_with_merge() {
"###);
// Test abandoning the same commit twice directly
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "b", "b"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "b", "b"]);
insta::assert_snapshot!(stdout, @r###"
Abandoned commit zsuskuln 1394f625 b | b
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ e
@ -134,8 +138,8 @@ fn test_rebase_branch_with_merge() {
"###);
// Test abandoning the same commit twice indirectly
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "d::", "a::"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "d::", "a::"]);
insta::assert_snapshot!(stdout, @r###"
Abandoned the following commits:
znkkpsqq 5557ece3 e | e
@ -146,6 +150,7 @@ fn test_rebase_branch_with_merge() {
Parent commit : zzzzzzzz 00000000 a b e?? | (empty) (no description set)
Added 0 files, modified 0 files, removed 4 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@
c d e??

View file

@ -21,11 +21,11 @@ pub mod common;
#[test]
fn test_alias_basic() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(r#"aliases.b = ["log", "-r", "@", "-T", "branches"]"#);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "my-branch"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "my-branch"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["b"]);
insta::assert_snapshot!(stdout, @r###"
@ my-branch
@ -37,12 +37,12 @@ fn test_alias_basic() {
#[test]
fn test_alias_legacy_section() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Can define aliases in [alias] section
test_env.add_config(r#"alias.b = ["log", "-r", "@", "-T", "branches"]"#);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "my-branch"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "my-branch"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["b"]);
insta::assert_snapshot!(stdout, @r###"
@ my-branch
@ -62,7 +62,7 @@ fn test_alias_legacy_section() {
#[test]
fn test_alias_bad_name() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["foo."]);
@ -78,7 +78,7 @@ fn test_alias_bad_name() {
#[test]
fn test_alias_calls_unknown_command() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(r#"aliases.foo = ["nonexistent"]"#);
@ -97,7 +97,7 @@ fn test_alias_calls_unknown_command() {
#[test]
fn test_alias_calls_command_with_invalid_option() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(r#"aliases.foo = ["log", "--nonexistent"]"#);
@ -116,7 +116,7 @@ fn test_alias_calls_command_with_invalid_option() {
#[test]
fn test_alias_calls_help() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(r#"aliases.h = ["--help"]"#);
let stdout = test_env.jj_cmd_success(&repo_path, &["h"]);
@ -132,7 +132,7 @@ fn test_alias_calls_help() {
#[test]
fn test_alias_cannot_override_builtin() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(r#"aliases.log = ["rebase"]"#);
@ -146,7 +146,7 @@ fn test_alias_cannot_override_builtin() {
#[test]
fn test_alias_recursive() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(
@ -171,7 +171,7 @@ fn test_alias_recursive() {
#[test]
fn test_alias_global_args_before_and_after() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(r#"aliases.l = ["log", "-T", "commit_id", "-r", "all()"]"#);
// Test the setup
@ -206,7 +206,7 @@ fn test_alias_global_args_before_and_after() {
#[test]
fn test_alias_global_args_in_definition() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(
r#"aliases.l = ["log", "-T", "commit_id", "--at-op", "@-", "-r", "all()", "--color=always"]"#,

View file

@ -21,7 +21,7 @@ pub mod common;
#[test]
fn test_branch_multiple_names() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo", "bar"]);
@ -35,10 +35,12 @@ fn test_branch_multiple_names() {
000000000000
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "delete", "foo", "bar", "foo"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["branch", "delete", "foo", "bar", "foo"]);
insta::assert_snapshot!(stdout, @r###"
Deleted 2 branches.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 230dd059e1b0
000000000000
@ -48,11 +50,13 @@ fn test_branch_multiple_names() {
#[test]
fn test_branch_at_root() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "create", "fred", "-r=root()"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "fred", "-r=root()"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
@ -66,7 +70,7 @@ fn test_branch_at_root() {
#[test]
fn test_branch_empty_name() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["branch", "create", ""]);
@ -80,22 +84,24 @@ fn test_branch_empty_name() {
#[test]
fn test_branch_forget_glob() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo-1"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "bar-2"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo-3"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo-4"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo-1"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "bar-2"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo-3"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo-4"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 foo-1 foo-3 foo-4 230dd059e1b0
000000000000
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "forget", "--glob", "foo-[1-3]"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["branch", "forget", "--glob", "foo-[1-3]"]);
insta::assert_snapshot!(stdout, @r###"
Forgot 2 branches.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 foo-4 230dd059e1b0
000000000000
@ -103,13 +109,14 @@ fn test_branch_forget_glob() {
// Forgetting a branch via both explicit name and glob pattern, or with
// multiple glob patterns, shouldn't produce an error.
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&[
"branch", "forget", "foo-4", "--glob", "foo-*", "--glob", "foo-*",
],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 230dd059e1b0
000000000000
@ -141,7 +148,7 @@ fn test_branch_forget_glob() {
fn test_branch_delete_glob() {
// Set up a git repo with a branch and a jj repo that has it as a remote.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let git_repo_path = test_env.env_root().join("git-repo");
let git_repo = git2::Repository::init_bare(git_repo_path).unwrap();
@ -150,27 +157,29 @@ fn test_branch_delete_glob() {
tree_builder
.insert("file", file_oid, git2::FileMode::Blob.into())
.unwrap();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "origin", "../git-repo"],
);
test_env.jj_cmd_success(&repo_path, &["describe", "-m=commit"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo-1"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "bar-2"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo-3"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo-4"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=commit"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo-1"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "bar-2"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo-3"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo-4"]);
// Push to create remote-tracking branches
test_env.jj_cmd_success(&repo_path, &["git", "push", "--all"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push", "--all"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 foo-1 foo-3 foo-4 6fbf398c2d59
000000000000
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "delete", "--glob", "foo-[1-3]"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["branch", "delete", "--glob", "foo-[1-3]"]);
insta::assert_snapshot!(stdout, @r###"
Deleted 2 branches.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 foo-1@origin foo-3@origin foo-4 6fbf398c2d59
000000000000
@ -185,13 +194,14 @@ fn test_branch_delete_glob() {
// Deleting a branch via both explicit name and glob pattern, or with
// multiple glob patterns, shouldn't produce an error.
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&[
"branch", "delete", "foo-4", "--glob", "foo-*", "--glob", "foo-*",
],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 foo-1@origin foo-3@origin foo-4@origin 6fbf398c2d59
000000000000
@ -224,14 +234,14 @@ fn test_branch_delete_glob() {
#[test]
fn test_branch_delete_export() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo"]);
test_env.jj_cmd_success(&repo_path, &["git", "export"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo"]);
test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
test_env.jj_cmd_success(&repo_path, &["branch", "delete", "foo"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "delete", "foo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
insta::assert_snapshot!(stdout, @r###"
foo (deleted)
@ -239,7 +249,7 @@ fn test_branch_delete_export() {
(this branch will be deleted from the underlying Git repo on the next `jj git export`)
"###);
test_env.jj_cmd_success(&repo_path, &["git", "export"]);
test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
insta::assert_snapshot!(stdout, @r###"
"###);
@ -248,21 +258,23 @@ fn test_branch_delete_export() {
#[test]
fn test_branch_forget_export() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "foo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
insta::assert_snapshot!(stdout, @r###"
foo: rlvkpnrz 65b6b74e (empty) (no description set)
"###);
// Exporting the branch to git creates a local-git tracking branch
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "export"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "forget", "foo"]);
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "forget", "foo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
// Forgetting a branch deletes local and remote-tracking branches including
// the corresponding git-tracking branch.
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
@ -276,8 +288,9 @@ fn test_branch_forget_export() {
// this will happen automatically immediately after a `jj branch forget`.
// This is demonstrated in `test_git_colocated_branch_forget` in
// test_git_colocated.rs
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "export"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
insta::assert_snapshot!(stdout, @"");
}
@ -289,7 +302,7 @@ fn test_branch_forget_fetched_branch() {
// Set up a git repo with a branch and a jj repo that has it as a remote.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let git_repo_path = test_env.env_root().join("git-repo");
let git_repo = git2::Repository::init_bare(git_repo_path).unwrap();
@ -302,7 +315,7 @@ fn test_branch_forget_fetched_branch() {
.unwrap();
let tree_oid = tree_builder.write().unwrap();
let tree = git_repo.find_tree(tree_oid).unwrap();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "origin", "../git-repo"],
);
@ -319,14 +332,14 @@ fn test_branch_forget_fetched_branch() {
.unwrap();
// Fetch normally
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1: mzyxwzks 9f01a0e0 message
"###);
// TEST 1: with export-import
// Forget the branch
test_env.jj_cmd_success(&repo_path, &["branch", "forget", "feature1"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "forget", "feature1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
// At this point `jj git export && jj git import` does *not* recreate the
@ -337,25 +350,31 @@ fn test_branch_forget_fetched_branch() {
// the ref in jj view's `git_refs` tracking the local git repo's remote-tracking
// branch.
// TODO: Show that jj git push is also a no-op
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "export"]), @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "import"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
// We can fetch feature1 again.
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1: mzyxwzks 9f01a0e0 message
"###);
// TEST 2: No export/import (otherwise the same as test 1)
test_env.jj_cmd_success(&repo_path, &["branch", "forget", "feature1"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "forget", "feature1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
// Fetch works even without the export-import
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1: mzyxwzks 9f01a0e0 message
"###);
@ -373,12 +392,14 @@ fn test_branch_forget_fetched_branch() {
&[&git_repo.find_commit(first_git_repo_commit).unwrap()],
)
.unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "forget", "feature1"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "forget", "feature1"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
// Fetching a moved branch does not create a conflict
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1: ooosovrs 38aefb17 (empty) another message
"###);
@ -392,7 +413,7 @@ fn test_branch_forget_deleted_or_nonexistent_branch() {
// ======== Beginning of test setup ========
// Set up a git repo with a branch and a jj repo that has it as a remote.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let git_repo_path = test_env.env_root().join("git-repo");
let git_repo = git2::Repository::init_bare(git_repo_path).unwrap();
@ -405,7 +426,7 @@ fn test_branch_forget_deleted_or_nonexistent_branch() {
.unwrap();
let tree_oid = tree_builder.write().unwrap();
let tree = git_repo.find_tree(tree_oid).unwrap();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "origin", "../git-repo"],
);
@ -422,8 +443,8 @@ fn test_branch_forget_deleted_or_nonexistent_branch() {
.unwrap();
// Fetch and then delete the branch
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
test_env.jj_cmd_success(&repo_path, &["branch", "delete", "feature1"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "delete", "feature1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1 (deleted)
@origin: mzyxwzks 9f01a0e0 message
@ -434,7 +455,7 @@ fn test_branch_forget_deleted_or_nonexistent_branch() {
// ============ End of test setup ============
// We can forget a deleted branch
test_env.jj_cmd_success(&repo_path, &["branch", "forget", "feature1"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "forget", "feature1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
// Can't forget a non-existent branch
@ -452,29 +473,29 @@ fn test_branch_list_filtered_by_revset() {
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
// Initialize remote refs
test_env.jj_cmd_success(test_env.env_root(), &["init", "remote", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "remote", "--git"]);
let remote_path = test_env.env_root().join("remote");
for branch in ["remote-keep", "remote-delete", "remote-rewrite"] {
test_env.jj_cmd_success(&remote_path, &["new", "root()", "-m", branch]);
test_env.jj_cmd_success(&remote_path, &["branch", "set", branch]);
test_env.jj_cmd_ok(&remote_path, &["new", "root()", "-m", branch]);
test_env.jj_cmd_ok(&remote_path, &["branch", "set", branch]);
}
test_env.jj_cmd_success(&remote_path, &["new"]);
test_env.jj_cmd_success(&remote_path, &["git", "export"]);
test_env.jj_cmd_ok(&remote_path, &["new"]);
test_env.jj_cmd_ok(&remote_path, &["git", "export"]);
// Initialize local refs
let mut remote_git_path = remote_path;
remote_git_path.extend([".jj", "repo", "store", "git"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
test_env.env_root(),
&["git", "clone", remote_git_path.to_str().unwrap(), "local"],
);
let local_path = test_env.env_root().join("local");
test_env.jj_cmd_success(&local_path, &["new", "root()", "-m", "local-keep"]);
test_env.jj_cmd_success(&local_path, &["branch", "set", "local-keep"]);
test_env.jj_cmd_ok(&local_path, &["new", "root()", "-m", "local-keep"]);
test_env.jj_cmd_ok(&local_path, &["branch", "set", "local-keep"]);
// Mutate refs in local repository
test_env.jj_cmd_success(&local_path, &["branch", "delete", "remote-delete"]);
test_env.jj_cmd_success(&local_path, &["describe", "-mrewritten", "remote-rewrite"]);
test_env.jj_cmd_ok(&local_path, &["branch", "delete", "remote-delete"]);
test_env.jj_cmd_ok(&local_path, &["describe", "-mrewritten", "remote-rewrite"]);
let template = r#"separate(" ", commit_id.short(), branches, if(hidden, "(hidden)"))"#;
insta::assert_snapshot!(

View file

@ -20,7 +20,7 @@ pub mod common;
fn set_up(trunk_name: &str) -> (TestEnvironment, PathBuf) {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "origin"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "origin"]);
let origin_path = test_env.env_root().join("origin");
let origin_git_repo_path = origin_path
.join(".jj")
@ -28,13 +28,13 @@ fn set_up(trunk_name: &str) -> (TestEnvironment, PathBuf) {
.join("store")
.join("git");
test_env.jj_cmd_success(&origin_path, &["describe", "-m=description 1"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", trunk_name]);
test_env.jj_cmd_success(&origin_path, &["new", "root()", "-m=description 2"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "unrelated_branch"]);
test_env.jj_cmd_success(&origin_path, &["git", "export"]);
test_env.jj_cmd_ok(&origin_path, &["describe", "-m=description 1"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", trunk_name]);
test_env.jj_cmd_ok(&origin_path, &["new", "root()", "-m=description 2"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "unrelated_branch"]);
test_env.jj_cmd_ok(&origin_path, &["git", "export"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
test_env.env_root(),
&[
"git",
@ -87,8 +87,8 @@ fn test_builtin_alias_trunk_matches_trunk() {
fn test_builtin_alias_trunk_matches_exactly_one_commit() {
let (test_env, workspace_root) = set_up("main");
let origin_path = test_env.env_root().join("origin");
test_env.jj_cmd_success(&origin_path, &["new", "root()", "-m=description 3"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "master"]);
test_env.jj_cmd_ok(&origin_path, &["new", "root()", "-m=description 3"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "master"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "trunk()"]);
insta::assert_snapshot!(stdout, @r###"

View file

@ -19,11 +19,11 @@ pub mod common;
#[test]
fn test_cat() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
std::fs::create_dir(repo_path.join("dir")).unwrap();
std::fs::write(repo_path.join("dir").join("file2"), "c\n").unwrap();
@ -70,9 +70,9 @@ fn test_cat() {
"###);
// Can print a conflict
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "@", "-d", "@--"]);
test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "@", "-d", "@--"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file1"]);
insta::assert_snapshot!(stdout, @r###"
<<<<<<<

View file

@ -21,18 +21,19 @@ pub mod common;
#[test]
fn test_checkout() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "second"]);
// Check out current commit
let stdout = test_env.jj_cmd_success(&repo_path, &["checkout", "@"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["checkout", "@"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: zsuskuln 05ce7118 (empty) (no description set)
Parent commit : rlvkpnrz 5c52832c (empty) second
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 05ce7118568d3007efc9163b055f9cb4a6becfde
5c52832c3483e0ace06d047a806024984f28f1d7 second
@ -41,7 +42,7 @@ fn test_checkout() {
"###);
// Can provide a description
test_env.jj_cmd_success(&repo_path, &["checkout", "@--", "-m", "my message"]);
test_env.jj_cmd_ok(&repo_path, &["checkout", "@--", "-m", "my message"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 1191baaf276e3d0b96b1747e885b3a517be80d6f my message
5c52832c3483e0ace06d047a806024984f28f1d7 second
@ -54,14 +55,14 @@ fn test_checkout() {
#[test]
fn test_checkout_not_single_rev() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "fourth"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "fifth"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "fourth"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "fifth"]);
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "root()..@"]);
insta::assert_snapshot!(stderr, @r###"
@ -103,13 +104,13 @@ fn test_checkout_not_single_rev() {
#[test]
fn test_checkout_conflicting_branches() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "one"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "two", "@-"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "foo"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "one"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "two", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]);
test_env.jj_cmd_ok(
&repo_path,
&[
"--at-op=@-",
@ -122,7 +123,7 @@ fn test_checkout_conflicting_branches() {
);
// Trigger resolution of concurrent operations
test_env.jj_cmd_success(&repo_path, &["st"]);
test_env.jj_cmd_ok(&repo_path, &["st"]);
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "foo"]);
insta::assert_snapshot!(stderr, @r###"
@ -138,14 +139,14 @@ fn test_checkout_conflicting_branches() {
#[test]
fn test_checkout_conflicting_change_ids() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "one"]);
test_env.jj_cmd_success(&repo_path, &["--at-op=@-", "describe", "-m", "two"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "one"]);
test_env.jj_cmd_ok(&repo_path, &["--at-op=@-", "describe", "-m", "two"]);
// Trigger resolution of concurrent operations
test_env.jj_cmd_success(&repo_path, &["st"]);
test_env.jj_cmd_ok(&repo_path, &["st"]);
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "qpvuntsm"]);
insta::assert_snapshot!(stderr, @r###"

View file

@ -26,16 +26,16 @@ fn create_commit(
files: &[(&str, &str)],
) {
if parents.is_empty() {
test_env.jj_cmd_success(repo_path, &["new", "root()", "-m", name]);
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", name]);
} else {
let mut args = vec!["new", "-m", name];
args.extend(parents);
test_env.jj_cmd_success(repo_path, &args);
test_env.jj_cmd_ok(repo_path, &args);
}
for (name, content) in files {
std::fs::write(repo_path.join(name), content).unwrap();
}
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
}
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
@ -45,14 +45,14 @@ fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
#[test]
fn test_chmod_regular_conflict() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
create_commit(&test_env, &repo_path, "n", &["base"], &[("file", "n\n")]);
create_commit(&test_env, &repo_path, "x", &["base"], &[("file", "x\n")]);
// Test chmodding a file. The effect will be visible in the conflict below.
test_env.jj_cmd_success(&repo_path, &["chmod", "x", "file", "-r=x"]);
test_env.jj_cmd_ok(&repo_path, &["chmod", "x", "file", "-r=x"]);
create_commit(&test_env, &repo_path, "conflict", &["x", "n"], &[]);
// Test the setup
@ -75,7 +75,7 @@ fn test_chmod_regular_conflict() {
"###);
// Test chmodding a conflict
test_env.jj_cmd_success(&repo_path, &["chmod", "x", "file"]);
test_env.jj_cmd_ok(&repo_path, &["chmod", "x", "file"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file"]);
insta::assert_snapshot!(stdout,
@r###"
@ -84,7 +84,7 @@ fn test_chmod_regular_conflict() {
Adding executable file with id 587be6b4c3f93f93c489c0111bba5596147a26cb
Adding executable file with id 8ba3a16384aacc37d01564b28401755ce8053f51
"###);
test_env.jj_cmd_success(&repo_path, &["chmod", "n", "file"]);
test_env.jj_cmd_ok(&repo_path, &["chmod", "n", "file"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file"]);
insta::assert_snapshot!(stdout,
@r###"
@ -122,7 +122,7 @@ fn test_chmod_regular_conflict() {
#[test]
fn test_chmod_file_dir_deletion_conflicts() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
@ -185,13 +185,15 @@ fn test_chmod_file_dir_deletion_conflicts() {
-base
>>>>>>>
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["chmod", "x", "file", "-r=file_deletion"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["chmod", "x", "file", "-r=file_deletion"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: kmkuslsw 8b70a1d2 file_deletion | (conflict) file_deletion
Parent commit : zsuskuln c51c9c55 file | file
Parent commit : royxmykx 6b18b3c1 deletion | deletion
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "-r=file_deletion", "file"]);
insta::assert_snapshot!(stdout,
@r###"

View file

@ -21,11 +21,11 @@ pub mod common;
#[test]
fn test_commit_with_description_from_cli() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
// Description applies to the current working-copy (not the new one)
test_env.jj_cmd_success(&workspace_path, &["commit", "-m=first"]);
test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=first"]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
@ b88fb4e51bdd
69542c1984c1 first
@ -36,15 +36,15 @@ fn test_commit_with_description_from_cli() {
#[test]
fn test_commit_with_editor() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
// Check that the text file gets initialized with the current description and
// set a new one
test_env.jj_cmd_success(&workspace_path, &["describe", "-m=initial"]);
test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=initial"]);
let edit_script = test_env.set_up_fake_editor();
std::fs::write(&edit_script, ["dump editor0", "write\nmodified"].join("\0")).unwrap();
test_env.jj_cmd_success(&workspace_path, &["commit"]);
test_env.jj_cmd_ok(&workspace_path, &["commit"]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
@ 3df78bc2b9b5
30a8c2b3d6eb modified
@ -60,9 +60,9 @@ fn test_commit_with_editor() {
// Check that the editor content includes diff summary
std::fs::write(workspace_path.join("file1"), "foo\n").unwrap();
std::fs::write(workspace_path.join("file2"), "foo\n").unwrap();
test_env.jj_cmd_success(&workspace_path, &["describe", "-m=add files"]);
test_env.jj_cmd_ok(&workspace_path, &["describe", "-m=add files"]);
std::fs::write(&edit_script, "dump editor1").unwrap();
test_env.jj_cmd_success(&workspace_path, &["commit"]);
test_env.jj_cmd_ok(&workspace_path, &["commit"]);
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r###"
add files
@ -78,7 +78,7 @@ fn test_commit_with_editor() {
#[test]
fn test_commit_with_default_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
test_env.add_config(r#"ui.default-description = "\n\nTESTED=TODO""#);
let workspace_path = test_env.env_root().join("repo");
@ -86,7 +86,7 @@ fn test_commit_with_default_description() {
std::fs::write(workspace_path.join("file2"), "bar\n").unwrap();
let edit_script = test_env.set_up_fake_editor();
std::fs::write(&edit_script, ["dump editor"].join("\0")).unwrap();
test_env.jj_cmd_success(&workspace_path, &["commit"]);
test_env.jj_cmd_ok(&workspace_path, &["commit"]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r#"
@ 8dc0591d00f7
@ -110,10 +110,10 @@ JJ: Lines starting with "JJ: " (like this one) will be removed.
#[test]
fn test_commit_without_working_copy() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&workspace_path, &["workspace", "forget"]);
test_env.jj_cmd_ok(&workspace_path, &["workspace", "forget"]);
let stderr = test_env.jj_cmd_failure(&workspace_path, &["commit", "-m=first"]);
insta::assert_snapshot!(stderr, @r###"
Error: This command requires a working copy
@ -123,13 +123,13 @@ fn test_commit_without_working_copy() {
#[test]
fn test_commit_paths() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
std::fs::write(workspace_path.join("file1"), "foo\n").unwrap();
std::fs::write(workspace_path.join("file2"), "bar\n").unwrap();
test_env.jj_cmd_success(&workspace_path, &["commit", "-m=first", "file1"]);
test_env.jj_cmd_ok(&workspace_path, &["commit", "-m=first", "file1"]);
let stdout = test_env.jj_cmd_success(&workspace_path, &["diff", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Added regular file file1:
@ -146,7 +146,7 @@ fn test_commit_paths() {
#[test]
fn test_commit_paths_warning() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
std::fs::write(workspace_path.join("file1"), "foo\n").unwrap();

View file

@ -20,12 +20,12 @@ pub mod common;
#[test]
fn test_log_parents() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["new", "@-"]);
test_env.jj_cmd_success(&repo_path, &["new", "@", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@", "@-"]);
let template = r#"commit_id ++ "\nP: " ++ parents.map(|c| c.commit_id()) ++ "\n""#;
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
@ -78,11 +78,11 @@ fn test_log_parents() {
#[test]
fn test_log_author_timestamp() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "second"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "author.timestamp()"]);
insta::assert_snapshot!(stdout, @r###"
@ -95,11 +95,11 @@ fn test_log_author_timestamp() {
#[test]
fn test_log_author_timestamp_ago() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "second"]);
let template = r#"author.timestamp().ago() ++ "\n""#;
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-T", template]);
@ -113,7 +113,7 @@ fn test_log_author_timestamp_ago() {
#[test]
fn test_log_author_timestamp_utc() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "author.timestamp().utc()"]);
@ -126,13 +126,13 @@ fn test_log_author_timestamp_utc() {
#[test]
fn test_log_default() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "description 1"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "my-branch"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "description 1"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "my-branch"]);
// Test default log output format
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
@ -168,7 +168,7 @@ fn test_log_default() {
#[test]
fn test_log_builtin_templates() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
@ -233,7 +233,7 @@ fn test_log_builtin_templates() {
#[test]
fn test_log_builtin_templates_colored() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render =
|template| test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", template]);
@ -299,11 +299,11 @@ fn test_log_builtin_templates_colored() {
#[test]
fn test_log_obslog_divergence() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description 1"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description 1"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
// No divergence
insta::assert_snapshot!(stdout, @r###"
@ -313,11 +313,11 @@ fn test_log_obslog_divergence() {
"###);
// Create divergence
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["describe", "-m", "description 2", "--at-operation", "@-"],
);
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
qpvuntsm?? test.user@example.com 2001-02-03 04:05:10.000 +07:00 8979953d
@ -326,6 +326,7 @@ fn test_log_obslog_divergence() {
description 1
zzzzzzzz root() 00000000
"###);
insta::assert_snapshot!(stderr, @"");
// Color
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always"]);
@ -365,9 +366,9 @@ fn test_log_git_head() {
let test_env = TestEnvironment::default();
let repo_path = test_env.env_root().join("repo");
git2::Repository::init(&repo_path).unwrap();
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_success(&repo_path, &["new", "-m=initial"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m=initial"]);
std::fs::write(repo_path.join("file"), "foo\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always"]);
insta::assert_snapshot!(stdout, @r###"
@ -382,10 +383,10 @@ fn test_log_git_head() {
#[test]
fn test_log_customize_short_id() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]);
// Customize both the commit and the change id
let decl = "template-aliases.'format_short_id(id)'";

View file

@ -23,17 +23,17 @@ pub mod common;
#[test]
fn test_concurrent_operation_divergence() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "message 1"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "message 1"]);
test_env.jj_cmd_ok(
&repo_path,
&["describe", "-m", "message 2", "--at-op", "@-"],
);
// We should be informed about the concurrent modification
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-T", "description"]);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
message 2
@ -41,16 +41,17 @@ fn test_concurrent_operation_divergence() {
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_concurrent_operations_auto_rebase() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
insta::assert_snapshot!(stdout, @r###"
@ cfc96ff553b9 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
@ -66,45 +67,48 @@ fn test_concurrent_operations_auto_rebase() {
"###);
let op_id_hex = stdout[3..15].to_string();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "rewritten"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "rewritten"]);
test_env.jj_cmd_ok(
&repo_path,
&["new", "--at-op", &op_id_hex, "-m", "new child"],
);
// We should be informed about the concurrent modification
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
let (stdout, stderr) = get_log_output_with_stderr(&test_env, &repo_path);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
Rebased 1 descendant commits onto commits rewritten by other operation
3f06323826b4a293a9ee6d24cc0e07ad2961b5d5 new child
@ d91437157468ec86bbbc9e6a14a60d3e8d1790ac rewritten
0000000000000000000000000000000000000000
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_concurrent_operations_wc_modified() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "contents\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
let op_id_hex = stdout[3..15].to_string();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["new", "--at-op", &op_id_hex, "-m", "new child1"],
);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["new", "--at-op", &op_id_hex, "-m", "new child2"],
);
std::fs::write(repo_path.join("file"), "modified\n").unwrap();
// We should be informed about the concurrent modification
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
let (stdout, stderr) = get_log_output_with_stderr(&test_env, &repo_path);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
@ 4eb0610031b7cd148ff9f729a673a3f815033170 new child1
4b20e61d23ee7d7c4d5e61e11e97c26e716f9c30 new child2
@ -112,6 +116,7 @@ fn test_concurrent_operations_wc_modified() {
52c893bf3cd201e215b23e084e8a871244ca14d5 initial
0000000000000000000000000000000000000000
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--git"]);
insta::assert_snapshot!(stdout, @r###"
diff --git a/file b/file
@ -142,7 +147,7 @@ fn test_concurrent_operations_wc_modified() {
#[test]
fn test_concurrent_snapshot_wc_reloadable() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let op_heads_dir = repo_path
.join(".jj")
@ -151,11 +156,11 @@ fn test_concurrent_snapshot_wc_reloadable() {
.join("heads");
std::fs::write(repo_path.join("base"), "").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "initial"]);
// Create new commit and checkout it.
std::fs::write(repo_path.join("child1"), "").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "new child1"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "new child1"]);
let template = r#"id ++ "\n" ++ description ++ "\n" ++ tags"#;
let op_log_stdout = test_env.jj_cmd_success(&repo_path, &["op", "log", "-T", template]);
@ -189,11 +194,12 @@ fn test_concurrent_snapshot_wc_reloadable() {
)
.unwrap();
std::fs::write(repo_path.join("child2"), "").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["describe", "-m", "new child2"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "new child2"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: kkmpptxz 4011424e new child2
Parent commit : rlvkpnrz e08863ee new child1
"###);
insta::assert_snapshot!(stderr, @"");
// Since the repo can be reloaded before snapshotting, "child2" should be
// a child of "child1", not of "initial".
@ -210,7 +216,7 @@ fn test_concurrent_snapshot_wc_reloadable() {
"###);
}
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
fn get_log_output_with_stderr(test_env: &TestEnvironment, cwd: &Path) -> (String, String) {
let template = r#"commit_id ++ " " ++ description"#;
test_env.jj_cmd_success(cwd, &["log", "-T", template])
test_env.jj_cmd_ok(cwd, &["log", "-T", template])
}

View file

@ -129,7 +129,7 @@ fn test_config_list_all() {
#[test]
fn test_config_layer_override_default() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let config_key = "merge-tools.vimdiff.program";
@ -179,7 +179,7 @@ fn test_config_layer_override_default() {
#[test]
fn test_config_layer_override_env() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let config_key = "ui.editor";
@ -234,14 +234,14 @@ fn test_config_layer_override_env() {
#[test]
fn test_config_layer_workspace() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
let main_path = test_env.env_root().join("main");
let secondary_path = test_env.env_root().join("secondary");
let config_key = "ui.editor";
std::fs::write(main_path.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&main_path, &["new"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&main_path, &["new"]);
test_env.jj_cmd_ok(
&main_path,
&["workspace", "add", "--name", "second", "../secondary"],
);
@ -281,17 +281,17 @@ fn test_config_set_missing_opts() {
#[test]
fn test_config_set_for_user() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
// Point to a config file since `config set` can't handle directories.
let user_config_path = test_env.config_path().join("config.toml");
test_env.set_config_path(user_config_path.to_owned());
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["config", "set", "--user", "test-key", "test-val"],
);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["config", "set", "--user", "test-table.foo", "true"],
);
@ -310,13 +310,13 @@ fn test_config_set_for_user() {
#[test]
fn test_config_set_for_repo() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["config", "set", "--repo", "test-key", "test-val"],
);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["config", "set", "--repo", "test-table.foo", "true"],
);
@ -340,12 +340,12 @@ fn test_config_set_for_repo() {
#[test]
fn test_config_set_type_mismatch() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let user_config_path = test_env.config_path().join("config.toml");
test_env.set_config_path(user_config_path);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["config", "set", "--user", "test-table.foo", "test-val"],
);
@ -361,12 +361,12 @@ fn test_config_set_type_mismatch() {
#[test]
fn test_config_set_nontable_parent() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let user_config_path = test_env.config_path().join("config.toml");
test_env.set_config_path(user_config_path);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["config", "set", "--user", "test-nontable", "test-val"],
);
@ -396,7 +396,7 @@ fn test_config_edit_missing_opt() {
#[test]
fn test_config_edit_user() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();
@ -405,13 +405,13 @@ fn test_config_edit_user() {
format!("expectpath\n{}", test_env.config_path().to_str().unwrap()),
)
.unwrap();
test_env.jj_cmd_success(&repo_path, &["config", "edit", "--user"]);
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--user"]);
}
#[test]
fn test_config_edit_repo() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();
@ -423,7 +423,7 @@ fn test_config_edit_repo() {
),
)
.unwrap();
test_env.jj_cmd_success(&repo_path, &["config", "edit", "--repo"]);
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--repo"]);
}
#[test]

View file

@ -22,7 +22,7 @@ pub mod common;
#[test]
fn test_debug_revset() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "revset", "root()"]);
@ -59,7 +59,7 @@ fn test_debug_revset() {
#[test]
fn test_debug_index() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]);
assert_snapshot!(filter_index_stats(&stdout), @r###"
@ -79,10 +79,10 @@ fn test_debug_index() {
#[test]
fn test_debug_reindex() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&workspace_path, &["new"]);
test_env.jj_cmd_success(&workspace_path, &["new"]);
test_env.jj_cmd_ok(&workspace_path, &["new"]);
test_env.jj_cmd_ok(&workspace_path, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]);
assert_snapshot!(filter_index_stats(&stdout), @r###"
Number of commits: 4
@ -99,10 +99,11 @@ fn test_debug_reindex() {
Name: [hash]
"###
);
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "reindex"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_path, &["debug", "reindex"]);
assert_snapshot!(stdout, @r###"
Finished indexing 4 commits.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]);
assert_snapshot!(filter_index_stats(&stdout), @r###"
Number of commits: 4
@ -121,7 +122,7 @@ fn test_debug_reindex() {
#[test]
fn test_debug_operation_id() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let workspace_path = test_env.env_root().join("repo");
let stdout =
test_env.jj_cmd_success(&workspace_path, &["debug", "operation", "--display", "id"]);

View file

@ -19,31 +19,36 @@ pub mod common;
#[test]
fn test_describe() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();
// Set a description using `-m` flag
let stdout = test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description from CLI"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description from CLI"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: qpvuntsm cf3e8673 (empty) description from CLI
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
// Set the same description using `-m` flag, but with explicit newline
let stdout = test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description from CLI\n"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description from CLI\n"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
// Check that the text file gets initialized with the current description and
// make no changes
std::fs::write(&edit_script, "dump editor0").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
description from CLI
@ -53,11 +58,12 @@ fn test_describe() {
// Set a description in editor
std::fs::write(&edit_script, "write\ndescription from editor").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: qpvuntsm 100943ae (empty) description from editor
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
// Lines in editor starting with "JJ: " are ignored
std::fs::write(
@ -65,19 +71,21 @@ fn test_describe() {
"write\nJJ: ignored\ndescription among comment\nJJ: ignored",
)
.unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: qpvuntsm ccefa58b (empty) description among comment
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
// Multi-line description
std::fs::write(&edit_script, "write\nline1\nline2\n\nline4\n\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: qpvuntsm e932ba42 (empty) line1
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
let stdout =
test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-r@", "-Tdescription"]);
insta::assert_snapshot!(stdout, @r###"
@ -89,18 +97,20 @@ fn test_describe() {
// Multi-line description again with CRLF, which should make no changes
std::fs::write(&edit_script, "write\nline1\r\nline2\r\n\r\nline4\r\n\r\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
// Multi-line description starting with newlines
std::fs::write(&edit_script, "write\n\n\nline1\nline2").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe"]);
insta::assert_snapshot!(stdout, @r#"
Working copy now at: qpvuntsm 13f903c1 (empty) line1
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"#);
insta::assert_snapshot!(stderr, @"");
let stdout =
test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-r@", "-Tdescription"]);
insta::assert_snapshot!(stdout, @r#"
@ -109,16 +119,18 @@ fn test_describe() {
"#);
// Clear description
let stdout = test_env.jj_cmd_success(&repo_path, &["describe", "-m", ""]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe", "-m", ""]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: qpvuntsm 3196270d (empty) (no description set)
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
std::fs::write(&edit_script, "write\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
// Fails if the editor fails
std::fs::write(&edit_script, "fail").unwrap();
@ -164,11 +176,11 @@ fn test_describe() {
#[test]
fn test_multiple_message_args() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Set a description using `-m` flag
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&[
"describe",
@ -182,6 +194,7 @@ fn test_multiple_message_args() {
Working copy now at: qpvuntsm bdee9366 (empty) First Paragraph from CLI
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
let stdout =
test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-r@", "-Tdescription"]);
@ -192,7 +205,7 @@ fn test_multiple_message_args() {
"###);
// Set the same description, with existing newlines
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&[
"describe",
@ -205,9 +218,10 @@ fn test_multiple_message_args() {
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
// Use an empty -m flag between paragraphs to insert an extra blank line
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&[
"describe",
@ -223,6 +237,7 @@ fn test_multiple_message_args() {
Working copy now at: qpvuntsm a7506fe0 (empty) First Paragraph from CLI
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
let stdout =
test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-r@", "-Tdescription"]);
@ -237,7 +252,7 @@ fn test_multiple_message_args() {
#[test]
fn test_describe_default_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
test_env.add_config(r#"ui.default-description = "\n\nTESTED=TODO""#);
let workspace_path = test_env.env_root().join("repo");
@ -245,12 +260,12 @@ fn test_describe_default_description() {
std::fs::write(workspace_path.join("file2"), "bar\n").unwrap();
let edit_script = test_env.set_up_fake_editor();
std::fs::write(&edit_script, ["dump editor"].join("\0")).unwrap();
let stdout = test_env.jj_cmd_success(&workspace_path, &["describe"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_path, &["describe"]);
insta::assert_snapshot!(stdout, @r#"
Working copy now at: qpvuntsm 7e780ba8 TESTED=TODO
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"#);
insta::assert_snapshot!(stderr, @"");
assert_eq!(
std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(),
r#"
@ -268,7 +283,7 @@ JJ: Lines starting with "JJ: " (like this one) will be removed.
#[test]
fn test_describe_author() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(
@ -293,7 +308,7 @@ fn test_describe_author() {
"###);
// Reset the author (the committer is always reset)
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&[
"describe",

View file

@ -20,12 +20,12 @@ pub mod common;
#[test]
fn test_diff_basic() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::remove_file(repo_path.join("file1")).unwrap();
std::fs::write(repo_path.join("file2"), "foo\nbar\n").unwrap();
std::fs::write(repo_path.join("file3"), "foo\n").unwrap();
@ -120,7 +120,7 @@ fn test_diff_basic() {
#[test]
fn test_diff_empty() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "").unwrap();
@ -130,7 +130,7 @@ fn test_diff_empty() {
(empty)
"###);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::remove_file(repo_path.join("file1")).unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diff"]);
insta::assert_snapshot!(stdout, @r###"
@ -148,24 +148,24 @@ fn test_diff_empty() {
#[test]
fn test_diff_types() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let file_path = repo_path.join("foo");
// Missing
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m=missing"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m=missing"]);
// Normal file
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m=file"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m=file"]);
std::fs::write(&file_path, "foo").unwrap();
// Conflict (add/add)
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m=conflict"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m=conflict"]);
std::fs::write(&file_path, "foo").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()"]);
std::fs::write(&file_path, "bar").unwrap();
test_env.jj_cmd_success(&repo_path, &["move", r#"--to=description("conflict")"#]);
test_env.jj_cmd_ok(&repo_path, &["move", r#"--to=description("conflict")"#]);
#[cfg(unix)]
{
@ -173,12 +173,12 @@ fn test_diff_types() {
use std::path::PathBuf;
// Executable
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m=executable"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m=executable"]);
std::fs::write(&file_path, "foo").unwrap();
std::fs::set_permissions(&file_path, std::fs::Permissions::from_mode(0o755)).unwrap();
// Symlink
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m=symlink"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m=symlink"]);
std::os::unix::fs::symlink(PathBuf::from("."), &file_path).unwrap();
}
@ -217,7 +217,7 @@ fn test_diff_types() {
#[test]
fn test_diff_bad_args() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["diff", "-s", "--types"]);
@ -242,7 +242,7 @@ fn test_diff_bad_args() {
#[test]
fn test_diff_relative_paths() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::create_dir_all(repo_path.join("dir1").join("subdir1")).unwrap();
@ -255,7 +255,7 @@ fn test_diff_relative_paths() {
)
.unwrap();
std::fs::write(repo_path.join("dir2").join("file4"), "foo4\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "bar1\n").unwrap();
std::fs::write(repo_path.join("dir1").join("file2"), "bar2\n").unwrap();
std::fs::write(
@ -375,12 +375,12 @@ fn test_diff_relative_paths() {
#[test]
fn test_diff_missing_newline() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo").unwrap();
std::fs::write(repo_path.join("file2"), "foo\nbar").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "foo\nbar").unwrap();
std::fs::write(repo_path.join("file2"), "foo").unwrap();
@ -429,25 +429,25 @@ fn test_diff_missing_newline() {
#[test]
fn test_color_words_diff_missing_newline() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "=== Empty"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "=== Empty"]);
std::fs::write(repo_path.join("file1"), "a\nb\nc\nd\ne\nf\ng\nh\ni").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "=== Add no newline"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "=== Add no newline"]);
std::fs::write(repo_path.join("file1"), "A\nb\nc\nd\ne\nf\ng\nh\ni").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "=== Modify first line"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "=== Modify first line"]);
std::fs::write(repo_path.join("file1"), "A\nb\nc\nd\nE\nf\ng\nh\ni").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "=== Modify middle line"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "=== Modify middle line"]);
std::fs::write(repo_path.join("file1"), "A\nb\nc\nd\nE\nf\ng\nh\nI").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "=== Modify last line"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "=== Modify last line"]);
std::fs::write(repo_path.join("file1"), "A\nb\nc\nd\nE\nf\ng\nh\nI\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "=== Append newline"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "=== Append newline"]);
std::fs::write(repo_path.join("file1"), "A\nb\nc\nd\nE\nf\ng\nh\nI").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "=== Remove newline"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "=== Remove newline"]);
std::fs::write(repo_path.join("file1"), "").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "=== Empty"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "=== Empty"]);
let stdout = test_env.jj_cmd_success(
&repo_path,
@ -530,23 +530,23 @@ fn test_color_words_diff_missing_newline() {
#[test]
fn test_diff_skipped_context() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\nb\nc\nd\ne\nf\ng\nh\ni\nj").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "=== Left side of diffs"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "=== Left side of diffs"]);
test_env.jj_cmd_success(&repo_path, &["new", "@", "-m", "=== Must skip 2 lines"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@", "-m", "=== Must skip 2 lines"]);
std::fs::write(repo_path.join("file1"), "A\nb\nc\nd\ne\nf\ng\nh\ni\nJ").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "@-", "-m", "=== Don't skip 1 line"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m", "=== Don't skip 1 line"]);
std::fs::write(repo_path.join("file1"), "A\nb\nc\nd\ne\nf\ng\nh\nI\nj").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "@-", "-m", "=== No gap to skip"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m", "=== No gap to skip"]);
std::fs::write(repo_path.join("file1"), "a\nB\nc\nd\ne\nf\ng\nh\nI\nj").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "@-", "-m", "=== No gap to skip"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m", "=== No gap to skip"]);
std::fs::write(repo_path.join("file1"), "a\nb\nC\nd\ne\nf\ng\nh\nI\nj").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "@-", "-m", "=== 1 line at start"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m", "=== 1 line at start"]);
std::fs::write(repo_path.join("file1"), "a\nb\nc\nd\nE\nf\ng\nh\ni\nj").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "@-", "-m", "=== 1 line at end"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m", "=== 1 line at end"]);
std::fs::write(repo_path.join("file1"), "a\nb\nc\nd\ne\nF\ng\nh\ni\nj").unwrap();
let stdout = test_env.jj_cmd_success(
@ -641,12 +641,12 @@ fn test_diff_skipped_context() {
#[test]
fn test_diff_external_tool() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::remove_file(repo_path.join("file1")).unwrap();
std::fs::write(repo_path.join("file2"), "foo\nbar\n").unwrap();
std::fs::write(repo_path.join("file3"), "foo\n").unwrap();
@ -759,7 +759,7 @@ fn test_diff_external_tool() {
#[test]
fn test_diff_stat() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
@ -769,13 +769,13 @@ fn test_diff_stat() {
1 file changed, 1 insertion(+), 0 deletions(-)
"###);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--stat"]);
insta::assert_snapshot!(stdout, @"0 files changed, 0 insertions(+), 0 deletions(-)");
std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "bar\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--stat"]);
@ -789,11 +789,11 @@ fn test_diff_stat() {
fn test_diff_stat_long_name_or_stat() {
let mut test_env = TestEnvironment::default();
test_env.add_env_var("COLUMNS", "30");
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let get_stat = |test_env: &TestEnvironment, path_length: usize, stat_size: usize| {
test_env.jj_cmd_success(&repo_path, &["new", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()"]);
let ascii_name = "1234567890".chars().cycle().take(path_length).join("");
let han_name = "一二三四五六七八九十"
.chars()

View file

@ -19,14 +19,14 @@ pub mod common;
#[test]
fn test_diffedit() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
std::fs::write(repo_path.join("file3"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::remove_file(repo_path.join("file1")).unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
@ -38,10 +38,11 @@ fn test_diffedit() {
"files-before file1 file2\0files-after JJ-INSTRUCTIONS file2",
)
.unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -61,22 +62,23 @@ fn test_diffedit() {
// Can edit changes to individual files
std::fs::write(&edit_script, "reset file2").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit"]);
insta::assert_snapshot!(stdout, @r###"
Created kkmpptxz 1930da4a (no description set)
Working copy now at: kkmpptxz 1930da4a (no description set)
Parent commit : rlvkpnrz 613028a4 (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
"###);
// Changes to a commit are propagated to descendants
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(&edit_script, "write file3\nmodified\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit", "-r", "@-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Created rlvkpnrz c03ae967 (no description set)
Rebased 1 descendant commits
@ -84,25 +86,27 @@ fn test_diffedit() {
Parent commit : rlvkpnrz c03ae967 (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let contents = String::from_utf8(std::fs::read(repo_path.join("file3")).unwrap()).unwrap();
insta::assert_snapshot!(contents, @r###"
modified
"###);
// Test diffedit --from @--
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(
&edit_script,
"files-before file1\0files-after JJ-INSTRUCTIONS file2 file3\0reset file2",
)
.unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit", "--from", "@--"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit", "--from", "@--"]);
insta::assert_snapshot!(stdout, @r###"
Created kkmpptxz 15f2c966 (no description set)
Working copy now at: kkmpptxz 15f2c966 (no description set)
Parent commit : rlvkpnrz 613028a4 (no description set)
Added 0 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -113,11 +117,11 @@ fn test_diffedit() {
#[test]
fn test_diffedit_new_file() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::remove_file(repo_path.join("file1")).unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
@ -129,10 +133,11 @@ fn test_diffedit_new_file() {
"files-before file1\0files-after JJ-INSTRUCTIONS file2",
)
.unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -141,13 +146,14 @@ fn test_diffedit_new_file() {
// Creating `file1` on the right side is noticed by `jj diffedit`
std::fs::write(&edit_script, "write file1\nmodified\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit"]);
insta::assert_snapshot!(stdout, @r###"
Created rlvkpnrz 7b849299 (no description set)
Working copy now at: rlvkpnrz 7b849299 (no description set)
Parent commit : qpvuntsm 414e1614 (no description set)
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
M file1
@ -160,12 +166,13 @@ fn test_diffedit_new_file() {
// On one hand, it is unexpected and potentially a minor BUG. On the other
// hand, this prevents `jj` from loading any backup files the merge tool
// generates.
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(&edit_script, "write new_file\nnew file\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -176,14 +183,14 @@ fn test_diffedit_new_file() {
#[test]
fn test_diffedit_3pane() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
std::fs::write(repo_path.join("file3"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::remove_file(repo_path.join("file1")).unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
@ -207,26 +214,28 @@ fn test_diffedit_3pane() {
"files-before file1 file2\0files-after JJ-INSTRUCTIONS file2",
)
.unwrap();
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["diffedit", "--config-toml", &config_with_output_as_after],
);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
M file2
"###);
// Nothing happens if we make no changes, `config_with_right_as_after` version
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["diffedit", "--config-toml", &config_with_right_as_after],
);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -235,7 +244,7 @@ fn test_diffedit_3pane() {
// Can edit changes to individual files
std::fs::write(&edit_script, "reset file2").unwrap();
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["diffedit", "--config-toml", &config_with_output_as_after],
);
@ -245,15 +254,16 @@ fn test_diffedit_3pane() {
Parent commit : rlvkpnrz 613028a4 (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
"###);
// Can write something new to `file1`
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(&edit_script, "write file1\nnew content").unwrap();
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["diffedit", "--config-toml", &config_with_output_as_after],
);
@ -263,6 +273,7 @@ fn test_diffedit_3pane() {
Parent commit : rlvkpnrz 613028a4 (no description set)
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
M file1
@ -270,15 +281,16 @@ fn test_diffedit_3pane() {
"###);
// But nothing happens if we modify the right side
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(&edit_script, "write file1\nnew content").unwrap();
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["diffedit", "--config-toml", &config_with_right_as_after],
);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -292,24 +304,24 @@ fn test_diffedit_3pane() {
#[test]
fn test_diffedit_merge() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["co", "@-"]);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["co", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
std::fs::write(repo_path.join("file2"), "c\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "@", "b", "-m", "merge"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@", "b", "-m", "merge"]);
// Resolve the conflict in file1, but leave the conflict in file2
std::fs::write(repo_path.join("file1"), "d\n").unwrap();
std::fs::write(repo_path.join("file3"), "d\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
// Test the setup
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-r", "@-", "-s"]);
insta::assert_snapshot!(stdout, @r###"
@ -325,7 +337,7 @@ fn test_diffedit_merge() {
"files-before file1\0files-after JJ-INSTRUCTIONS file1 file3\0rm file1",
)
.unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit", "-r", "@-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Created royxmykx 2b5202ae (conflict) merge
Rebased 1 descendant commits
@ -333,6 +345,7 @@ fn test_diffedit_merge() {
Parent commit : royxmykx 2b5202ae (conflict) merge
Added 0 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -354,12 +367,12 @@ fn test_diffedit_merge() {
#[test]
fn test_diffedit_old_restore_interactive_tests() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::remove_file(repo_path.join("file1")).unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
std::fs::write(repo_path.join("file3"), "b\n").unwrap();
@ -367,10 +380,11 @@ fn test_diffedit_old_restore_interactive_tests() {
let edit_script = test_env.set_up_fake_diff_editor();
// Nothing happens if we make no changes
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit", "--from", "@-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit", "--from", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -392,28 +406,30 @@ fn test_diffedit_old_restore_interactive_tests() {
// Can restore changes to individual files
std::fs::write(&edit_script, "reset file2\0reset file3").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit", "--from", "@-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit", "--from", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Created rlvkpnrz abdbf627 (no description set)
Working copy now at: rlvkpnrz abdbf627 (no description set)
Parent commit : qpvuntsm 2375fa16 (no description set)
Added 0 files, modified 1 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
"###);
// Can make unrelated edits
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(&edit_script, "write file3\nunrelated\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["diffedit", "--from", "@-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit", "--from", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Created rlvkpnrz e31f7f33 (no description set)
Working copy now at: rlvkpnrz e31f7f33 (no description set)
Parent commit : qpvuntsm 2375fa16 (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--git"]);
insta::assert_snapshot!(stdout, @r###"
diff --git a/file1 b/file1

View file

@ -20,20 +20,20 @@ pub mod common;
fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, parents: &[&str]) {
if parents.is_empty() {
test_env.jj_cmd_success(repo_path, &["new", "root()", "-m", name]);
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", name]);
} else {
let mut args = vec!["new", "-m", name];
args.extend(parents);
test_env.jj_cmd_success(repo_path, &args);
test_env.jj_cmd_ok(repo_path, &args);
}
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
}
#[test]
fn test_duplicate() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -54,10 +54,11 @@ fn test_duplicate() {
Error: Cannot duplicate the root commit
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "a"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "a"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 2443ea76b0b1 as znkkpsqq 2f6dc5a1 a
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
2f6dc5a1ffc2 a
@ 17a00fc21654 c
@ -69,11 +70,14 @@ fn test_duplicate() {
000000000000
"###);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["undo"]), @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate" /* duplicates `c` */]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate" /* duplicates `c` */]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 17a00fc21654 as wqnwkozp 1dd099ea c
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
1dd099ea963c c
@ -89,7 +93,7 @@ fn test_duplicate() {
#[test]
fn test_duplicate_many() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -109,11 +113,12 @@ fn test_duplicate_many() {
000000000000
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "b::"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "b::"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 1394f625cbbd as wqnwkozp 3b74d969 b
Duplicated 921dde6e55c0 as mouksmqu 8348ddce e
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
8348ddcec733 e
@ -130,11 +135,12 @@ fn test_duplicate_many() {
"###);
// Try specifying the same commit twice directly
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "b", "b"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "b", "b"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 1394f625cbbd as nkmrtpmo 0276d3d7 b
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
0276d3d7c24d b
@ 921dde6e55c0 e
@ -149,13 +155,14 @@ fn test_duplicate_many() {
"###);
// Try specifying the same commit twice indirectly
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "b::", "d::"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "b::", "d::"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 1394f625cbbd as xtnwkqum fa167d18 b
Duplicated ebd06dba20ec as pqrnrkux 2181781b d
Duplicated 921dde6e55c0 as ztxkyksq 0f7430f2 e
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
0f7430f2727a e
@ -173,7 +180,7 @@ fn test_duplicate_many() {
000000000000
"###);
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
// Reminder of the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 921dde6e55c0 e
@ -185,12 +192,13 @@ fn test_duplicate_many() {
2443ea76b0b1 a
000000000000
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "d::", "a"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "d::", "a"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 2443ea76b0b1 as nlrtlrxv c6f7f8c4 a
Duplicated ebd06dba20ec as plymsszl d94e4c55 d
Duplicated 921dde6e55c0 as urrlptpw 9bd4389f e
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
9bd4389f5d47 e
@ -209,8 +217,8 @@ fn test_duplicate_many() {
"###);
// Check for BUG -- makes too many 'a'-s, etc.
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "a::"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "a::"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 2443ea76b0b1 as uuuvxpvw 0fe67a05 a
Duplicated 1394f625cbbd as nmpuuozl e13ac0ad b
@ -218,6 +226,7 @@ fn test_duplicate_many() {
Duplicated ebd06dba20ec as yxrlprzz 2f2442db d
Duplicated 921dde6e55c0 as mvkzkxrl ee8fe64e e
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
ee8fe64ed254 e
@ -242,7 +251,7 @@ fn test_duplicate_many() {
#[test]
fn test_undo_after_duplicate() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -251,10 +260,11 @@ fn test_undo_after_duplicate() {
000000000000
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "a"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "a"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 2443ea76b0b1 as mzvwutvl f5cefcbb a
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
f5cefcbb65a4 a
@ 2443ea76b0b1 a
@ -262,7 +272,9 @@ fn test_undo_after_duplicate() {
000000000000
"###);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["undo"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 2443ea76b0b1 a
000000000000
@ -273,7 +285,7 @@ fn test_undo_after_duplicate() {
#[test]
fn test_rebase_duplicates() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -285,14 +297,16 @@ fn test_rebase_duplicates() {
000000000000 @ 1970-01-01 00:00:00.000 +00:00
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "b"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "b"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 1394f625cbbd as yqosqzyt fdaaf395 b
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["duplicate", "b"]);
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate", "b"]);
insta::assert_snapshot!(stdout, @r###"
Duplicated 1394f625cbbd as vruxwmqv 870cf438 b
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output_with_ts(&test_env, &repo_path), @r###"
870cf438ccbb b @ 2001-02-03 04:05:14.000 +07:00
fdaaf3950f07 b @ 2001-02-03 04:05:13.000 +07:00
@ -303,12 +317,13 @@ fn test_rebase_duplicates() {
000000000000 @ 1970-01-01 00:00:00.000 +00:00
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-s", "a", "-d", "a-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s", "a", "-d", "a-"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 4 commits
Working copy now at: zsuskuln 29bd36b6 b | b
Parent commit : rlvkpnrz 2f6dc5a1 a | a
"###);
insta::assert_snapshot!(stderr, @"");
// Some of the duplicate commits' timestamps were changed a little to make them
// have distinct commit ids.
insta::assert_snapshot!(get_log_output_with_ts(&test_env, &repo_path), @r###"

View file

@ -21,11 +21,11 @@ pub mod common;
#[test]
fn test_edit() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "0").unwrap();
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "second"]);
std::fs::write(repo_path.join("file1"), "1").unwrap();
// Errors out without argument
@ -40,27 +40,32 @@ fn test_edit() {
"###);
// Makes the specified commit the working-copy commit
let stdout = test_env.jj_cmd_success(&repo_path, &["edit", "@-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["edit", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: qpvuntsm f41390a5 first
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = get_log_output_with_stderr(&test_env, &repo_path);
insta::assert_snapshot!(stdout, @r###"
b2f7e9c549aa second
@ f41390a5efbf first
000000000000
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(read_file(&repo_path.join("file1")), @"0");
// Changes in the working copy are amended into the commit
std::fs::write(repo_path.join("file2"), "0").unwrap();
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
let (stdout, stderr) = get_log_output_with_stderr(&test_env, &repo_path);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits onto updated working copy
51d937a3eeb4 second
@ 409306de8f44 first
000000000000
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
@ -72,11 +77,11 @@ fn test_edit_current_wc_commit_missing() {
// Test that we get a reasonable error message when the current working-copy
// commit is missing
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["edit", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["edit", "@-"]);
let wc_id = test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-T=commit_id", "-r=@"]);
let wc_child_id =
@ -106,7 +111,7 @@ fn read_file(path: &Path) -> String {
String::from_utf8(std::fs::read(path).unwrap()).unwrap()
}
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
fn get_log_output_with_stderr(test_env: &TestEnvironment, cwd: &Path) -> (String, String) {
let template = r#"commit_id.short() ++ " " ++ description"#;
test_env.jj_cmd_success(cwd, &["log", "-T", template])
test_env.jj_cmd_ok(cwd, &["log", "-T", template])
}

View file

@ -23,11 +23,13 @@ fn test_git_clone() {
let git_repo = git2::Repository::init(git_repo_path).unwrap();
// Clone an empty repo
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "source", "empty"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "empty"]);
insta::assert_snapshot!(stdout, @r###"
Fetching into new repo in "$TEST_ENV/empty"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
// Set-up a non-empty repo
let signature =
@ -52,20 +54,24 @@ fn test_git_clone() {
git_repo.set_head("refs/heads/main").unwrap();
// Clone with relative source path
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "source", "clone"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "clone"]);
insta::assert_snapshot!(stdout, @r###"
Fetching into new repo in "$TEST_ENV/clone"
Working copy now at: uuqppmxq 1f0b881a (empty) (no description set)
Parent commit : mzyxwzks 9f01a0e0 main | message
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
assert!(test_env.env_root().join("clone").join("file").exists());
// Subsequent fetch should just work even if the source path was relative
let stdout = test_env.jj_cmd_success(&test_env.env_root().join("clone"), &["git", "fetch"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&test_env.env_root().join("clone"), &["git", "fetch"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
// Failed clone should clean up the destination directory
std::fs::create_dir(test_env.env_root().join("bad")).unwrap();
@ -135,7 +141,7 @@ fn test_git_clone_colocate() {
let git_repo = git2::Repository::init(git_repo_path).unwrap();
// Clone an empty repo
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
test_env.env_root(),
&["git", "clone", "source", "empty", "--colocate"],
);
@ -143,6 +149,7 @@ fn test_git_clone_colocate() {
Fetching into new repo in "$TEST_ENV/empty"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
// Set-up a non-empty repo
let signature =
@ -167,7 +174,7 @@ fn test_git_clone_colocate() {
git_repo.set_head("refs/heads/main").unwrap();
// Clone with relative source path
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
test_env.env_root(),
&["git", "clone", "source", "clone", "--colocate"],
);
@ -177,6 +184,7 @@ fn test_git_clone_colocate() {
Parent commit : mzyxwzks 9f01a0e0 main | message
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
assert!(test_env.env_root().join("clone").join("file").exists());
assert!(test_env.env_root().join("clone").join(".git").exists());
@ -217,10 +225,12 @@ fn test_git_clone_colocate() {
"###);
// Subsequent fetch should just work even if the source path was relative
let stdout = test_env.jj_cmd_success(&test_env.env_root().join("clone"), &["git", "fetch"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&test_env.env_root().join("clone"), &["git", "fetch"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
// Failed clone should clean up the destination directory
std::fs::create_dir(test_env.env_root().join("bad")).unwrap();

View file

@ -57,7 +57,7 @@ fn test_git_colocated() {
);
// Import the repo
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
@ 3e9369cd54227eb88455e1834dbc08aad6a16ac4
e61b6729ff4292870702f2f72b2a60165679ef37 master HEAD@git initial
@ -82,7 +82,7 @@ fn test_git_colocated() {
);
// Create a new change from jj and check that it's reflected in Git
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
@ 9dbb23ff2ff5e66c43880f1042369d704f7a321e
b26951a9c6f5c270e4d039880208952fd5faae5e HEAD@git
@ -114,7 +114,7 @@ fn test_git_colocated_unborn_branch() {
};
// Initially, HEAD isn't set.
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
assert!(git_repo.head().is_err());
assert_eq!(
git_repo.find_reference("HEAD").unwrap().symbolic_target(),
@ -127,12 +127,13 @@ fn test_git_colocated_unborn_branch() {
// Stage some change, and check out root. This shouldn't clobber the HEAD.
add_file_to_index("file0", "");
insta::assert_snapshot!(
test_env.jj_cmd_success(&workspace_root, &["checkout", "root()"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["checkout", "root()"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: kkmpptxz fcdbbd73 (empty) (no description set)
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
Added 0 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
assert!(git_repo.head().is_err());
assert_eq!(
git_repo.find_reference("HEAD").unwrap().symbolic_target(),
@ -155,10 +156,12 @@ fn test_git_colocated_unborn_branch() {
// Stage some change, and create new HEAD. This shouldn't move the default
// branch.
add_file_to_index("file1", "");
insta::assert_snapshot!(test_env.jj_cmd_success(&workspace_root, &["new"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["new"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: royxmykx 76c60bf0 (empty) (no description set)
Parent commit : kkmpptxz f8d5bc77 (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
assert!(git_repo.head().unwrap().symbolic_target().is_none());
insta::assert_snapshot!(
git_repo.head().unwrap().peel_to_commit().unwrap().id().to_string(),
@ -180,17 +183,18 @@ fn test_git_colocated_unborn_branch() {
"###);
// Assign the default branch. The branch is no longer "unborn".
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "-r@-", "master"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "-r@-", "master"]);
// Stage some change, and check out root again. This should unset the HEAD.
// https://github.com/martinvonz/jj/issues/1495
add_file_to_index("file2", "");
insta::assert_snapshot!(
test_env.jj_cmd_success(&workspace_root, &["checkout", "root()"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["checkout", "root()"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: znkkpsqq 10dd328b (empty) (no description set)
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(stderr, @"");
assert!(git_repo.head().is_err());
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
@ 10dd328bb906e15890e55047740eab2812a3b2f7
@ -211,10 +215,12 @@ fn test_git_colocated_unborn_branch() {
// New snapshot and commit can be created after the HEAD got unset.
std::fs::write(workspace_root.join("file3"), "").unwrap();
insta::assert_snapshot!(test_env.jj_cmd_success(&workspace_root, &["new"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["new"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: wqnwkozp cab23370 (empty) (no description set)
Parent commit : znkkpsqq 8f5b2638 (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
@ cab233704a5c0b21bde070943055f22142fb2043
8f5b263819457712a2937428b9c58a2a84afbb1c HEAD@git
@ -235,11 +241,11 @@ fn test_git_colocated_export_branches_on_snapshot() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
let git_repo = git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
// Create branch pointing to the initial commit
std::fs::write(workspace_root.join("file"), "initial").unwrap();
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "foo"]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
@ 438471f3fbf1004298d8fb01eeb13663a051a643 foo
0000000000000000000000000000000000000000
@ -265,17 +271,17 @@ fn test_git_colocated_rebase_on_import() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
let git_repo = git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
// Make some changes in jj and check that they're reflected in git
std::fs::write(workspace_root.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&workspace_root, &["commit", "-m", "add a file"]);
test_env.jj_cmd_ok(&workspace_root, &["commit", "-m", "add a file"]);
std::fs::write(workspace_root.join("file"), "modified").unwrap();
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "master"]);
test_env.jj_cmd_success(&workspace_root, &["commit", "-m", "modify a file"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "master"]);
test_env.jj_cmd_ok(&workspace_root, &["commit", "-m", "modify a file"]);
// TODO: We shouldn't need this command here to trigger an import of the
// refs/heads/master we just exported
test_env.jj_cmd_success(&workspace_root, &["st"]);
test_env.jj_cmd_ok(&workspace_root, &["st"]);
// Move `master` and HEAD backwards, which should result in commit2 getting
// hidden, and a new working-copy commit at the new position.
@ -289,13 +295,15 @@ fn test_git_colocated_rebase_on_import() {
let commit1 = commit2.parents().next().unwrap();
git_repo.branch("master", &commit1, true).unwrap();
git_repo.set_head("refs/heads/master").unwrap();
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
let (stdout, stderr) = get_log_output_with_stderr(&test_env, &workspace_root);
insta::assert_snapshot!(stdout, @r###"
Abandoned 1 commits that are no longer reachable.
Done importing changes from the underlying Git repo.
@ 7f96185cfbe36341d0f9a86ebfaeab67a5922c7e
4bcbeaba9a4b309c5f45a8807fbf5499b9714315 master HEAD@git add a file
0000000000000000000000000000000000000000
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
@ -303,9 +311,9 @@ fn test_git_colocated_branches() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
let git_repo = git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_success(&workspace_root, &["new", "-m", "foo"]);
test_env.jj_cmd_success(&workspace_root, &["new", "@-", "-m", "bar"]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["new", "-m", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "@-", "-m", "bar"]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
@ 3560559274ab431feea00b7b7e0b9250ecce951f bar
1e6f0b403ed2ff9713b5d6b1dc601e4804250cda foo
@ -316,7 +324,7 @@ fn test_git_colocated_branches() {
// Create a branch in jj. It should be exported to Git even though it points to
// the working- copy commit.
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "master"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "master"]);
insta::assert_snapshot!(
git_repo.find_reference("refs/heads/master").unwrap().target().unwrap().to_string(),
@"3560559274ab431feea00b7b7e0b9250ecce951f"
@ -339,7 +347,8 @@ fn test_git_colocated_branches() {
"test",
)
.unwrap();
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
let (stdout, stderr) = get_log_output_with_stderr(&test_env, &workspace_root);
insta::assert_snapshot!(stdout, @r###"
Abandoned 1 commits that are no longer reachable.
Working copy now at: yqosqzyt 096dc80d (empty) (no description set)
Parent commit : qpvuntsm 230dd059 (empty) (no description set)
@ -350,6 +359,7 @@ fn test_git_colocated_branches() {
230dd059e1b059aefc0da06a2e5a7dbf22362f22 HEAD@git
0000000000000000000000000000000000000000
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
@ -357,9 +367,9 @@ fn test_git_colocated_branch_forget() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
let _git_repo = git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "foo"]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
@ 65b6b74e08973b88d38404430f119c8c79465250 foo
230dd059e1b059aefc0da06a2e5a7dbf22362f22 HEAD@git
@ -370,8 +380,9 @@ fn test_git_colocated_branch_forget() {
foo: rlvkpnrz 65b6b74e (empty) (no description set)
"###);
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "forget", "foo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["branch", "forget", "foo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
// A forgotten branch is deleted in the git repo. For a detailed demo explaining
// this, see `test_branch_forget_export` in `test_branch_command.rs`.
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
@ -383,8 +394,8 @@ fn test_git_colocated_conflicting_git_refs() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "main"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "main/sub"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
@ -401,18 +412,18 @@ fn test_git_colocated_fetch_deleted_or_moved_branch() {
let test_env = TestEnvironment::default();
let origin_path = test_env.env_root().join("origin");
git2::Repository::init(&origin_path).unwrap();
test_env.jj_cmd_success(&origin_path, &["init", "--git-repo=."]);
test_env.jj_cmd_success(&origin_path, &["describe", "-m=A"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "A"]);
test_env.jj_cmd_success(&origin_path, &["new", "-m=B_to_delete"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "B_to_delete"]);
test_env.jj_cmd_success(&origin_path, &["new", "-m=original C", "@-"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "C_to_move"]);
test_env.jj_cmd_ok(&origin_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&origin_path, &["describe", "-m=A"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "A"]);
test_env.jj_cmd_ok(&origin_path, &["new", "-m=B_to_delete"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "B_to_delete"]);
test_env.jj_cmd_ok(&origin_path, &["new", "-m=original C", "@-"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "C_to_move"]);
let clone_path = test_env.env_root().join("clone");
git2::Repository::clone(origin_path.to_str().unwrap(), &clone_path).unwrap();
test_env.jj_cmd_success(&clone_path, &["init", "--git-repo=."]);
test_env.jj_cmd_success(&clone_path, &["new", "A"]);
test_env.jj_cmd_ok(&clone_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&clone_path, &["new", "A"]);
insta::assert_snapshot!(get_log_output(&test_env, &clone_path), @r###"
@ 0335878796213c3a701f1c9c34dcae242bee4131
8d4e006fd63547965fbc3a26556a9aa531076d32 C_to_move original C
@ -423,13 +434,14 @@ fn test_git_colocated_fetch_deleted_or_moved_branch() {
0000000000000000000000000000000000000000
"###);
test_env.jj_cmd_success(&origin_path, &["branch", "delete", "B_to_delete"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "delete", "B_to_delete"]);
// Move branch C sideways
test_env.jj_cmd_success(&origin_path, &["describe", "C_to_move", "-m", "moved C"]);
let stdout = test_env.jj_cmd_success(&clone_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&origin_path, &["describe", "C_to_move", "-m", "moved C"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&clone_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @r###"
Abandoned 2 commits that are no longer reachable.
"###);
insta::assert_snapshot!(stderr, @"");
// "original C" and "B_to_delete" are abandoned, as the corresponding branches
// were deleted or moved on the remote (#864)
insta::assert_snapshot!(get_log_output(&test_env, &clone_path), @r###"
@ -446,11 +458,11 @@ fn test_git_colocated_external_checkout() {
let test_env = TestEnvironment::default();
let repo_path = test_env.env_root().join("repo");
let git_repo = git2::Repository::init(&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, &["branch", "set", "-r@-", "master"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m=B", "root()"]);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&repo_path, &["ci", "-m=A"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "-r@-", "master"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m=B", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
// Checked out anonymous branch
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ -474,7 +486,8 @@ fn test_git_colocated_external_checkout() {
// The old working-copy commit gets abandoned, but the whole branch should not
// be abandoned. (#1042)
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
let (stdout, stderr) = get_log_output_with_stderr(&test_env, &repo_path);
insta::assert_snapshot!(stdout, @r###"
Done importing changes from the underlying Git repo.
@ adadbd65a794e2294962b3c3da9aada09fe1b472
a86754f975f953fa25da4265764adc0c62e9ce6b master HEAD@git A
@ -482,6 +495,7 @@ fn test_git_colocated_external_checkout() {
0000000000000000000000000000000000000000
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
@ -489,8 +503,8 @@ fn test_git_colocated_squash_undo() {
let test_env = TestEnvironment::default();
let repo_path = test_env.env_root().join("repo");
git2::Repository::init(&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_ok(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&repo_path, &["ci", "-m=A"]);
// Test the setup
insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###"
@ rlvkpnrzqnoo 8f71e3b6a3be
@ -498,13 +512,13 @@ fn test_git_colocated_squash_undo() {
zzzzzzzzzzzz 000000000000
"###);
test_env.jj_cmd_success(&repo_path, &["squash"]);
test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###"
@ zsuskulnrvyr f0c12b0396d9
qpvuntsmwlqt 2f376ea1478c A HEAD@git
zzzzzzzzzzzz 000000000000
"###);
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
// TODO: There should be no divergence here; 2f376ea1478c should be hidden
// (#922)
insta::assert_snapshot!(get_log_output_divergence(&test_env, &repo_path), @r###"
@ -519,10 +533,10 @@ fn test_git_colocated_undo_head_move() {
let test_env = TestEnvironment::default();
let repo_path = test_env.env_root().join("repo");
let git_repo = git2::Repository::init(&repo_path).unwrap();
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&repo_path, &["init", "--git-repo=."]);
// Create new HEAD
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
insta::assert_snapshot!(
git_repo.head().unwrap().target().unwrap().to_string(),
@"230dd059e1b059aefc0da06a2e5a7dbf22362f22");
@ -533,7 +547,7 @@ fn test_git_colocated_undo_head_move() {
"###);
// HEAD should be unset
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
assert!(git_repo.head().is_err());
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
@ -541,8 +555,8 @@ fn test_git_colocated_undo_head_move() {
"###);
// Create commit on non-root commit
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 69b19f73cf584f162f078fb0d91c55ca39d10bc7
eb08b363bb5ef8ee549314260488980d7bbe8f63 HEAD@git
@ -554,10 +568,12 @@ fn test_git_colocated_undo_head_move() {
@"eb08b363bb5ef8ee549314260488980d7bbe8f63");
// HEAD should be moved back
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["undo"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: royxmykx eb08b363 (empty) (no description set)
Parent commit : qpvuntsm 230dd059 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(
git_repo.head().unwrap().target().unwrap().to_string(),
@"230dd059e1b059aefc0da06a2e5a7dbf22362f22");
@ -587,6 +603,14 @@ fn get_log_output(test_env: &TestEnvironment, workspace_root: &Path) -> String {
test_env.jj_cmd_success(workspace_root, &["log", "-T", template, "-r=all()"])
}
fn get_log_output_with_stderr(
test_env: &TestEnvironment,
workspace_root: &Path,
) -> (String, String) {
let template = r#"separate(" ", commit_id, branches, git_head, description)"#;
test_env.jj_cmd_ok(workspace_root, &["log", "-T", template, "-r=all()"])
}
#[test]
fn test_git_colocated_unreachable_commits() {
let test_env = TestEnvironment::default();
@ -641,7 +665,7 @@ fn test_git_colocated_unreachable_commits() {
);
// Import the repo while there is no path to the second commit
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
@ 66ae47cee4f8c28ee8d7e4f5d9401b03c07e22f2
2ee37513d2b5e549f7478c671a780053614bff19 master HEAD@git initial

View file

@ -45,7 +45,7 @@ fn init_git_remote(test_env: &TestEnvironment, remote: &str) {
/// Add a remote containing a branch with the same name
fn add_git_remote(test_env: &TestEnvironment, repo_path: &Path, remote: &str) {
init_git_remote(test_env, remote);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
repo_path,
&["git", "remote", "add", remote, &format!("../{remote}")],
);
@ -58,14 +58,14 @@ fn get_branch_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, parents: &[&str]) {
let descr = format!("descr_for_{name}");
if parents.is_empty() {
test_env.jj_cmd_success(repo_path, &["new", "root()", "-m", &descr]);
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", &descr]);
} else {
let mut args = vec!["new", "-m", &descr];
args.extend(parents);
test_env.jj_cmd_success(repo_path, &args);
test_env.jj_cmd_ok(repo_path, &args);
}
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
}
fn get_log_output(test_env: &TestEnvironment, workspace_root: &Path) -> String {
@ -76,11 +76,11 @@ fn get_log_output(test_env: &TestEnvironment, workspace_root: &Path) -> String {
#[test]
fn test_git_fetch_default_remote() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "origin");
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin: oputwtnw ffecd2d6 message
"###);
@ -89,7 +89,7 @@ fn test_git_fetch_default_remote() {
#[test]
fn test_git_fetch_single_remote() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
@ -106,7 +106,7 @@ fn test_git_fetch_single_remote() {
#[test]
fn test_git_fetch_single_remote_all_remotes_flag() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
@ -122,11 +122,11 @@ fn test_git_fetch_single_remote_all_remotes_flag() {
#[test]
fn test_git_fetch_single_remote_from_arg() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote", "rem1"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote", "rem1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
rem1: qxosxrvv 6a211027 message
"###);
@ -135,12 +135,12 @@ fn test_git_fetch_single_remote_from_arg() {
#[test]
fn test_git_fetch_single_remote_from_config() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
test_env.add_config(r#"git.fetch = "rem1""#);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
rem1: qxosxrvv 6a211027 message
"###);
@ -149,12 +149,12 @@ fn test_git_fetch_single_remote_from_config() {
#[test]
fn test_git_fetch_multiple_remotes() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
add_git_remote(&test_env, &repo_path, "rem2");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "fetch", "--remote", "rem1", "--remote", "rem2"],
);
@ -167,12 +167,12 @@ fn test_git_fetch_multiple_remotes() {
#[test]
fn test_git_fetch_all_remotes() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
add_git_remote(&test_env, &repo_path, "rem2");
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--all-remotes"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--all-remotes"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
rem1: qxosxrvv 6a211027 message
rem2: yszkquru 2497a8a0 message
@ -182,13 +182,13 @@ fn test_git_fetch_all_remotes() {
#[test]
fn test_git_fetch_multiple_remotes_from_config() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
add_git_remote(&test_env, &repo_path, "rem2");
test_env.add_config(r#"git.fetch = ["rem1", "rem2"]"#);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
rem1: qxosxrvv 6a211027 message
rem2: yszkquru 2497a8a0 message
@ -198,7 +198,7 @@ fn test_git_fetch_multiple_remotes_from_config() {
#[test]
fn test_git_fetch_nonexistent_remote() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
@ -216,7 +216,7 @@ fn test_git_fetch_nonexistent_remote() {
#[test]
fn test_git_fetch_nonexistent_remote_from_config() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
test_env.add_config(r#"git.fetch = ["rem1", "rem2"]"#);
@ -238,7 +238,7 @@ fn test_git_fetch_from_remote_named_git() {
git_repo.remote("git", "../git").unwrap();
// Existing remote named 'git' shouldn't block the repo initialization.
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&repo_path, &["init", "--git-repo=."]);
// Try fetching from the remote named 'git'.
let stderr = &test_env.jj_cmd_failure(&repo_path, &["git", "fetch", "--remote=git"]);
@ -248,8 +248,9 @@ fn test_git_fetch_from_remote_named_git() {
"###);
// Implicit import shouldn't fail because of the remote ref.
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "list"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
// Explicit import is an error.
// (This could be warning if we add mechanism to report ignored refs.)
@ -259,21 +260,22 @@ fn test_git_fetch_from_remote_named_git() {
"###);
// The remote can be renamed, and the ref can be imported.
test_env.jj_cmd_success(&repo_path, &["git", "remote", "rename", "git", "bar"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
test_env.jj_cmd_ok(&repo_path, &["git", "remote", "rename", "git", "bar"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "list"]);
insta::assert_snapshot!(stdout, @r###"
Done importing changes from the underlying Git repo.
git: mrylzrtu 76fc7466 message
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_git_fetch_prune_before_updating_tips() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "origin");
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin: oputwtnw ffecd2d6 message
"###);
@ -286,7 +288,7 @@ fn test_git_fetch_prune_before_updating_tips() {
.rename("origin/subname", false)
.unwrap();
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin/subname: oputwtnw ffecd2d6 message
"###);
@ -295,18 +297,18 @@ fn test_git_fetch_prune_before_updating_tips() {
#[test]
fn test_git_fetch_conflicting_branches() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "rem1");
// Create a rem1 branch locally
test_env.jj_cmd_success(&repo_path, &["new", "root()"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "rem1"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "rem1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
rem1: kkmpptxz fcdbbd73 (empty) (no description set)
"###);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "fetch", "--remote", "rem1", "--branch", "*"],
);
@ -325,18 +327,18 @@ fn test_git_fetch_conflicting_branches_colocated() {
let repo_path = test_env.env_root().join("repo");
let _git_repo = git2::Repository::init(&repo_path).unwrap();
// create_colocated_repo_and_branches_from_trunk1(&test_env, &repo_path);
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&repo_path, &["init", "--git-repo", "."]);
add_git_remote(&test_env, &repo_path, "rem1");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
// Create a rem1 branch locally
test_env.jj_cmd_success(&repo_path, &["new", "root()"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "rem1"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "rem1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
rem1: zsuskuln f652c321 (empty) (no description set)
"###);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "fetch", "--remote", "rem1", "--branch", "rem1"],
);
@ -358,7 +360,7 @@ fn create_colocated_repo_and_branches_from_trunk1(
repo_path: &Path,
) -> String {
// Create a colocated repo in `source` to populate it more easily
test_env.jj_cmd_success(repo_path, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(repo_path, &["init", "--git-repo", "."]);
create_commit(test_env, repo_path, "trunk1", &[]);
create_commit(test_env, repo_path, "a1", &["trunk1"]);
create_commit(test_env, repo_path, "a2", &["trunk1"]);
@ -372,7 +374,7 @@ fn create_colocated_repo_and_branches_from_trunk1(
fn create_trunk2_and_rebase_branches(test_env: &TestEnvironment, repo_path: &Path) -> String {
create_commit(test_env, repo_path, "trunk2", &["trunk1"]);
for br in ["a1", "a2", "b"] {
test_env.jj_cmd_success(repo_path, &["rebase", "-b", br, "-d", "trunk2"]);
test_env.jj_cmd_ok(repo_path, &["rebase", "-b", br, "-d", "trunk2"]);
}
format!(
" ===== Source git repo contents =====\n{}",
@ -388,12 +390,13 @@ fn test_git_fetch_all() {
let _git_repo = git2::Repository::init(source_git_repo_path.clone()).unwrap();
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated
let stdout =
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "source", "target"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "target"]);
insta::assert_snapshot!(stdout, @r###"
Fetching into new repo in "$TEST_ENV/target"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let target_jj_repo_path = test_env.env_root().join("target");
let source_log =
@ -415,7 +418,9 @@ fn test_git_fetch_all() {
000000000000
"###);
insta::assert_snapshot!(get_branch_output(&test_env, &target_jj_repo_path), @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &target_jj_repo_path), @r###"
a1: nknoxmzm 359a9a02 descr_for_a1
a2: qkvnknrk decaa396 descr_for_a2
@ -449,7 +454,7 @@ fn test_git_fetch_all() {
000000000000
"###);
// Change a branch in the source repo as well, so that it becomes conflicted.
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&target_jj_repo_path,
&["describe", "b", "-m=new_descr_for_b_to_create_conflict"],
);
@ -473,9 +478,11 @@ fn test_git_fetch_all() {
@origin (ahead by 1 commits, behind by 1 commits): vpupmnsl c7d4bdcb descr_for_b
trunk1: zowqyktl ff36dc55 descr_for_trunk1
"###);
insta::assert_snapshot!(test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @r###"
Abandoned 2 commits that are no longer reachable.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &target_jj_repo_path), @r###"
a1: quxllqov 0424f6df descr_for_a1
a2: osusxwst 91e46b4b descr_for_a2
@ -511,12 +518,13 @@ fn test_git_fetch_some_of_many_branches() {
let _git_repo = git2::Repository::init(source_git_repo_path.clone()).unwrap();
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated
let stdout =
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "source", "target"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "target"]);
insta::assert_snapshot!(stdout, @r###"
Fetching into new repo in "$TEST_ENV/target"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let target_jj_repo_path = test_env.env_root().join("target");
let source_log =
@ -545,8 +553,10 @@ fn test_git_fetch_some_of_many_branches() {
000000000000
"###);
// Fetch one branch...
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch", "--branch", "b"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch", "--branch", "b"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
c7d4bdcbc215 descr_for_b b
ff36dc55760e descr_for_trunk1
@ -559,8 +569,10 @@ fn test_git_fetch_some_of_many_branches() {
b: vpupmnsl c7d4bdcb descr_for_b
"###);
// ...then fetch two others with a glob.
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch", "--branch", "a*"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch", "--branch", "a*"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
decaa3966c83 descr_for_a2 a2
359a9a02457d descr_for_a1 a1
@ -573,10 +585,12 @@ fn test_git_fetch_some_of_many_branches() {
000000000000
"###);
// Fetching the same branch again
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch", "--branch", "a1"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch", "--branch", "a1"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
decaa3966c83 descr_for_a2 a2
359a9a02457d descr_for_a1 a1
@ -604,7 +618,7 @@ fn test_git_fetch_some_of_many_branches() {
000000000000
"###);
// Change a branch in the source repo as well, so that it becomes conflicted.
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&target_jj_repo_path,
&["describe", "b", "-m=new_descr_for_b_to_create_conflict"],
);
@ -621,13 +635,14 @@ fn test_git_fetch_some_of_many_branches() {
000000000000
"###);
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&target_jj_repo_path,
&["git", "fetch", "--branch", "b", "--branch", "a1"],
);
insta::assert_snapshot!(stdout, @r###"
Abandoned 1 commits that are no longer reachable.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
13ac032802f1 descr_for_b b?? b@origin
6f4e1c4dfe29 descr_for_a1 a1
@ -655,13 +670,14 @@ fn test_git_fetch_some_of_many_branches() {
"###);
// Now, let's fetch a2 and double-check that fetching a1 and b again doesn't do
// anything.
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&target_jj_repo_path,
&["git", "fetch", "--branch", "b", "--branch", "a*"],
);
insta::assert_snapshot!(stdout, @r###"
Abandoned 1 commits that are no longer reachable.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
010977d69c5b descr_for_a2 a2
13ac032802f1 descr_for_b b?? b@origin
@ -696,12 +712,13 @@ fn test_git_fetch_undo() {
let _git_repo = git2::Repository::init(source_git_repo_path.clone()).unwrap();
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated
let stdout =
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "source", "target"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "target"]);
insta::assert_snapshot!(stdout, @r###"
Fetching into new repo in "$TEST_ENV/target"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let target_jj_repo_path = test_env.env_root().join("target");
let source_log =
@ -718,11 +735,12 @@ fn test_git_fetch_undo() {
"###);
// Fetch 2 branches
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&target_jj_repo_path,
&["git", "fetch", "--branch", "b", "--branch", "a1"],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
c7d4bdcbc215 descr_for_b b
359a9a02457d descr_for_a1 a1
@ -732,15 +750,19 @@ fn test_git_fetch_undo() {
000000000000
"###);
insta::assert_snapshot!(test_env.jj_cmd_success(&target_jj_repo_path, &["undo"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&target_jj_repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
// The undo works as expected
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
@ 230dd059e1b0
000000000000
"###);
// Now try to fetch just one branch
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch", "--branch", "b"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch", "--branch", "b"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
c7d4bdcbc215 descr_for_b b
ff36dc55760e descr_for_trunk1
@ -759,12 +781,13 @@ fn test_fetch_undo_what() {
let _git_repo = git2::Repository::init(source_git_repo_path.clone()).unwrap();
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated
let stdout =
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "source", "target"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "target"]);
insta::assert_snapshot!(stdout, @r###"
Fetching into new repo in "$TEST_ENV/target"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let repo_path = test_env.env_root().join("target");
let source_log =
@ -786,8 +809,9 @@ fn test_fetch_undo_what() {
let base_operation_id = test_env.current_operation_id(&repo_path);
// Fetch a branch
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--branch", "b"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--branch", "b"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
c7d4bdcbc215 descr_for_b b
ff36dc55760e descr_for_trunk1
@ -800,11 +824,12 @@ fn test_fetch_undo_what() {
"###);
// We can undo the change in the repo without moving the remote-tracking branch
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["op", "restore", "--what", "repo", &base_operation_id],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
b (deleted)
@origin: vpupmnsl c7d4bdcb descr_for_b
@ -814,7 +839,7 @@ fn test_fetch_undo_what() {
// Now, let's demo restoring just the remote-tracking branch. First, let's
// change our local repo state...
test_env.jj_cmd_success(&repo_path, &["branch", "c", "newbranch"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "c", "newbranch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
b (deleted)
@origin: vpupmnsl c7d4bdcb descr_for_b
@ -824,7 +849,7 @@ fn test_fetch_undo_what() {
"###);
// Restoring just the remote-tracking state will not affect `newbranch`, but
// will eliminate `b@origin`.
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&[
"op",
@ -835,6 +860,7 @@ fn test_fetch_undo_what() {
],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
newbranch: qpvuntsm 230dd059 (empty) (no description set)
"###);
@ -843,16 +869,16 @@ fn test_fetch_undo_what() {
#[test]
fn test_git_fetch_remove_fetch() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "origin");
test_env.jj_cmd_success(&repo_path, &["branch", "set", "origin"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "origin"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin: qpvuntsm 230dd059 (empty) (no description set)
"###);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin (conflicted):
+ qpvuntsm 230dd059 (empty) (no description set)
@ -860,18 +886,19 @@ fn test_git_fetch_remove_fetch() {
@origin (behind by 1 commits): oputwtnw ffecd2d6 message
"###);
test_env.jj_cmd_success(&repo_path, &["git", "remote", "remove", "origin"]);
test_env.jj_cmd_ok(&repo_path, &["git", "remote", "remove", "origin"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin (conflicted):
+ qpvuntsm 230dd059 (empty) (no description set)
+ oputwtnw ffecd2d6 message
"###);
test_env.jj_cmd_success(&repo_path, &["git", "remote", "add", "origin", "../origin"]);
test_env.jj_cmd_ok(&repo_path, &["git", "remote", "add", "origin", "../origin"]);
// Check that origin@origin is properly recreated
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin (conflicted):
+ qpvuntsm 230dd059 (empty) (no description set)
@ -883,16 +910,16 @@ fn test_git_fetch_remove_fetch() {
#[test]
fn test_git_fetch_rename_fetch() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "origin");
test_env.jj_cmd_success(&repo_path, &["branch", "set", "origin"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "origin"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin: qpvuntsm 230dd059 (empty) (no description set)
"###);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin (conflicted):
+ qpvuntsm 230dd059 (empty) (no description set)
@ -900,7 +927,7 @@ fn test_git_fetch_rename_fetch() {
@origin (behind by 1 commits): oputwtnw ffecd2d6 message
"###);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "rename", "origin", "upstream"],
);
@ -912,10 +939,12 @@ fn test_git_fetch_rename_fetch() {
"###);
// Check that jj indicates that nothing has changed
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote", "upstream"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote", "upstream"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
@ -925,12 +954,13 @@ fn test_git_fetch_removed_branch() {
let _git_repo = git2::Repository::init(source_git_repo_path.clone()).unwrap();
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated
let stdout =
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "source", "target"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "target"]);
insta::assert_snapshot!(stdout, @r###"
Fetching into new repo in "$TEST_ENV/target"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let target_jj_repo_path = test_env.env_root().join("target");
let source_log =
@ -947,8 +977,9 @@ fn test_git_fetch_removed_branch() {
"###);
// Fetch all branches
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
c7d4bdcbc215 descr_for_b b
decaa3966c83 descr_for_a2 a2
@ -962,13 +993,15 @@ fn test_git_fetch_removed_branch() {
"###);
// Remove a2 branch in origin
test_env.jj_cmd_success(&source_git_repo_path, &["branch", "forget", "a2"]);
test_env.jj_cmd_ok(&source_git_repo_path, &["branch", "forget", "a2"]);
// Fetch branch a1 from origin and check that a2 is still there
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch", "--branch", "a1"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch", "--branch", "a1"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
c7d4bdcbc215 descr_for_b b
decaa3966c83 descr_for_a2 a2
@ -982,10 +1015,12 @@ fn test_git_fetch_removed_branch() {
"###);
// Fetch branches a2 from origin, and check that it has been removed locally
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch", "--branch", "a2"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch", "--branch", "a2"]);
insta::assert_snapshot!(stdout, @r###"
Abandoned 1 commits that are no longer reachable.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
c7d4bdcbc215 descr_for_b b
359a9a02457d descr_for_a1 a1
@ -1004,12 +1039,13 @@ fn test_git_fetch_removed_parent_branch() {
let _git_repo = git2::Repository::init(source_git_repo_path.clone()).unwrap();
// Clone an empty repo. The target repo is a normal `jj` repo, *not* colocated
let stdout =
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "source", "target"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "target"]);
insta::assert_snapshot!(stdout, @r###"
Fetching into new repo in "$TEST_ENV/target"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
let target_jj_repo_path = test_env.env_root().join("target");
let source_log =
@ -1026,8 +1062,9 @@ fn test_git_fetch_removed_parent_branch() {
"###);
// Fetch all branches
let stdout = test_env.jj_cmd_success(&target_jj_repo_path, &["git", "fetch"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&target_jj_repo_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
c7d4bdcbc215 descr_for_b b
decaa3966c83 descr_for_a2 a2
@ -1041,12 +1078,12 @@ fn test_git_fetch_removed_parent_branch() {
"###);
// Remove all branches in origin.
test_env.jj_cmd_success(&source_git_repo_path, &["branch", "forget", "--glob", "*"]);
test_env.jj_cmd_ok(&source_git_repo_path, &["branch", "forget", "--glob", "*"]);
// Fetch branches master, trunk1 and a1 from origin and check that only those
// branches have been removed and that others were not rebased because of
// abandoned commits.
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&target_jj_repo_path,
&[
"git", "fetch", "--branch", "master", "--branch", "trunk1", "--branch", "a1",
@ -1055,6 +1092,7 @@ fn test_git_fetch_removed_parent_branch() {
insta::assert_snapshot!(stdout, @r###"
Abandoned 1 commits that are no longer reachable.
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
c7d4bdcbc215 descr_for_b b
decaa3966c83 descr_for_a2 a2
@ -1069,7 +1107,7 @@ fn test_git_fetch_removed_parent_branch() {
#[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"]);
test_env.jj_cmd_ok(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
@ -1084,7 +1122,7 @@ fn test_git_fetch_remote_only_branch() {
.unwrap();
let tree_oid = tree_builder.write().unwrap();
let tree = git_repo.find_tree(tree_oid).unwrap();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "origin", "../git-repo"],
);
@ -1101,7 +1139,7 @@ fn test_git_fetch_remote_only_branch() {
.unwrap();
// Fetch normally
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1: mzyxwzks 9f01a0e0 message
"###);
@ -1119,7 +1157,7 @@ fn test_git_fetch_remote_only_branch() {
// 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"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch", "--remote=origin"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1: mzyxwzks 9f01a0e0 message
feature2 (deleted)

View file

@ -23,16 +23,17 @@ pub mod common;
#[test]
fn test_resolution_of_git_tracking_branches() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-r", "main", "-m", "old_message"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-r", "main", "-m", "old_message"]);
// Create local-git tracking branch
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "export"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
// Move the local branch somewhere else
test_env.jj_cmd_success(&repo_path, &["describe", "-r", "main", "-m", "new_message"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-r", "main", "-m", "new_message"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
main: qpvuntsm 3af37026 (empty) new_message
@git (ahead by 1 commits, behind by 1 commits): qpvuntsm 16d541ca (empty) old_message
@ -60,11 +61,11 @@ fn test_resolution_of_git_tracking_branches() {
#[test]
fn test_git_export_conflicting_git_refs() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main/sub"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main/sub"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
@ -79,15 +80,17 @@ fn test_git_export_conflicting_git_refs() {
#[test]
fn test_git_export_undo() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let git_repo = git2::Repository::open(repo_path.join(".jj/repo/store/git")).unwrap();
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: qpvuntsm 230dd059 (empty) (no description set)
"###);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "export"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["log", "-ra@git"]), @r###"
@ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 a 230dd059
(empty) (no description set)
@ -96,8 +99,9 @@ fn test_git_export_undo() {
// Exported refs won't be removed by undoing the export, but the git-tracking
// branch is. This is the same as remote-tracking branches.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["op", "undo"]), @r###"
"###);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r###"
[
(
@ -114,7 +118,9 @@ fn test_git_export_undo() {
"###);
// This would re-export branch "a" and create git-tracking branch.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "export"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["log", "-ra@git"]), @r###"
@ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 a 230dd059
(empty) (no description set)
@ -125,7 +131,7 @@ fn test_git_export_undo() {
#[test]
fn test_git_import_undo() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let git_repo = git2::Repository::open(repo_path.join(".jj/repo/store/git")).unwrap();
@ -141,18 +147,22 @@ fn test_git_import_undo() {
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
let base_operation_id = test_env.current_operation_id(&repo_path);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "import"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: qpvuntsm 230dd059 (empty) (no description set)
"###);
// "git import" can be undone by default.
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @r###"
"###);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
// Try "git import" again, which should re-import the branch "a".
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "import"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: qpvuntsm 230dd059 (empty) (no description set)
"###);
@ -161,7 +171,7 @@ fn test_git_import_undo() {
#[test]
fn test_git_import_move_export_with_default_undo() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let git_repo = git2::Repository::open(repo_path.join(".jj/repo/store/git")).unwrap();
@ -178,19 +188,23 @@ fn test_git_import_move_export_with_default_undo() {
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
let base_operation_id = test_env.current_operation_id(&repo_path);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "import"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: qpvuntsm 230dd059 (empty) (no description set)
"###);
// Move branch "a" and export to git repo
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "a"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "a"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: yqosqzyt 096dc80d (empty) (no description set)
@git (behind by 1 commits): qpvuntsm 230dd059 (empty) (no description set)
"###);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "export"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: yqosqzyt 096dc80d (empty) (no description set)
"###);
@ -198,10 +212,12 @@ fn test_git_import_move_export_with_default_undo() {
// "git import" can be undone with the default `restore` behavior, as shown in
// the previous test. However, "git export" can't: the branches in the git
// repo stay where they were.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["op", "restore", &base_operation_id]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: qpvuntsm 230dd059 (empty) (no description set)
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @"");
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r###"
[
@ -216,7 +232,9 @@ fn test_git_import_move_export_with_default_undo() {
// The last branch "a" state is imported from git. No idea what's the most
// intuitive result here.
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["git", "import"]), @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "import"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
a: yqosqzyt 096dc80d (empty) (no description set)
"###);

View file

@ -20,7 +20,7 @@ pub mod common;
fn set_up() -> (TestEnvironment, PathBuf) {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "origin"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "origin"]);
let origin_path = test_env.env_root().join("origin");
let origin_git_repo_path = origin_path
.join(".jj")
@ -28,13 +28,13 @@ fn set_up() -> (TestEnvironment, PathBuf) {
.join("store")
.join("git");
test_env.jj_cmd_success(&origin_path, &["describe", "-m=description 1"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "branch1"]);
test_env.jj_cmd_success(&origin_path, &["new", "root()", "-m=description 2"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "branch2"]);
test_env.jj_cmd_success(&origin_path, &["git", "export"]);
test_env.jj_cmd_ok(&origin_path, &["describe", "-m=description 1"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "branch1"]);
test_env.jj_cmd_ok(&origin_path, &["new", "root()", "-m=description 2"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "branch2"]);
test_env.jj_cmd_ok(&origin_path, &["git", "export"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
test_env.env_root(),
&[
"git",
@ -51,10 +51,11 @@ fn set_up() -> (TestEnvironment, PathBuf) {
fn test_git_push_nothing() {
let (test_env, workspace_root) = set_up();
// No branches to push yet
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--all"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--all"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
@ -63,14 +64,14 @@ fn test_git_push_current_branch() {
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
// Update some branches. `branch1` is not a current branch, but `branch2` and
// `my-branch` are.
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&workspace_root,
&["describe", "branch1", "-m", "modified branch1 commit"],
);
test_env.jj_cmd_success(&workspace_root, &["co", "branch2"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "branch2"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "my-branch"]);
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["co", "branch2"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "branch2"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "my-branch"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m", "foo"]);
// Check the setup
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
insta::assert_snapshot!(stdout, @r###"
@ -81,19 +82,21 @@ fn test_git_push_current_branch() {
my-branch: yostqsxw 10ee3363 (empty) foo
"###);
// First dry-run. `branch1` should not get pushed.
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--dry-run"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--dry-run"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Move branch branch2 from 8476341eb395 to 10ee3363b259
Add branch my-branch to 10ee3363b259
Dry-run requested, not pushing.
"###);
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Move branch branch2 from 8476341eb395 to 10ee3363b259
Add branch my-branch to 10ee3363b259
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
insta::assert_snapshot!(stdout, @r###"
branch1: lzmmnrxq 19e00bf6 (empty) modified branch1 commit
@ -107,24 +110,25 @@ fn test_git_push_current_branch() {
fn test_git_push_parent_branch() {
let (test_env, workspace_root) = set_up();
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
test_env.jj_cmd_success(&workspace_root, &["edit", "branch1"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&workspace_root, &["edit", "branch1"]);
test_env.jj_cmd_ok(
&workspace_root,
&["describe", "-m", "modified branch1 commit"],
);
test_env.jj_cmd_success(&workspace_root, &["new", "-m", "non-empty description"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "-m", "non-empty description"]);
std::fs::write(workspace_root.join("file"), "file").unwrap();
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Force branch branch1 from 45a3aa29e907 to d47326d59ee1
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_git_push_no_matching_branch() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
@ -137,7 +141,7 @@ fn test_git_push_no_matching_branch() {
#[test]
fn test_git_push_matching_branch_unchanged() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["co", "branch1"]);
test_env.jj_cmd_ok(&workspace_root, &["co", "branch1"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
@ -162,7 +166,7 @@ fn test_git_push_other_remote_has_branch() {
.join("repo")
.join("store")
.join("git");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&workspace_root,
&[
"git",
@ -173,8 +177,8 @@ fn test_git_push_other_remote_has_branch() {
],
);
// Modify branch1 and push it to `origin`
test_env.jj_cmd_success(&workspace_root, &["edit", "branch1"]);
test_env.jj_cmd_success(&workspace_root, &["describe", "-m=modified"]);
test_env.jj_cmd_ok(&workspace_root, &["edit", "branch1"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m=modified"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
@ -204,15 +208,15 @@ fn test_git_push_not_fast_forward() {
// Move branch1 forward on the remote
let origin_path = test_env.env_root().join("origin");
test_env.jj_cmd_success(&origin_path, &["new", "branch1", "-m=remote"]);
test_env.jj_cmd_ok(&origin_path, &["new", "branch1", "-m=remote"]);
std::fs::write(origin_path.join("remote"), "remote").unwrap();
test_env.jj_cmd_success(&origin_path, &["branch", "set", "branch1"]);
test_env.jj_cmd_success(&origin_path, &["git", "export"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "set", "branch1"]);
test_env.jj_cmd_ok(&origin_path, &["git", "export"]);
// Move branch1 forward to another commit locally
test_env.jj_cmd_success(&workspace_root, &["new", "branch1", "-m=local"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "branch1", "-m=local"]);
std::fs::write(workspace_root.join("local"), "local").unwrap();
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "branch1"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "branch1"]);
// Pushing should fail
let assert = test_env
@ -232,13 +236,13 @@ fn test_git_push_not_fast_forward() {
#[test]
fn test_git_push_multiple() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["branch", "delete", "branch1"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&workspace_root, &["branch", "delete", "branch1"]);
test_env.jj_cmd_ok(
&workspace_root,
&["branch", "set", "--allow-backwards", "branch2"],
);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "my-branch"]);
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "my-branch"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m", "foo"]);
// Check the setup
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
insta::assert_snapshot!(stdout, @r###"
@ -251,7 +255,8 @@ fn test_git_push_multiple() {
my-branch: yqosqzyt 15dcdaa4 (empty) foo
"###);
// First dry-run
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--all", "--dry-run"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--all", "--dry-run"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Delete branch branch1 from 45a3aa29e907
@ -259,8 +264,9 @@ fn test_git_push_multiple() {
Add branch my-branch to 15dcdaa4f12f
Dry-run requested, not pushing.
"###);
insta::assert_snapshot!(stderr, @"");
// Dry run requesting two specific branches
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&workspace_root,
&["git", "push", "-b=branch1", "-b=my-branch", "--dry-run"],
);
@ -270,8 +276,9 @@ fn test_git_push_multiple() {
Add branch my-branch to 15dcdaa4f12f
Dry-run requested, not pushing.
"###);
insta::assert_snapshot!(stderr, @"");
// Dry run requesting two specific branches twice
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&workspace_root,
&[
"git",
@ -289,7 +296,8 @@ fn test_git_push_multiple() {
Add branch my-branch to 15dcdaa4f12f
Dry-run requested, not pushing.
"###);
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--all"]);
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--all"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Delete branch branch1 from 45a3aa29e907
@ -297,6 +305,7 @@ fn test_git_push_multiple() {
Add branch my-branch to 15dcdaa4f12f
Abandoned 2 commits that are no longer reachable.
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
insta::assert_snapshot!(stdout, @r###"
branch2: yqosqzyt 15dcdaa4 (empty) foo
@ -307,35 +316,38 @@ fn test_git_push_multiple() {
#[test]
fn test_git_push_changes() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m", "foo"]);
std::fs::write(workspace_root.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&workspace_root, &["new", "-m", "bar"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "-m", "bar"]);
std::fs::write(workspace_root.join("file"), "modified").unwrap();
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change", "@"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--change", "@"]);
insta::assert_snapshot!(stdout, @r###"
Creating branch push-yostqsxwqrlt for revision @
Branch changes to push to origin:
Add branch push-yostqsxwqrlt to 28d7620ea63a
"###);
insta::assert_snapshot!(stderr, @"");
// test pushing two changes at once
std::fs::write(workspace_root.join("file"), "modified2").unwrap();
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "-c=@", "-c=@-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-c=@", "-c=@-"]);
insta::assert_snapshot!(stdout, @r###"
Creating branch push-yqosqzytrlsw for revision @-
Branch changes to push to origin:
Force branch push-yostqsxwqrlt from 28d7620ea63a to 48d8c7948133
Add branch push-yqosqzytrlsw to fa16a14170fb
"###);
insta::assert_snapshot!(stderr, @"");
// specifying the same change twice doesn't break things
std::fs::write(workspace_root.join("file"), "modified3").unwrap();
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "-c=@", "-c=@"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-c=@", "-c=@"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Force branch push-yostqsxwqrlt from 48d8c7948133 to b5f030322b1d
"###);
insta::assert_snapshot!(stderr, @"");
// Test changing `git.push-branch-prefix`. It causes us to push again.
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&workspace_root,
&[
"git",
@ -350,19 +362,20 @@ fn test_git_push_changes() {
Branch changes to push to origin:
Add branch test-yostqsxwqrlt to b5f030322b1d
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_git_push_revisions() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m", "foo"]);
std::fs::write(workspace_root.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&workspace_root, &["new", "-m", "bar"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "branch-1"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "-m", "bar"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "branch-1"]);
std::fs::write(workspace_root.join("file"), "modified").unwrap();
test_env.jj_cmd_success(&workspace_root, &["new", "-m", "baz"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "branch-2a"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "branch-2b"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "-m", "baz"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "branch-2a"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "branch-2b"]);
std::fs::write(workspace_root.join("file"), "modified again").unwrap();
// Push an empty set
@ -379,14 +392,16 @@ fn test_git_push_revisions() {
No branches point to the specified revisions.
"###);
// Push a revision with a single branch
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "-r=@-", "--dry-run"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-r=@-", "--dry-run"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Add branch branch-1 to 7decc7932d9c
Dry-run requested, not pushing.
"###);
insta::assert_snapshot!(stderr, @"");
// Push multiple revisions of which some have branches
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&workspace_root,
&["git", "push", "-r=@--", "-r=@-", "--dry-run"],
);
@ -395,16 +410,19 @@ fn test_git_push_revisions() {
Add branch branch-1 to 7decc7932d9c
Dry-run requested, not pushing.
"###);
insta::assert_snapshot!(stderr, @"");
// Push a revision with a multiple branches
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "-r=@", "--dry-run"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-r=@", "--dry-run"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Add branch branch-2a to 1b45449e18d0
Add branch branch-2b to 1b45449e18d0
Dry-run requested, not pushing.
"###);
insta::assert_snapshot!(stderr, @"");
// Repeating a commit doesn't result in repeated messages about the branch
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&workspace_root,
&["git", "push", "-r=@-", "-r=@-", "--dry-run"],
);
@ -413,22 +431,23 @@ fn test_git_push_revisions() {
Add branch branch-1 to 7decc7932d9c
Dry-run requested, not pushing.
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_git_push_mixed() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m", "foo"]);
std::fs::write(workspace_root.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&workspace_root, &["new", "-m", "bar"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "branch-1"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "-m", "bar"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "branch-1"]);
std::fs::write(workspace_root.join("file"), "modified").unwrap();
test_env.jj_cmd_success(&workspace_root, &["new", "-m", "baz"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "branch-2a"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "branch-2b"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "-m", "baz"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "branch-2a"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "branch-2b"]);
std::fs::write(workspace_root.join("file"), "modified again").unwrap();
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&workspace_root,
&["git", "push", "--change=@--", "--branch=branch-1", "-r=@"],
);
@ -440,47 +459,48 @@ fn test_git_push_mixed() {
Add branch branch-2a to 1b45449e18d0
Add branch branch-2b to 1b45449e18d0
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_git_push_existing_long_branch() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m", "foo"]);
std::fs::write(workspace_root.join("file"), "contents").unwrap();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&workspace_root,
&["branch", "create", "push-19b790168e73f7a73a98deae21e807c0"],
);
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change=@"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--change=@"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Add branch push-19b790168e73f7a73a98deae21e807c0 to fa16a14170fb
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_git_push_unsnapshotted_change() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m", "foo"]);
std::fs::write(workspace_root.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change", "@"]);
test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--change", "@"]);
std::fs::write(workspace_root.join("file"), "modified").unwrap();
test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change", "@"]);
test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--change", "@"]);
}
#[test]
fn test_git_push_conflict() {
let (test_env, workspace_root) = set_up();
std::fs::write(workspace_root.join("file"), "first").unwrap();
test_env.jj_cmd_success(&workspace_root, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&workspace_root, &["commit", "-m", "first"]);
std::fs::write(workspace_root.join("file"), "second").unwrap();
test_env.jj_cmd_success(&workspace_root, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&workspace_root, &["commit", "-m", "second"]);
std::fs::write(workspace_root.join("file"), "third").unwrap();
test_env.jj_cmd_success(&workspace_root, &["rebase", "-r", "@", "-d", "@--"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "my-branch"]);
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "third"]);
test_env.jj_cmd_ok(&workspace_root, &["rebase", "-r", "@", "-d", "@--"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "my-branch"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m", "third"]);
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--all"]);
insta::assert_snapshot!(stderr, @r###"
Error: Won't push commit 1973d389875c since it has conflicts
@ -490,8 +510,8 @@ fn test_git_push_conflict() {
#[test]
fn test_git_push_no_description() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "my-branch"]);
test_env.jj_cmd_success(&workspace_root, &["describe", "-m="]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "my-branch"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "-m="]);
let stderr =
test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--branch", "my-branch"]);
insta::assert_snapshot!(stderr, @r###"
@ -537,15 +557,15 @@ fn test_git_push_missing_committer() {
.assert()
.success();
};
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "missing-name"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "missing-name"]);
run_without_var("JJ_USER", &["describe", "-m=no committer name"]);
let stderr =
test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--branch=missing-name"]);
insta::assert_snapshot!(stderr, @r###"
Error: Won't push commit 4fd190283d1a since it has no author and/or committer set
"###);
test_env.jj_cmd_success(&workspace_root, &["checkout", "root()"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "missing-email"]);
test_env.jj_cmd_ok(&workspace_root, &["checkout", "root()"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "missing-email"]);
run_without_var("JJ_EMAIL", &["describe", "-m=no committer email"]);
let stderr =
test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--branch=missing-email"]);
@ -567,17 +587,19 @@ fn test_git_push_missing_committer() {
fn test_git_push_deleted() {
let (test_env, workspace_root) = set_up();
test_env.jj_cmd_success(&workspace_root, &["branch", "delete", "branch1"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--deleted"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "delete", "branch1"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--deleted"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Delete branch branch1 from 45a3aa29e907
Abandoned 1 commits that are no longer reachable.
"###);
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--deleted"]);
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--deleted"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
@ -595,10 +617,10 @@ fn test_git_push_conflicting_branches() {
.unwrap()
.delete()
.unwrap();
test_env.jj_cmd_success(&workspace_root, &["git", "import"]);
test_env.jj_cmd_success(&workspace_root, &["new", "root()", "-m=description 3"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "branch2"]);
test_env.jj_cmd_success(&workspace_root, &["git", "fetch"]);
test_env.jj_cmd_ok(&workspace_root, &["git", "import"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "root()", "-m=description 3"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "branch2"]);
test_env.jj_cmd_ok(&workspace_root, &["git", "fetch"]);
insta::assert_snapshot!(test_env.jj_cmd_success(&workspace_root, &["branch", "list"]), @r###"
branch1: lzmmnrxq 45a3aa29 (empty) description 1
branch2 (conflicted):
@ -608,8 +630,8 @@ fn test_git_push_conflicting_branches() {
"###);
let bump_branch1 = || {
test_env.jj_cmd_success(&workspace_root, &["new", "branch1", "-m=bump"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "branch1"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "branch1", "-m=bump"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "branch1"]);
};
// Conflicting branch at @

View file

@ -22,28 +22,31 @@ pub mod common;
fn test_git_remotes() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "repo"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "repo"]);
let repo_path = test_env.env_root().join("repo");
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
insta::assert_snapshot!(stdout, @"");
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "foo", "http://example.com/repo/foo"],
);
insta::assert_snapshot!(stdout, @"");
let stdout = test_env.jj_cmd_success(
insta::assert_snapshot!(stderr, @"");
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "bar", "http://example.com/repo/bar"],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
insta::assert_snapshot!(stdout, @r###"
bar http://example.com/repo/bar
foo http://example.com/repo/foo
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "remove", "foo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "remote", "remove", "foo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
insta::assert_snapshot!(stdout, @"bar http://example.com/repo/bar
");
@ -57,9 +60,9 @@ fn test_git_remotes() {
fn test_git_remote_add() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "repo"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "repo"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "foo", "http://example.com/repo/foo"],
);
@ -93,13 +96,13 @@ fn test_git_remote_add() {
fn test_git_remote_rename() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "repo"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "repo"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "foo", "http://example.com/repo/foo"],
);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["git", "remote", "add", "baz", "http://example.com/repo/baz"],
);
@ -115,8 +118,10 @@ fn test_git_remote_rename() {
insta::assert_snapshot!(stderr, @r###"
Error: Git remote named 'git' is reserved for local Git repository
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "rename", "foo", "bar"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["git", "remote", "rename", "foo", "bar"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
insta::assert_snapshot!(stdout, @r###"
bar http://example.com/repo/foo
@ -134,12 +139,14 @@ fn test_git_remote_named_git() {
git_repo
.remote("git", "http://example.com/repo/repo")
.unwrap();
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", "main"]);
test_env.jj_cmd_ok(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "main"]);
// The remote can be renamed.
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "rename", "git", "bar"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["git", "remote", "rename", "git", "bar"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
insta::assert_snapshot!(stdout, @r###"
bar http://example.com/repo/repo
@ -161,11 +168,12 @@ fn test_git_remote_named_git() {
// Reinitialize the repo with remote named 'git'.
fs::remove_dir_all(repo_path.join(".jj")).unwrap();
git_repo.remote_rename("bar", "git").unwrap();
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&repo_path, &["init", "--git-repo=."]);
// The remote can also be removed.
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "remove", "git"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "remote", "remove", "git"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
insta::assert_snapshot!(stdout, @r###"
"###);

View file

@ -21,7 +21,7 @@ fn test_gitsubmodule_print_gitmodules() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
std::fs::write(
workspace_root.join(".gitmodules"),
@ -33,7 +33,7 @@ fn test_gitsubmodule_print_gitmodules() {
)
.unwrap();
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
std::fs::write(
workspace_root.join(".gitmodules"),

View file

@ -23,7 +23,7 @@ fn test_gitignores() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
// Say in core.excludesFiles that we don't want file1, file2, or file3
let mut file = std::fs::OpenOptions::new()
@ -71,18 +71,18 @@ fn test_gitignores_ignored_file_in_target_commit() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
git2::Repository::init(&workspace_root).unwrap();
test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
// Create a commit with file "ignored" in it
std::fs::write(workspace_root.join("ignored"), "committed contents\n").unwrap();
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "with-file"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "with-file"]);
let target_commit_id = test_env.jj_cmd_success(
&workspace_root,
&["log", "--no-graph", "-T=commit_id", "-r=@"],
);
// Create another commit where we ignore that path
test_env.jj_cmd_success(&workspace_root, &["new", "root()"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "root()"]);
std::fs::write(workspace_root.join("ignored"), "contents in working copy\n").unwrap();
std::fs::write(workspace_root.join(".gitignore"), ".gitignore\nignored\n").unwrap();

View file

@ -45,7 +45,7 @@ fn test_non_utf8_arg() {
#[test]
fn test_no_subcommand() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Outside of a repo.
@ -81,10 +81,10 @@ fn test_no_subcommand() {
assert_eq!(stdout, test_env.jj_cmd_success(&repo_path, &["log"]));
// Command argument that looks like a command name.
test_env.jj_cmd_success(&repo_path, &["branch", "create", "help"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "log"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "show"]);
// TODO: test_env.jj_cmd_success(&repo_path, &["-r", "help"])
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "help"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "log"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "show"]);
// TODO: test_env.jj_cmd_ok(&repo_path, &["-r", "help"])
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["-r", "log"]), @r###"
@ qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 help log show 230dd059
(empty) (no description set)
@ -100,7 +100,7 @@ fn test_no_subcommand() {
#[test]
fn test_ignore_working_copy() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
@ -149,7 +149,7 @@ fn test_repo_arg_with_git_clone() {
#[test]
fn test_resolve_workspace_directory() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let subdir = repo_path.join("dir").join("subdir");
std::fs::create_dir_all(&subdir).unwrap();
@ -211,7 +211,7 @@ fn test_no_workspace_directory() {
#[test]
fn test_broken_repo_structure() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let store_path = repo_path.join(".jj").join("repo").join("store");
let store_type_path = store_path.join("type");
@ -253,7 +253,7 @@ fn test_broken_repo_structure() {
fn test_color_config() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Test that --color=always is respected.
@ -380,7 +380,7 @@ fn test_invalid_config() {
fn test_no_user_configured() {
// Test that the user is reminded if they haven't configured their name or email
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let assert = test_env

View file

@ -19,14 +19,14 @@ pub mod common;
#[test]
fn test_rewrite_immutable_generic() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "a").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m=a"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m=b"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=a"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m=b"]);
std::fs::write(repo_path.join("file"), "b").unwrap();
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["new", "main-", "-m=c"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["new", "main-", "-m=c"]);
std::fs::write(repo_path.join("file"), "c").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
@ -84,17 +84,17 @@ fn test_rewrite_immutable_generic() {
#[test]
fn test_rewrite_immutable_commands() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "a").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m=a"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m=b"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=a"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m=b"]);
std::fs::write(repo_path.join("file"), "b").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "@-", "-m=c"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m=c"]);
std::fs::write(repo_path.join("file"), "c").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "all:visible_heads()", "-m=merge"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["new", "description(b)"]);
test_env.jj_cmd_ok(&repo_path, &["new", "all:visible_heads()", "-m=merge"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["new", "description(b)"]);
test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);
// Log shows mutable commits and immutable heads by default

View file

@ -55,10 +55,11 @@ fn init_git_repo_with_opts(git_repo_path: &Path, opts: &git2::RepositoryInitOpti
#[test]
fn test_init_git_internal() {
let test_env = TestEnvironment::default();
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let (stdout, stderr) = test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
insta::assert_snapshot!(stdout, @r###"
Initialized repo in "repo"
"###);
insta::assert_snapshot!(stderr, @"");
let workspace_root = test_env.env_root().join("repo");
let jj_path = workspace_root.join(".jj");
@ -82,7 +83,7 @@ fn test_init_git_external(bare: bool) {
let git_repo_path = test_env.env_root().join("git-repo");
init_git_repo(&git_repo_path, bare);
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
test_env.env_root(),
&[
"init",
@ -98,6 +99,7 @@ fn test_init_git_external(bare: bool) {
Added 1 files, modified 0 files, removed 0 files
Initialized repo in "repo"
"###);
insta::assert_snapshot!(stderr, @"");
}
let workspace_root = test_env.env_root().join("repo");
@ -162,11 +164,12 @@ fn test_init_git_colocated() {
let test_env = TestEnvironment::default();
let workspace_root = test_env.env_root().join("repo");
init_git_repo(&workspace_root, false);
let stdout = test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
insta::assert_snapshot!(stdout, @r###"
Done importing changes from the underlying Git repo.
Initialized repo in "."
"###);
insta::assert_snapshot!(stderr, @"");
let jj_path = workspace_root.join(".jj");
let repo_path = jj_path.join("repo");
@ -190,7 +193,7 @@ fn test_init_git_colocated() {
"###);
// Check that the Git repo's HEAD moves
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
sqpuoqvx test.user@example.com 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
@ -210,11 +213,12 @@ fn test_init_git_colocated_gitlink() {
git2::RepositoryInitOptions::new().workdir_path(&workspace_root),
);
assert!(workspace_root.join(".git").is_file());
let stdout = test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
insta::assert_snapshot!(stdout, @r###"
Done importing changes from the underlying Git repo.
Initialized repo in "."
"###);
insta::assert_snapshot!(stderr, @"");
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
@ -225,7 +229,7 @@ fn test_init_git_colocated_gitlink() {
"###);
// Check that the Git repo's HEAD moves
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
sqpuoqvx test.user@example.com 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
@ -244,11 +248,12 @@ fn test_init_git_colocated_symlink_directory() {
init_git_repo(&git_repo_path, false);
std::fs::create_dir(&workspace_root).unwrap();
std::os::unix::fs::symlink(git_repo_path.join(".git"), workspace_root.join(".git")).unwrap();
let stdout = test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
insta::assert_snapshot!(stdout, @r###"
Done importing changes from the underlying Git repo.
Initialized repo in "."
"###);
insta::assert_snapshot!(stderr, @"");
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
@ -259,7 +264,7 @@ fn test_init_git_colocated_symlink_directory() {
"###);
// Check that the Git repo's HEAD moves
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
sqpuoqvx test.user@example.com 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
@ -283,11 +288,12 @@ fn test_init_git_colocated_symlink_gitlink() {
assert!(git_workdir_path.join(".git").is_file());
std::fs::create_dir(&workspace_root).unwrap();
std::os::unix::fs::symlink(git_workdir_path.join(".git"), workspace_root.join(".git")).unwrap();
let stdout = test_env.jj_cmd_success(&workspace_root, &["init", "--git-repo", "."]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]);
insta::assert_snapshot!(stdout, @r###"
Done importing changes from the underlying Git repo.
Initialized repo in "."
"###);
insta::assert_snapshot!(stderr, @"");
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
@ -298,7 +304,7 @@ fn test_init_git_colocated_symlink_gitlink() {
"###);
// Check that the Git repo's HEAD moves
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
sqpuoqvx test.user@example.com 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
@ -314,13 +320,14 @@ fn test_init_git_external_but_git_dir_exists() {
let workspace_root = test_env.env_root().join("repo");
git2::Repository::init(&git_repo_path).unwrap();
init_git_repo(&workspace_root, false);
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&workspace_root,
&["init", "--git-repo", git_repo_path.to_str().unwrap()],
);
insta::assert_snapshot!(stdout, @r###"
Initialized repo in "."
"###);
insta::assert_snapshot!(stderr, @"");
// The local ".git" repository is unrelated, so no commits should be imported
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
@ -329,7 +336,7 @@ fn test_init_git_external_but_git_dir_exists() {
"###);
// Check that Git HEAD is not set because this isn't a colocated repo
test_env.jj_cmd_success(&workspace_root, &["new"]);
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
qpvuntsm test.user@example.com 2001-02-03 04:05:07.000 +07:00 230dd059
@ -377,10 +384,11 @@ fn test_init_local_disallowed() {
fn test_init_local() {
let test_env = TestEnvironment::default();
test_env.add_config(r#"ui.allow-init-native = true"#);
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo"]);
insta::assert_snapshot!(stdout, @r###"
Initialized repo in "repo"
"###);
insta::assert_snapshot!(stderr, @"");
let workspace_root = test_env.env_root().join("repo");
let jj_path = workspace_root.join(".jj");

View file

@ -19,19 +19,19 @@ pub mod common;
#[test]
fn test_interdiff_basic() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["branch", "create", "left"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]);
test_env.jj_cmd_success(&repo_path, &["checkout", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]);
std::fs::write(repo_path.join("file3"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file2"), "foo\nbar\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["branch", "create", "right"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]);
// implicit --to
let stdout = test_env.jj_cmd_success(&repo_path, &["interdiff", "--from", "left"]);
@ -42,7 +42,7 @@ fn test_interdiff_basic() {
"###);
// explicit --to
test_env.jj_cmd_success(&repo_path, &["checkout", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["checkout", "@-"]);
let stdout = test_env.jj_cmd_success(
&repo_path,
&["interdiff", "--from", "left", "--to", "right"],
@ -52,7 +52,7 @@ fn test_interdiff_basic() {
1 1: foo
2: bar
"###);
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
// formats specifiers
let stdout = test_env.jj_cmd_success(
@ -81,23 +81,23 @@ fn test_interdiff_basic() {
#[test]
fn test_interdiff_paths() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "bar\n").unwrap();
std::fs::write(repo_path.join("file2"), "bar\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["branch", "create", "left"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]);
test_env.jj_cmd_success(&repo_path, &["checkout", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]);
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "baz\n").unwrap();
std::fs::write(repo_path.join("file2"), "baz\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["branch", "create", "right"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]);
let stdout = test_env.jj_cmd_success(
&repo_path,
@ -131,19 +131,19 @@ fn test_interdiff_paths() {
#[test]
fn test_interdiff_conflicting() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file"), "bar\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["branch", "create", "left"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]);
test_env.jj_cmd_success(&repo_path, &["checkout", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]);
std::fs::write(repo_path.join("file"), "abc\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file"), "def\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["branch", "create", "right"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]);
let stdout = test_env.jj_cmd_success(
&repo_path,

View file

@ -19,7 +19,7 @@ pub mod common;
#[test]
fn test_log_with_empty_revision() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["log", "-r="]);
@ -33,7 +33,7 @@ fn test_log_with_empty_revision() {
#[test]
fn test_log_legacy_range_operator() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r=@:"]);
@ -80,12 +80,12 @@ fn test_log_legacy_range_operator() {
#[test]
fn test_log_with_or_without_diff() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "a new commit"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "a new commit"]);
std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description"]);
@ -317,18 +317,18 @@ fn test_log_with_or_without_diff() {
#[test]
fn test_log_null_terminate_multiline_descriptions() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["commit", "-m", "commit 1 line 1", "-m", "commit 1 line 2"],
);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["commit", "-m", "commit 2 line 1", "-m", "commit 2 line 2"],
);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["describe", "-m", "commit 3 line 1", "-m", "commit 3 line 2"],
);
@ -353,7 +353,7 @@ fn test_log_null_terminate_multiline_descriptions() {
#[test]
fn test_log_shortest_accessors() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |rev, template| {
test_env.jj_cmd_success(
@ -369,20 +369,20 @@ fn test_log_shortest_accessors() {
);
std::fs::write(repo_path.join("file"), "original file\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_success(&repo_path, &["branch", "c", "original"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "c", "original"]);
insta::assert_snapshot!(
render("original", r#"format_id(change_id) ++ " " ++ format_id(commit_id)"#),
@"q[pvuntsmwlqt] b[a1a30916d29]");
// Create a chain of 10 commits
for i in 1..10 {
test_env.jj_cmd_success(&repo_path, &["new", "-m", &format!("commit{i}")]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", &format!("commit{i}")]);
std::fs::write(repo_path.join("file"), format!("file {i}\n")).unwrap();
}
// Create 2^3 duplicates of the chain
for _ in 0..3 {
test_env.jj_cmd_success(&repo_path, &["duplicate", "description(commit)"]);
test_env.jj_cmd_ok(&repo_path, &["duplicate", "description(commit)"]);
}
insta::assert_snapshot!(
@ -461,7 +461,7 @@ fn test_log_shortest_accessors() {
#[test]
fn test_log_bad_short_prefixes() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Error on bad config of short prefixes
test_env.add_config(r#"revsets.short-prefixes = "!nval!d""#);
@ -481,7 +481,7 @@ fn test_log_bad_short_prefixes() {
#[test]
fn test_log_prefix_highlight_styled() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
fn prefix_format(len: Option<usize>) -> String {
@ -500,8 +500,8 @@ fn test_log_prefix_highlight_styled() {
}
std::fs::write(repo_path.join("file"), "original file\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_success(&repo_path, &["branch", "c", "original"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "c", "original"]);
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "original", "-T", &prefix_format(Some(12))]),
@r###"
@ -513,12 +513,12 @@ fn test_log_prefix_highlight_styled() {
// Create a chain of 10 commits
for i in 1..10 {
test_env.jj_cmd_success(&repo_path, &["new", "-m", &format!("commit{i}")]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", &format!("commit{i}")]);
std::fs::write(repo_path.join("file"), format!("file {i}\n")).unwrap();
}
// Create 2^3 duplicates of the chain
for _ in 0..3 {
test_env.jj_cmd_success(&repo_path, &["duplicate", "description(commit)"]);
test_env.jj_cmd_ok(&repo_path, &["duplicate", "description(commit)"]);
}
insta::assert_snapshot!(
@ -612,7 +612,7 @@ fn test_log_prefix_highlight_styled() {
#[test]
fn test_log_prefix_highlight_counts_hidden_commits() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(
r#"
@ -634,8 +634,8 @@ fn test_log_prefix_highlight_counts_hidden_commits() {
"#;
std::fs::write(repo_path.join("file"), "original file\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_success(&repo_path, &["branch", "c", "original"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "c", "original"]);
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", prefix_format]),
@r###"
@ -645,11 +645,11 @@ fn test_log_prefix_highlight_counts_hidden_commits() {
);
// Create 2^7 hidden commits
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m", "extra"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "extra"]);
for _ in 0..7 {
test_env.jj_cmd_success(&repo_path, &["duplicate", "description(extra)"]);
test_env.jj_cmd_ok(&repo_path, &["duplicate", "description(extra)"]);
}
test_env.jj_cmd_success(&repo_path, &["abandon", "description(extra)"]);
test_env.jj_cmd_ok(&repo_path, &["abandon", "description(extra)"]);
// The unique prefixes became longer.
insta::assert_snapshot!(
@ -680,7 +680,7 @@ fn test_log_prefix_highlight_counts_hidden_commits() {
#[test]
fn test_log_short_shortest_length_parameter() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
@ -709,7 +709,7 @@ fn test_log_short_shortest_length_parameter() {
#[test]
fn test_log_author_format() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
insta::assert_snapshot!(
@ -743,12 +743,12 @@ fn test_log_author_format() {
#[test]
fn test_log_divergence() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let template = r#"description.first_line() ++ if(divergent, " !divergence!")"#;
std::fs::write(repo_path.join("file"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description 1"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description 1"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
// No divergence
insta::assert_snapshot!(stdout, @r###"
@ -757,11 +757,11 @@ fn test_log_divergence() {
"###);
// Create divergence
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["describe", "-m", "description 2", "--at-operation", "@-"],
);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-T", template]);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
description 2 !divergence!
@ -769,16 +769,17 @@ fn test_log_divergence() {
"###);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_log_reversed() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "second"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "--reversed"]);
insta::assert_snapshot!(stdout, @r###"
@ -800,12 +801,12 @@ fn test_log_reversed() {
#[test]
fn test_log_filtered_by_path() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "second"]);
std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap();
std::fs::write(repo_path.join("file2"), "baz\n").unwrap();
@ -864,16 +865,16 @@ fn test_log_filtered_by_path() {
#[test]
fn test_log_limit() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "a"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "a"]);
std::fs::write(repo_path.join("a"), "").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "-m", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "b"]);
std::fs::write(repo_path.join("b"), "").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "-m", "c", "description(a)"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "c", "description(a)"]);
std::fs::write(repo_path.join("c"), "").unwrap();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["new", "-m", "d", "description(c)", "description(b)"],
);
@ -946,7 +947,7 @@ fn test_log_limit() {
#[test]
fn test_log_warn_path_might_be_revset() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
@ -1003,11 +1004,11 @@ fn test_log_warn_path_might_be_revset() {
#[test]
fn test_default_revset() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]);
// Set configuration to only show the root commit.
test_env.add_config(r#"revsets.log = "root()""#);
@ -1026,11 +1027,11 @@ fn test_default_revset() {
#[test]
fn test_default_revset_per_repo() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]);
// Set configuration to only show the root commit.
std::fs::write(
@ -1053,11 +1054,11 @@ fn test_default_revset_per_repo() {
#[test]
fn test_multiple_revsets() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
for name in ["foo", "bar", "baz"] {
test_env.jj_cmd_success(&repo_path, &["new", "-m", name]);
test_env.jj_cmd_success(&repo_path, &["branch", "set", name]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", name]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", name]);
}
// Default revset should be overridden if one or more -r options are specified.
@ -1092,14 +1093,14 @@ fn test_multiple_revsets() {
fn test_graph_template_color() {
// Test that color codes from a multi-line template don't span the graph lines.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["describe", "-m", "first line\nsecond line\nthird line"],
);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "single line"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "single line"]);
test_env.add_config(
r#"[colors]
@ -1132,17 +1133,17 @@ fn test_graph_template_color() {
fn test_graph_styles() {
// Test that different graph styles are available.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "initial"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "main branch 1"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "main branch 2"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "main branch 1"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "main branch 2"]);
test_env.jj_cmd_ok(
&repo_path,
&["new", "-m", "side branch\nwith\nlong\ndescription"],
);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["new", "-m", "merge", r#"description("main branch 1")"#, "@"],
);
@ -1237,7 +1238,7 @@ fn test_graph_styles() {
#[test]
fn test_log_word_wrap() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |args: &[&str], columns: u32, word_wrap: bool| {
let mut args = args.to_vec();
@ -1253,10 +1254,10 @@ fn test_log_word_wrap() {
get_stdout_string(&assert)
};
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "main branch 1"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "main branch 2"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "side"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "merge", "@--", "@"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "main branch 1"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "main branch 2"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "side"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "merge", "@--", "@"]);
// ui.log-word-wrap option applies to both graph/no-graph outputs
insta::assert_snapshot!(render(&["log", "-r@"], 40, false), @r###"

View file

@ -21,7 +21,7 @@ pub mod common;
#[test]
fn test_move() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Create history like this:
@ -35,25 +35,25 @@ fn test_move() {
//
// When moving changes between e.g. C and F, we should not get unrelated changes
// from B and D.
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
std::fs::write(repo_path.join("file3"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
std::fs::write(repo_path.join("file3"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["edit", "a"]);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "d"]);
test_env.jj_cmd_ok(&repo_path, &["edit", "a"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
std::fs::write(repo_path.join("file3"), "d\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "e"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "e"]);
std::fs::write(repo_path.join("file2"), "e\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "f"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "f"]);
std::fs::write(repo_path.join("file2"), "f\n").unwrap();
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ -84,12 +84,13 @@ fn test_move() {
"###);
// Can move from sibling, which results in the source being abandoned
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "c"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["move", "--from", "c"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: kmkuslsw 1c03e3d3 f | (no description set)
Parent commit : znkkpsqq e9515f21 e | (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 1c03e3d3c63f f
e9515f21068c e
@ -111,12 +112,13 @@ fn test_move() {
"###);
// Can move from ancestor
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "@--"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["move", "--from", "@--"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: kmkuslsw c8d83075 f | (no description set)
Parent commit : znkkpsqq 2c50bfc5 e | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
// The change has been removed from the source (the change pointed to by 'd'
// became empty and was abandoned)
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ -136,13 +138,14 @@ fn test_move() {
"###);
// Can move from descendant
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "e", "--to", "d"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["move", "--from", "e", "--to", "d"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: kmkuslsw 2b723b1d f | (no description set)
Parent commit : vruxwmqv 4293930d d e | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
// The change has been removed from the source (the change pointed to by 'e'
// became empty and was abandoned)
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ -164,7 +167,7 @@ fn test_move() {
#[test]
fn test_move_partial() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Create history like this:
@ -173,20 +176,20 @@ fn test_move_partial() {
// D B
// |/
// A
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
std::fs::write(repo_path.join("file3"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
std::fs::write(repo_path.join("file3"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
std::fs::write(repo_path.join("file2"), "c\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["edit", "a"]);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "d"]);
test_env.jj_cmd_ok(&repo_path, &["edit", "a"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
std::fs::write(repo_path.join("file3"), "d\n").unwrap();
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ -201,12 +204,13 @@ fn test_move_partial() {
let edit_script = test_env.set_up_fake_diff_editor();
// If we don't make any changes in the diff-editor, the whole change is moved
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "-i", "--from", "c"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["move", "-i", "--from", "c"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv 71b69e43 d | (no description set)
Parent commit : qpvuntsm 3db0a2f5 a | (no description set)
Added 0 files, modified 2 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 71b69e433fbc d
55171e33db26 b c
@ -230,14 +234,15 @@ fn test_move_partial() {
"###);
// Can move only part of the change in interactive mode
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(&edit_script, "reset file2").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "-i", "--from", "c"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["move", "-i", "--from", "c"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv 63f1a6e9 d | (no description set)
Parent commit : qpvuntsm 3db0a2f5 a | (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 63f1a6e96edb d
d027c6e3e6bc c
@ -263,15 +268,16 @@ fn test_move_partial() {
"###);
// Can move only part of the change from a sibling in non-interactive mode
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
// Clear the script so we know it won't be used
std::fs::write(&edit_script, "").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "c", "file1"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["move", "--from", "c", "file1"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv 17c2e663 d | (no description set)
Parent commit : qpvuntsm 3db0a2f5 a | (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 17c2e6632cc5 d
6a3ae047a03e c
@ -297,14 +303,15 @@ fn test_move_partial() {
"###);
// Can move only part of the change from a descendant in non-interactive mode
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
// Clear the script so we know it won't be used
std::fs::write(&edit_script, "").unwrap();
let stdout =
test_env.jj_cmd_success(&repo_path, &["move", "--from", "c", "--to", "b", "file1"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["move", "--from", "c", "--to", "b", "file1"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
21253406d416 c
e1cf08aae711 b
@ -326,12 +333,13 @@ fn test_move_partial() {
// If we specify only a non-existent file, then the move still succeeds and
// creates unchanged commits.
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "c", "nonexistent"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["move", "--from", "c", "nonexistent"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv b670567d d | (no description set)
Parent commit : qpvuntsm 3db0a2f5 a | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
}
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
@ -342,7 +350,7 @@ fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
#[test]
fn test_move_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();
@ -351,35 +359,35 @@ fn test_move_description() {
// If both descriptions are empty, the resulting description is empty
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["move", "--to", "@-"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @"");
// If the destination's description is empty and the source's description is
// non-empty, the resulting description is from the source
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "source"]);
test_env.jj_cmd_ok(&repo_path, &["move", "--to", "@-"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
source
"###);
// If the destination's description is non-empty and the source's description is
// empty, the resulting description is from the destination
test_env.jj_cmd_success(&repo_path, &["op", "restore", "@--"]);
test_env.jj_cmd_success(&repo_path, &["describe", "@-", "-m", "destination"]);
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["op", "restore", "@--"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "@-", "-m", "destination"]);
test_env.jj_cmd_ok(&repo_path, &["move", "--to", "@-"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
destination
"###);
// If both descriptions were non-empty, we get asked for a combined description
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "source"]);
std::fs::write(&edit_script, "dump editor0").unwrap();
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["move", "--to", "@-"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
destination
@ -399,9 +407,9 @@ fn test_move_description() {
// If the source's *content* doesn't become empty, then the source remains and
// both descriptions are unchanged
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-", "file1"]);
test_env.jj_cmd_ok(&repo_path, &["move", "--to", "@-", "file1"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
destination
"###);

View file

@ -21,11 +21,11 @@ pub mod common;
#[test]
fn test_new() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_success(&repo_path, &["new", "-m", "a new commit"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "a new commit"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 4f2d6e0a3482a6a34e4856a4a63869c0df109e79 a new commit
@ -34,7 +34,7 @@ fn test_new() {
"###);
// Start a new change off of a specific commit (the root commit in this case).
test_env.jj_cmd_success(&repo_path, &["new", "-m", "off of root", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "off of root", "root()"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 026537ddb96b801b9cb909985d5443aab44616c1 off of root
4f2d6e0a3482a6a34e4856a4a63869c0df109e79 a new commit
@ -47,17 +47,17 @@ fn test_new() {
#[test]
fn test_new_merge() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add file1"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add file1"]);
std::fs::write(repo_path.join("file1"), "a").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m", "add file2"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "add file2"]);
std::fs::write(repo_path.join("file2"), "b").unwrap();
// Create a merge commit
test_env.jj_cmd_success(&repo_path, &["new", "main", "@"]);
test_env.jj_cmd_ok(&repo_path, &["new", "main", "@"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 0c4e5b9b68ae0cbe7ce3c61042619513d09005bf
@ -72,8 +72,8 @@ fn test_new_merge() {
insta::assert_snapshot!(stdout, @"b");
// Same test with `jj merge`
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["merge", "main", "@"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["merge", "main", "@"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 200ed1a14c8acf09783dafefe5bebf2ff58f12fd
@ -109,7 +109,7 @@ fn test_new_merge() {
#[test]
fn test_new_insert_after() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
setup_before_insertion(&test_env, &repo_path);
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
@ -125,14 +125,15 @@ fn test_new_insert_after() {
root
"###);
let stdout =
test_env.jj_cmd_success(&repo_path, &["new", "--insert-after", "-m", "G", "B", "D"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["new", "--insert-after", "-m", "G", "B", "D"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 2 descendant commits
Working copy now at: kxryzmor ca7c6481 (empty) G
Parent commit : kkmpptxz 6041917c B | (empty) B
Parent commit : vruxwmqv c9257eff D | (empty) D
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
C
F
@ -148,12 +149,14 @@ fn test_new_insert_after() {
root
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["new", "--insert-after", "-m", "H", "D"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["new", "--insert-after", "-m", "H", "D"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 3 descendant commits
Working copy now at: uyznsvlq fcf8281b (empty) H
Parent commit : vruxwmqv c9257eff D | (empty) D
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
C
F
@ -174,7 +177,7 @@ fn test_new_insert_after() {
#[test]
fn test_new_insert_after_children() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
setup_before_insertion(&test_env, &repo_path);
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
@ -193,13 +196,14 @@ fn test_new_insert_after_children() {
// Check that inserting G after A and C doesn't try to rebase B (which is
// initially a child of A) onto G as that would create a cycle since B is
// a parent of C which is a parent G.
let stdout =
test_env.jj_cmd_success(&repo_path, &["new", "--insert-after", "-m", "G", "A", "C"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["new", "--insert-after", "-m", "G", "A", "C"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: kxryzmor b48d4d73 (empty) G
Parent commit : qpvuntsm 65b1ef43 A | (empty) A
Parent commit : mzvwutvl ec18c57d C | (empty) C
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
@ G
@ -220,7 +224,7 @@ fn test_new_insert_after_children() {
#[test]
fn test_new_insert_before() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
setup_before_insertion(&test_env, &repo_path);
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
@ -236,8 +240,8 @@ fn test_new_insert_before() {
root
"###);
let stdout =
test_env.jj_cmd_success(&repo_path, &["new", "--insert-before", "-m", "G", "C", "F"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["new", "--insert-before", "-m", "G", "C", "F"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 2 descendant commits
Working copy now at: kxryzmor ff6bbbc7 (empty) G
@ -245,6 +249,7 @@ fn test_new_insert_before() {
Parent commit : vruxwmqv c9257eff D | (empty) D
Parent commit : kkmpptxz 6041917c B | (empty) B
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
F
C
@ -264,7 +269,7 @@ fn test_new_insert_before() {
#[test]
fn test_new_insert_before_root_successors() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
setup_before_insertion(&test_env, &repo_path);
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
@ -280,13 +285,14 @@ fn test_new_insert_before_root_successors() {
root
"###);
let stdout =
test_env.jj_cmd_success(&repo_path, &["new", "--insert-before", "-m", "G", "A", "D"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["new", "--insert-before", "-m", "G", "A", "D"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 5 descendant commits
Working copy now at: kxryzmor 36541977 (empty) G
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
F
@ -305,7 +311,7 @@ fn test_new_insert_before_root_successors() {
#[test]
fn test_new_insert_before_no_loop() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
setup_before_insertion(&test_env, &repo_path);
let template = r#"commit_id.short() ++ " " ++ if(description, description, "root")"#;
@ -333,7 +339,7 @@ fn test_new_insert_before_no_loop() {
#[test]
fn test_new_insert_before_no_root_merge() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
setup_before_insertion(&test_env, &repo_path);
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
@ -349,13 +355,14 @@ fn test_new_insert_before_no_root_merge() {
root
"###);
let stdout =
test_env.jj_cmd_success(&repo_path, &["new", "--insert-before", "-m", "G", "B", "D"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["new", "--insert-before", "-m", "G", "B", "D"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 4 descendant commits
Working copy now at: kxryzmor bf9fc493 (empty) G
Parent commit : qpvuntsm 65b1ef43 A | (empty) A
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
F
@ -374,7 +381,7 @@ fn test_new_insert_before_no_root_merge() {
#[test]
fn test_new_insert_before_root() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
setup_before_insertion(&test_env, &repo_path);
insta::assert_snapshot!(get_short_log_output(&test_env, &repo_path), @r###"
@ -398,18 +405,18 @@ fn test_new_insert_before_root() {
}
fn setup_before_insertion(test_env: &TestEnvironment, repo_path: &Path) {
test_env.jj_cmd_success(repo_path, &["branch", "create", "A"]);
test_env.jj_cmd_success(repo_path, &["commit", "-m", "A"]);
test_env.jj_cmd_success(repo_path, &["branch", "create", "B"]);
test_env.jj_cmd_success(repo_path, &["commit", "-m", "B"]);
test_env.jj_cmd_success(repo_path, &["branch", "create", "C"]);
test_env.jj_cmd_success(repo_path, &["describe", "-m", "C"]);
test_env.jj_cmd_success(repo_path, &["new", "-m", "D", "root()"]);
test_env.jj_cmd_success(repo_path, &["branch", "create", "D"]);
test_env.jj_cmd_success(repo_path, &["new", "-m", "E", "root()"]);
test_env.jj_cmd_success(repo_path, &["branch", "create", "E"]);
test_env.jj_cmd_success(repo_path, &["new", "-m", "F", "D", "E"]);
test_env.jj_cmd_success(repo_path, &["branch", "create", "F"]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", "A"]);
test_env.jj_cmd_ok(repo_path, &["commit", "-m", "A"]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", "B"]);
test_env.jj_cmd_ok(repo_path, &["commit", "-m", "B"]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", "C"]);
test_env.jj_cmd_ok(repo_path, &["describe", "-m", "C"]);
test_env.jj_cmd_ok(repo_path, &["new", "-m", "D", "root()"]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", "D"]);
test_env.jj_cmd_ok(repo_path, &["new", "-m", "E", "root()"]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", "E"]);
test_env.jj_cmd_ok(repo_path, &["new", "-m", "F", "D", "E"]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", "F"]);
}
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {

View file

@ -27,15 +27,15 @@ fn test_next_simple() {
// third
//
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Create a simple linear history, which we'll traverse.
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
// Move to `first`
test_env.jj_cmd_success(&repo_path, &["new", "@--"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["next"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@--"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["next"]);
insta::assert_snapshot!(
stdout,
@r###"
@ -43,20 +43,21 @@ fn test_next_simple() {
Parent commit : kkmpptxz 3fa8931e (empty) third
"###
);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_next_multiple() {
// Move from first => fourth.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "fourth"]);
test_env.jj_cmd_success(&repo_path, &["new", "@---"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["next", "2"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "fourth"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@---"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["next", "2"]);
// We should now be the child of the fourth commit.
insta::assert_snapshot!(
stdout,
@ -65,18 +66,19 @@ fn test_next_multiple() {
Parent commit : zsuskuln 009f88bf (empty) fourth
"###
);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_prev_simple() {
// Move from third => second.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["prev"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["prev"]);
// The working copy commit is now a child of "second".
insta::assert_snapshot!(
stdout,
@ -85,19 +87,20 @@ fn test_prev_simple() {
Parent commit : rlvkpnrz 5c52832c (empty) second
"###
);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_prev_multiple_without_root() {
// Move from fourth => second.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "fourth"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["prev", "2"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "fourth"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["prev", "2"]);
insta::assert_snapshot!(
stdout,
@r###"
@ -105,18 +108,19 @@ fn test_prev_multiple_without_root() {
Parent commit : rlvkpnrz 5c52832c (empty) second
"###
);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_next_exceeding_history() {
// Try to step beyond the current repos history.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_success(&repo_path, &["edit", "-r", "@--"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["edit", "-r", "@--"]);
let stderr = test_env.jj_cmd_failure(&repo_path, &["next", "3"]);
// `jj next` beyond existing history fails.
insta::assert_snapshot!(stderr, @r###"
@ -128,20 +132,20 @@ fn test_next_exceeding_history() {
fn test_next_fails_on_branching_children() {
// TODO(#2126): Fix this behavior
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Create a main branch for this test
test_env.jj_cmd_success(&repo_path, &["branch", "set", "main"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "set", "main"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
// Create a branching child.
test_env.jj_cmd_success(&repo_path, &["branch", "c", "into-the-future"]);
test_env.jj_cmd_success(&repo_path, &["co", "into-the-future"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "42"]);
test_env.jj_cmd_success(&repo_path, &["co", "main"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "c", "into-the-future"]);
test_env.jj_cmd_ok(&repo_path, &["co", "into-the-future"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "42"]);
test_env.jj_cmd_ok(&repo_path, &["co", "main"]);
// Make the default branch have two possible children.
test_env.jj_cmd_success(&repo_path, &["new", "into-the-future", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["new", "into-the-future", "@-"]);
// Try to advance the working copy commit.
let stderr = test_env.jj_cmd_failure(&repo_path, &["next"]);
insta::assert_snapshot!(stderr,@r###"
@ -153,16 +157,16 @@ fn test_next_fails_on_branching_children() {
fn test_prev_fails_on_multiple_parents() {
// TODO(#2126): Fix this behavior
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_success(&repo_path, &["branch", "c", "all-about"]);
test_env.jj_cmd_success(&repo_path, &["co", "all-about"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "soname"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "c", "all-about"]);
test_env.jj_cmd_ok(&repo_path, &["co", "all-about"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "soname"]);
// Create a merge commit, which has two parents.
test_env.jj_cmd_success(&repo_path, &["new", "@-", "@--"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "@--"]);
// We have more than one parent, prev fails.
let stderr = test_env.jj_cmd_failure(&repo_path, &["prev"]);
insta::assert_snapshot!(stderr,@r###"
@ -173,12 +177,12 @@ fn test_prev_fails_on_multiple_parents() {
#[test]
fn test_prev_onto_root_fails() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "fourth"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "fourth"]);
// The root commit is before "first".
let stderr = test_env.jj_cmd_failure(&repo_path, &["prev", "6"]);
insta::assert_snapshot!(stderr,@r###"
@ -190,13 +194,13 @@ fn test_prev_onto_root_fails() {
fn test_prev_editing() {
// Edit the third commit.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "fourth"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["prev", "--edit"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "fourth"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["prev", "--edit"]);
insta::assert_snapshot!(
stdout,
@r###"
@ -204,20 +208,21 @@ fn test_prev_editing() {
Parent commit : kkmpptxz 3fa8931e (empty) third
"###
);
insta::assert_snapshot!(stderr, @"");
}
#[test]
fn test_next_editing() {
// Edit the second commit.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "fourth"]);
test_env.jj_cmd_success(&repo_path, &["edit", "@--"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["next", "--edit"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "fourth"]);
test_env.jj_cmd_ok(&repo_path, &["edit", "@--"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["next", "--edit"]);
insta::assert_snapshot!(
stdout,
@r###"
@ -225,4 +230,5 @@ fn test_next_editing() {
Parent commit : kkmpptxz 3fa8931e (empty) third
"###
);
insta::assert_snapshot!(stderr, @"");
}

View file

@ -19,14 +19,14 @@ pub mod common;
#[test]
fn test_obslog_with_or_without_diff() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "-m", "my description"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "my description"]);
std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap();
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "@", "-d", "root()"]);
test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "@", "-d", "root()"]);
std::fs::write(repo_path.join("file1"), "resolved\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["obslog"]);
@ -147,7 +147,7 @@ fn test_obslog_with_or_without_diff() {
#[test]
fn test_obslog_word_wrap() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |args: &[&str], columns: u32, word_wrap: bool| {
let mut args = args.to_vec();
@ -163,7 +163,7 @@ fn test_obslog_word_wrap() {
get_stdout_string(&assert)
};
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]);
// ui.log-word-wrap option applies to both graph/no-graph outputs
insta::assert_snapshot!(render(&["obslog"], 40, false), @r###"
@ -201,17 +201,17 @@ fn test_obslog_word_wrap() {
#[test]
fn test_obslog_squash() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "first"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "first"]);
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "second"]);
std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap();
let edit_script = test_env.set_up_fake_editor();
std::fs::write(edit_script, "write\nsquashed").unwrap();
test_env.jj_cmd_success(&repo_path, &["squash"]);
test_env.jj_cmd_ok(&repo_path, &["squash"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "-p", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"

View file

@ -24,9 +24,9 @@ pub mod common;
#[test]
fn test_op_log() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description 0"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description 0"]);
let stdout = test_env.jj_cmd_success(
&repo_path,
@ -98,8 +98,8 @@ fn test_op_log() {
Error: Operation ID "" is not a valid hexadecimal prefix
"###);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description 1"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description 1"]);
test_env.jj_cmd_ok(
&repo_path,
&[
"describe",
@ -112,7 +112,7 @@ fn test_op_log() {
insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "@-"]), @r###"
Error: The "@-" expression resolved to more than one operation
"###);
test_env.jj_cmd_success(&repo_path, &["st"]);
test_env.jj_cmd_ok(&repo_path, &["st"]);
insta::assert_snapshot!(test_env.jj_cmd_failure(&repo_path, &["log", "--at-op", "@-"]), @r###"
Error: The "@-" expression resolved to more than one operation
"###);
@ -121,7 +121,7 @@ fn test_op_log() {
#[test]
fn test_op_log_limit() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log", "-Tdescription", "--limit=1"]);
@ -133,7 +133,7 @@ fn test_op_log_limit() {
#[test]
fn test_op_log_no_graph() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stdout =
@ -149,10 +149,10 @@ fn test_op_log_no_graph() {
#[test]
fn test_op_log_no_graph_null_terminated() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "message1"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "message2"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "message1"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "message2"]);
let stdout = test_env.jj_cmd_success(
&repo_path,
@ -170,7 +170,7 @@ fn test_op_log_no_graph_null_terminated() {
#[test]
fn test_op_log_template() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| test_env.jj_cmd_success(&repo_path, &["op", "log", "-T", template]);
@ -214,10 +214,10 @@ fn test_op_log_template() {
#[test]
fn test_op_log_builtin_templates() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| test_env.jj_cmd_success(&repo_path, &["op", "log", "-T", template]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description 0"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "description 0"]);
insta::assert_snapshot!(render(r#"builtin_op_log_compact"#), @r###"
@ 98f7262e4a06 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
@ -246,7 +246,7 @@ fn test_op_log_builtin_templates() {
#[test]
fn test_op_log_word_wrap() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |args: &[&str], columns: u32, word_wrap: bool| {
let mut args = args.to_vec();

View file

@ -20,20 +20,20 @@ pub mod common;
fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, parents: &[&str]) {
if parents.is_empty() {
test_env.jj_cmd_success(repo_path, &["new", "root()", "-m", name]);
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", name]);
} else {
let mut args = vec!["new", "-m", name];
args.extend(parents);
test_env.jj_cmd_success(repo_path, &args);
test_env.jj_cmd_ok(repo_path, &args);
}
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
}
#[test]
fn test_rebase_invalid() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -88,7 +88,7 @@ fn test_rebase_invalid() {
#[test]
fn test_rebase_branch() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -108,10 +108,11 @@ fn test_rebase_branch() {
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-b", "c", "-d", "e"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b", "c", "-d", "e"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 3 commits
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
d
c
@ -123,14 +124,15 @@ fn test_rebase_branch() {
"###);
// Test rebasing multiple branches at once
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-b=e", "-b=d", "-d=b"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b=e", "-b=d", "-d=b"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 2 commits
Working copy now at: znkkpsqq 9ca2a154 e | e
Parent commit : zsuskuln 1394f625 b | b
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
d
@ e
@ -143,7 +145,7 @@ fn test_rebase_branch() {
"###);
// Same test but with more than one revision per argument
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-b=e|d", "-d=b"]);
insta::assert_snapshot!(stderr, @r###"
Error: Revset "e|d" resolved to more than one revision
@ -152,13 +154,14 @@ fn test_rebase_branch() {
vruxwmqv 514fa6b2 d | d
Prefix the expression with 'all' to allow any number of revisions (i.e. 'all:e|d').
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-b=all:e|d", "-d=b"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b=all:e|d", "-d=b"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 2 commits
Working copy now at: znkkpsqq 817e3fb0 e | e
Parent commit : zsuskuln 1394f625 b | b
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
d
@ e
@ -174,7 +177,7 @@ fn test_rebase_branch() {
#[test]
fn test_rebase_branch_with_merge() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -195,13 +198,14 @@ fn test_rebase_branch_with_merge() {
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-b", "d", "-d", "b"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-b", "d", "-d", "b"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 3 commits
Working copy now at: znkkpsqq 391c91a7 e | e
Parent commit : vruxwmqv 1677f795 d | d
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ e
d
@ -211,14 +215,15 @@ fn test_rebase_branch_with_merge() {
"###);
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-d", "b"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-d", "b"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 3 commits
Working copy now at: znkkpsqq 040ae3a6 e | e
Parent commit : vruxwmqv 3d0f3644 d | d
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ e
d
@ -232,7 +237,7 @@ fn test_rebase_branch_with_merge() {
#[test]
fn test_rebase_single_revision() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -256,13 +261,14 @@ fn test_rebase_single_revision() {
// "a". However, since the root commit is an ancestor of "a", we don't
// actually want both to be parents of the same commit. So, only "a" becomes
// a parent.
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "b", "-d", "a"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "b", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 2 descendant commits onto parent of rebased commit
Working copy now at: vruxwmqv 7e15b97a d | d
Parent commit : royxmykx 934236c8 c | c
Added 0 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ d
c
@ -271,11 +277,11 @@ fn test_rebase_single_revision() {
a
"###);
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
// Now, let's try moving the merge commit. After, both parents of "c" ("a" and
// "b") should become parents of "d".
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "root()"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "c", "-d", "root()"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 1 descendant commits onto parent of rebased commit
Working copy now at: vruxwmqv bf87078f d | d
@ -283,6 +289,7 @@ fn test_rebase_single_revision() {
Parent commit : rlvkpnrz 2443ea76 a | a
Added 0 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ d
@ -298,7 +305,7 @@ fn test_rebase_single_revision() {
#[test]
fn test_rebase_single_revision_merge_parent() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -318,7 +325,7 @@ fn test_rebase_single_revision_merge_parent() {
// Descendants of the rebased commit should be rebased onto parents, and if
// the descendant is a merge commit, it shouldn't forget its other parents.
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "c", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Also rebased 1 descendant commits onto parent of rebased commit
Working copy now at: vruxwmqv c62d0789 d | d
@ -326,6 +333,7 @@ fn test_rebase_single_revision_merge_parent() {
Parent commit : rlvkpnrz 2443ea76 a | a
Added 0 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ d
@ -341,7 +349,7 @@ fn test_rebase_single_revision_merge_parent() {
#[test]
fn test_rebase_multiple_destinations() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -357,8 +365,10 @@ fn test_rebase_multiple_destinations() {
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "a", "-d", "b", "-d", "c"]);
insta::assert_snapshot!(stdout, @r###""###);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "a", "-d", "b", "-d", "c"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
a
@ -376,8 +386,9 @@ fn test_rebase_multiple_destinations() {
zsuskuln d370aee1 b | b
Prefix the expression with 'all' to allow any number of revisions (i.e. 'all:b|c').
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-r", "a", "-d", "all:b|c"]);
insta::assert_snapshot!(stdout, @r###""###);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "a", "-d", "all:b|c"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
a
@ -413,7 +424,7 @@ fn test_rebase_multiple_destinations() {
#[test]
fn test_rebase_with_descendants() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "a", &[]);
@ -431,12 +442,13 @@ fn test_rebase_with_descendants() {
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-s", "b", "-d", "a"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s", "b", "-d", "a"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 3 commits
Working copy now at: vruxwmqv 309336ff d | d
Parent commit : royxmykx 244fa794 c | c
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ d
c
@ -446,14 +458,15 @@ fn test_rebase_with_descendants() {
"###);
// Rebase several subtrees at once.
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-s=c", "-s=d", "-d=a"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=c", "-s=d", "-d=a"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 2 commits
Working copy now at: vruxwmqv 92c2bc9a d | d
Parent commit : rlvkpnrz 2443ea76 a | a
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ d
c
@ -464,7 +477,7 @@ fn test_rebase_with_descendants() {
"###);
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
// Reminder of the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ d
@ -478,13 +491,14 @@ fn test_rebase_with_descendants() {
// `d` was a descendant of `b`, and both are moved to be direct descendants of
// `a`. `c` remains a descendant of `b`.
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-s=b", "-s=d", "-d=a"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=b", "-s=d", "-d=a"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 3 commits
Working copy now at: vruxwmqv f1e71cb7 d | d
Parent commit : rlvkpnrz 2443ea76 a | a
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
c
b
@ -495,7 +509,7 @@ fn test_rebase_with_descendants() {
"###);
// Same test as above, but with multiple commits per argument
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-s=b|d", "-d=a"]);
insta::assert_snapshot!(stderr, @r###"
Error: Revset "b|d" resolved to more than one revision
@ -504,13 +518,14 @@ fn test_rebase_with_descendants() {
zsuskuln d370aee1 b | b
Prefix the expression with 'all' to allow any number of revisions (i.e. 'all:b|d').
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["rebase", "-s=all:b|d", "-d=a"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["rebase", "-s=all:b|d", "-d=a"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 3 commits
Working copy now at: vruxwmqv d17539f7 d | d
Parent commit : rlvkpnrz 2443ea76 a | a
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
c
b

View file

@ -26,16 +26,16 @@ fn create_commit(
files: &[(&str, &str)],
) {
if parents.is_empty() {
test_env.jj_cmd_success(repo_path, &["new", "root()", "-m", name]);
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", name]);
} else {
let mut args = vec!["new", "-m", name];
args.extend(parents);
test_env.jj_cmd_success(repo_path, &args);
test_env.jj_cmd_ok(repo_path, &args);
}
for (name, content) in files {
std::fs::write(repo_path.join(name), content).unwrap();
}
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
}
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
@ -45,7 +45,7 @@ fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
#[test]
fn test_resolution() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
@ -85,13 +85,14 @@ fn test_resolution() {
["dump editor0", "write\nresolution\n"].join("\0"),
)
.unwrap();
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["resolve"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["resolve"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv e069f073 conflict | conflict
Parent commit : zsuskuln aa493daf a | a
Parent commit : royxmykx db6a4daf b | b
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
"###);
@ -113,7 +114,7 @@ fn test_resolution() {
// Check that the output file starts with conflict markers if
// `merge-tool-edits-conflict-markers=true`
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
@"");
std::fs::write(
@ -121,7 +122,7 @@ fn test_resolution() {
["dump editor1", "write\nresolution\n"].join("\0"),
)
.unwrap();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&[
"resolve",
@ -153,7 +154,7 @@ fn test_resolution() {
// Check that if merge tool leaves conflict markers in output file and
// `merge-tool-edits-conflict-markers=true`, these markers are properly parsed.
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
@"");
std::fs::write(
@ -173,16 +174,15 @@ conflict
.join("\0"),
)
.unwrap();
insta::assert_snapshot!(
test_env.jj_cmd_success(
&repo_path,
&[
"resolve",
"--config-toml",
"merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
],
),
@r###"
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&[
"resolve",
"--config-toml",
"merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
],
);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv ff4e8c6b conflict | (conflict) conflict
Parent commit : zsuskuln aa493daf a | a
Parent commit : royxmykx db6a4daf b | b
@ -190,6 +190,7 @@ conflict
After this operation, some files at this revision still have conflicts:
file 2-sided conflict
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(), @r###"
<<<<<<<
@ -220,7 +221,7 @@ conflict
// Check that if merge tool leaves conflict markers in output file but
// `merge-tool-edits-conflict-markers=false` or is not specified,
// `jj` considers the conflict resolved.
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
@"");
std::fs::write(
@ -240,13 +241,14 @@ conflict
.join("\0"),
)
.unwrap();
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["resolve"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["resolve"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv 95418cb8 conflict | conflict
Parent commit : zsuskuln aa493daf a | a
Parent commit : royxmykx db6a4daf b | b
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor3")).unwrap(), @r###"
"###);
@ -296,7 +298,7 @@ fn check_resolve_produces_input_file(
#[test]
fn test_normal_conflict_input_files() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
@ -337,7 +339,7 @@ fn test_normal_conflict_input_files() {
#[test]
fn test_baseless_conflict_input_files() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[]);
@ -377,7 +379,7 @@ fn test_baseless_conflict_input_files() {
#[test]
fn test_too_many_parents() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
@ -404,7 +406,7 @@ fn test_too_many_parents() {
#[test]
fn test_edit_delete_conflict_input_files() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
@ -445,7 +447,7 @@ fn test_edit_delete_conflict_input_files() {
#[test]
fn test_file_vs_dir() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
@ -484,7 +486,7 @@ fn test_file_vs_dir() {
#[test]
fn test_description_with_dir_and_deletion() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
@ -539,7 +541,7 @@ fn test_description_with_dir_and_deletion() {
#[test]
fn test_multiple_conflicts() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(
@ -630,8 +632,8 @@ fn test_multiple_conflicts() {
// Check that we can manually pick which of the conflicts to resolve first
std::fs::write(&editor_script, "expect\n\0write\nresolution another_file\n").unwrap();
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["resolve", "another_file"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["resolve", "another_file"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv c3c25bce conflict | (conflict) conflict
Parent commit : zsuskuln de7553ef a | a
Parent commit : royxmykx f68bc2f0 b | b
@ -639,6 +641,7 @@ fn test_multiple_conflicts() {
After this operation, some files at this revision still have conflicts:
this_file_has_a_very_long_name_to_test_padding 2-sided conflict
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
@r###"
Resolved conflict in another_file:
@ -656,19 +659,20 @@ fn test_multiple_conflicts() {
"###);
// Repeat the above with the `--quiet` option.
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(&editor_script, "expect\n\0write\nresolution another_file\n").unwrap();
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["resolve", "--quiet", "another_file"]), @r###"
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["resolve", "--quiet", "another_file"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv fd3874cd conflict | (conflict) conflict
Parent commit : zsuskuln de7553ef a | a
Parent commit : royxmykx f68bc2f0 b | b
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
// For the rest of the test, we call `jj resolve` several times in a row to
// resolve each conflict in the order it chooses.
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
@"");
std::fs::write(
@ -676,7 +680,7 @@ fn test_multiple_conflicts() {
"expect\n\0write\nfirst resolution for auto-chosen file\n",
)
.unwrap();
test_env.jj_cmd_success(&repo_path, &["resolve"]);
test_env.jj_cmd_ok(&repo_path, &["resolve"]);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
@r###"
Resolved conflict in another_file:
@ -698,7 +702,7 @@ fn test_multiple_conflicts() {
)
.unwrap();
test_env.jj_cmd_success(&repo_path, &["resolve"]);
test_env.jj_cmd_ok(&repo_path, &["resolve"]);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
@r###"
Resolved conflict in another_file:

View file

@ -21,13 +21,13 @@ pub mod common;
#[test]
fn test_restore() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::remove_file(repo_path.join("file1")).unwrap();
std::fs::write(repo_path.join("file2"), "c\n").unwrap();
std::fs::write(repo_path.join("file3"), "c\n").unwrap();
@ -41,23 +41,24 @@ fn test_restore() {
"###);
// Restores from parent by default
let stdout = test_env.jj_cmd_success(&repo_path, &["restore"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore"]);
insta::assert_snapshot!(stdout, @r###"
Created kkmpptxz ed1678e3 (empty) (no description set)
Working copy now at: kkmpptxz ed1678e3 (empty) (no description set)
Parent commit : rlvkpnrz 1a986a27 (no description set)
Added 1 files, modified 1 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @"");
// Can restore another revision from its parents
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r=@-"]);
insta::assert_snapshot!(stdout, @r###"
A file2
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["restore", "-c=@-"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore", "-c=@-"]);
insta::assert_snapshot!(stdout, @r###"
Created rlvkpnrz e25100af (empty) (no description set)
Rebased 1 descendant commits
@ -65,32 +66,35 @@ fn test_restore() {
Parent commit : rlvkpnrz e25100af (empty) (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r=@-"]);
insta::assert_snapshot!(stdout, @"");
// Can restore this revision from another revision
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["restore", "--from", "@--"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore", "--from", "@--"]);
insta::assert_snapshot!(stdout, @r###"
Created kkmpptxz 1dd6eb63 (no description set)
Working copy now at: kkmpptxz 1dd6eb63 (no description set)
Parent commit : rlvkpnrz 1a986a27 (no description set)
Added 1 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file2
"###);
// Can restore into other revision
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["restore", "--to", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore", "--to", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Created rlvkpnrz ec9d5b59 (no description set)
Rebased 1 descendant commits
Working copy now at: kkmpptxz d6f3c681 (empty) (no description set)
Parent commit : rlvkpnrz ec9d5b59 (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]);
@ -101,14 +105,16 @@ fn test_restore() {
"###);
// Can combine `--from` and `--to`
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["restore", "--from", "@", "--to", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["restore", "--from", "@", "--to", "@-"]);
insta::assert_snapshot!(stdout, @r###"
Created rlvkpnrz 5f6eb3d5 (no description set)
Rebased 1 descendant commits
Working copy now at: kkmpptxz 525afd5d (empty) (no description set)
Parent commit : rlvkpnrz 5f6eb3d5 (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]);
@ -119,14 +125,15 @@ fn test_restore() {
"###);
// Can restore only specified paths
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["restore", "file2", "file3"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore", "file2", "file3"]);
insta::assert_snapshot!(stdout, @r###"
Created kkmpptxz 569ce73d (no description set)
Working copy now at: kkmpptxz 569ce73d (no description set)
Parent commit : rlvkpnrz 1a986a27 (no description set)
Added 0 files, modified 1 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###"
R file1
@ -137,7 +144,7 @@ fn test_restore() {
#[test]
fn test_restore_conflicted_merge() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
create_commit(&test_env, &repo_path, "base", &[], &[("file", "base\n")]);
@ -182,7 +189,7 @@ fn test_restore_conflicted_merge() {
"###);
// ...and restore it back again.
let stdout = test_env.jj_cmd_success(&repo_path, &["restore", "file"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore", "file"]);
insta::assert_snapshot!(stdout, @r###"
Created vruxwmqv b2c9c888 (conflict) (empty) conflict
Working copy now at: vruxwmqv b2c9c888 conflict | (conflict) (empty) conflict
@ -190,6 +197,7 @@ fn test_restore_conflicted_merge() {
Parent commit : royxmykx db6a4daf b | b
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(
std::fs::read_to_string(repo_path.join("file")).unwrap()
, @r###"
@ -220,7 +228,7 @@ fn test_restore_conflicted_merge() {
"###);
// ... and restore it back again.
let stdout = test_env.jj_cmd_success(&repo_path, &["restore"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["restore"]);
insta::assert_snapshot!(stdout, @r###"
Created vruxwmqv 4fc10820 (conflict) (empty) conflict
Working copy now at: vruxwmqv 4fc10820 conflict | (conflict) (empty) conflict
@ -228,6 +236,7 @@ fn test_restore_conflicted_merge() {
Parent commit : royxmykx db6a4daf b | b
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(
std::fs::read_to_string(repo_path.join("file")).unwrap()
, @r###"
@ -249,16 +258,16 @@ fn create_commit(
files: &[(&str, &str)],
) {
if parents.is_empty() {
test_env.jj_cmd_success(repo_path, &["new", "root()", "-m", name]);
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", name]);
} else {
let mut args = vec!["new", "-m", name];
args.extend(parents);
test_env.jj_cmd_success(repo_path, &args);
test_env.jj_cmd_ok(repo_path, &args);
}
for (name, content) in files {
std::fs::write(repo_path.join(name), content).unwrap();
}
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
}
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {

View file

@ -19,7 +19,7 @@ pub mod common;
#[test]
fn test_syntax_error() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "x &"]);
@ -58,7 +58,7 @@ fn test_syntax_error() {
#[test]
fn test_bad_function_call() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "all(or::nothing)"]);
@ -209,7 +209,7 @@ fn test_bad_function_call() {
#[test]
fn test_function_name_hint() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let evaluate_err = |expr| test_env.jj_cmd_failure(&repo_path, &["log", "-r", expr]);
@ -248,7 +248,7 @@ fn test_function_name_hint() {
#[test]
fn test_alias() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(
@ -348,7 +348,7 @@ fn test_alias() {
#[test]
fn test_alias_override() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(
@ -378,7 +378,7 @@ fn test_alias_override() {
#[test]
fn test_bad_alias_decl() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(

View file

@ -21,7 +21,7 @@ pub mod common;
#[test]
fn test_show() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stdout = test_env.jj_cmd_success(&repo_path, &["show"]);
@ -38,7 +38,7 @@ fn test_show() {
#[test]
fn test_show_relative_timestamps() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(

View file

@ -21,7 +21,7 @@ pub mod common;
#[test]
fn test_sparse_manage_patterns() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();
@ -38,10 +38,11 @@ fn test_sparse_manage_patterns() {
"###);
// Can stop tracking all files
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "set", "--remove", "."]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["sparse", "set", "--remove", "."]);
insta::assert_snapshot!(stdout, @r###"
Added 0 files, modified 0 files, removed 3 files
"###);
insta::assert_snapshot!(stderr, @"");
// The list is now empty
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "list"]);
insta::assert_snapshot!(stdout, @"");
@ -58,13 +59,14 @@ fn test_sparse_manage_patterns() {
"###);
// Can `--add` a few files
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["sparse", "set", "--add", "file2", "--add", "file3"],
);
insta::assert_snapshot!(stdout, @r###"
Added 2 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "list"]);
insta::assert_snapshot!(stdout, @r###"
file2
@ -75,7 +77,7 @@ fn test_sparse_manage_patterns() {
assert!(repo_path.join("file3").exists());
// Can combine `--add` and `--remove`
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&[
"sparse", "set", "--add", "file1", "--remove", "file2", "--remove", "file3",
@ -84,6 +86,7 @@ fn test_sparse_manage_patterns() {
insta::assert_snapshot!(stdout, @r###"
Added 1 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "list"]);
insta::assert_snapshot!(stdout, @r###"
file1
@ -93,11 +96,12 @@ fn test_sparse_manage_patterns() {
assert!(!repo_path.join("file3").exists());
// Can use `--clear` and `--add`
let stdout =
test_env.jj_cmd_success(&repo_path, &["sparse", "set", "--clear", "--add", "file2"]);
let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["sparse", "set", "--clear", "--add", "file2"]);
insta::assert_snapshot!(stdout, @r###"
Added 1 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "list"]);
insta::assert_snapshot!(stdout, @r###"
file2
@ -107,10 +111,11 @@ fn test_sparse_manage_patterns() {
assert!(!repo_path.join("file3").exists());
// Can reset back to all files
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "set", "--reset"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["sparse", "set", "--reset"]);
insta::assert_snapshot!(stdout, @r###"
Added 2 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "list"]);
insta::assert_snapshot!(stdout, @r###"
.
@ -131,10 +136,11 @@ fn test_sparse_manage_patterns() {
let read_patterns = || std::fs::read_to_string(test_env.env_root().join("patterns0")).unwrap();
edit_patterns(&["file1"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "set", "--edit"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["sparse", "set", "--edit"]);
insta::assert_snapshot!(stdout, @r###"
Added 0 files, modified 0 files, removed 2 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(read_patterns(), @".");
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "list"]);
insta::assert_snapshot!(stdout, @r###"
@ -143,13 +149,14 @@ fn test_sparse_manage_patterns() {
// Can edit with `--clear` and `--add`
edit_patterns(&["file2"]);
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&repo_path,
&["sparse", "set", "--edit", "--clear", "--add", "file1"],
);
insta::assert_snapshot!(stdout, @r###"
Added 1 files, modified 0 files, removed 1 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(read_patterns(), @"file1");
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "list"]);
insta::assert_snapshot!(stdout, @r###"
@ -158,10 +165,11 @@ fn test_sparse_manage_patterns() {
// Can edit with multiple files
edit_patterns(&["file2", "file3"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "set", "--clear", "--edit"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["sparse", "set", "--clear", "--edit"]);
insta::assert_snapshot!(stdout, @r###"
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(read_patterns(), @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["sparse", "list"]);
insta::assert_snapshot!(stdout, @r###"

View file

@ -21,7 +21,7 @@ pub mod common;
#[test]
fn test_split_by_paths() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "foo").unwrap();
@ -39,13 +39,14 @@ fn test_split_by_paths() {
["dump editor0", "next invocation\n", "dump editor1"].join("\0"),
)
.unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "file2"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["split", "file2"]);
insta::assert_snapshot!(stdout, @r###"
First part: qpvuntsm 5eebce1d (no description set)
Second part: kkmpptxz 45833353 (no description set)
Working copy now at: kkmpptxz 45833353 (no description set)
Parent commit : qpvuntsm 5eebce1d (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
JJ: Enter commit description for the first part (parent).
@ -75,7 +76,7 @@ fn test_split_by_paths() {
// Insert an empty commit after @- with "split ."
test_env.set_up_fake_editor();
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "-r", "@-", "."]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["split", "-r", "@-", "."]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
First part: qpvuntsm 31425b56 (no description set)
@ -83,6 +84,7 @@ fn test_split_by_paths() {
Working copy now at: kkmpptxz 28d4ec20 (no description set)
Parent commit : yqosqzyt af096392 (empty) (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ kkmpptxzrspx false
@ -97,7 +99,7 @@ fn test_split_by_paths() {
"###);
// Remove newly created empty commit
test_env.jj_cmd_success(&repo_path, &["abandon", "@-"]);
test_env.jj_cmd_ok(&repo_path, &["abandon", "@-"]);
// Insert an empty commit before @- with "split nonexistent"
test_env.set_up_fake_editor();
@ -129,13 +131,13 @@ fn test_split_by_paths() {
#[test]
fn test_split_with_non_empty_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
test_env.add_config(r#"ui.default-description = "\n\nTESTED=TODO""#);
let workspace_path = test_env.env_root().join("repo");
std::fs::write(workspace_path.join("file1"), "foo\n").unwrap();
std::fs::write(workspace_path.join("file2"), "bar\n").unwrap();
test_env.jj_cmd_success(&workspace_path, &["describe", "-m", "test"]);
test_env.jj_cmd_ok(&workspace_path, &["describe", "-m", "test"]);
let edit_script = test_env.set_up_fake_editor();
std::fs::write(
edit_script,
@ -149,7 +151,7 @@ fn test_split_with_non_empty_description() {
.join("\0"),
)
.unwrap();
test_env.jj_cmd_success(&workspace_path, &["split", "file1"]);
test_env.jj_cmd_ok(&workspace_path, &["split", "file1"]);
assert_eq!(
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(),
@ -183,7 +185,7 @@ JJ: Lines starting with "JJ: " (like this one) will be removed.
#[test]
fn test_split_with_default_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
test_env.add_config(r#"ui.default-description = "\n\nTESTED=TODO""#);
let workspace_path = test_env.env_root().join("repo");
@ -195,7 +197,7 @@ fn test_split_with_default_description() {
["dump editor1", "next invocation\n", "dump editor2"].join("\0"),
)
.unwrap();
test_env.jj_cmd_success(&workspace_path, &["split", "file1"]);
test_env.jj_cmd_ok(&workspace_path, &["split", "file1"]);
assert_eq!(
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(),

View file

@ -21,16 +21,16 @@ pub mod common;
#[test]
fn test_squash() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ -41,11 +41,12 @@ fn test_squash() {
"###);
// Squashes the working copy into the parent by default
let stdout = test_env.jj_cmd_success(&repo_path, &["squash"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: vruxwmqv b9280a98 (empty) (no description set)
Parent commit : kkmpptxz 6ca29c9d b c | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ b9280a9898cb
6ca29c9d2e7c b c
@ -58,13 +59,14 @@ fn test_squash() {
"###);
// Can squash a given commit into its parent
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl e87cf8eb c | (no description set)
Parent commit : qpvuntsm 893c93ae a b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ e87cf8ebc7e1 c
893c93ae2a87 a b
@ -81,13 +83,13 @@ fn test_squash() {
// Cannot squash a merge commit (because it's unclear which parent it should go
// into)
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["edit", "b"]);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "d"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["edit", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
std::fs::write(repo_path.join("file2"), "d\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "c", "d"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "e"]);
test_env.jj_cmd_ok(&repo_path, &["new", "c", "d"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "e"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ c7a11b36d333 e
@ -104,13 +106,14 @@ fn test_squash() {
"###);
// Can squash into a merge commit
test_env.jj_cmd_success(&repo_path, &["co", "e"]);
test_env.jj_cmd_ok(&repo_path, &["co", "e"]);
std::fs::write(repo_path.join("file1"), "e\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["squash"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: xlzxqlsl 959145c1 (empty) (no description set)
Parent commit : nmzmmopx 80960125 e | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 959145c11426
80960125bb96 e
@ -131,18 +134,18 @@ fn test_squash() {
#[test]
fn test_squash_partial() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
std::fs::write(repo_path.join("file2"), "c\n").unwrap();
// Test the setup
@ -156,12 +159,13 @@ fn test_squash_partial() {
// If we don't make any changes in the diff-editor, the whole change is moved
// into the parent
let edit_script = test_env.set_up_fake_diff_editor();
let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b", "-i"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "-i"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl f03d5ce4 c | (no description set)
Parent commit : qpvuntsm c9f931cd a b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ f03d5ce4a973 c
c9f931cd78af a b
@ -173,14 +177,15 @@ fn test_squash_partial() {
"###);
// Can squash only some changes in interactive mode
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(&edit_script, "reset file1").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b", "-i"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "-i"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl e7a40106 c | (no description set)
Parent commit : kkmpptxz 05d95164 b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ e7a40106bee6 c
05d951646873 b
@ -205,15 +210,16 @@ fn test_squash_partial() {
"###);
// Can squash only some changes in non-interactive mode
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
// Clear the script so we know it won't be used even without -i
std::fs::write(&edit_script, "").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b", "file2"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "file2"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl a911fa1d c | (no description set)
Parent commit : kkmpptxz fb73ad17 b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ a911fa1d0627 c
fb73ad17899f b
@ -239,16 +245,17 @@ fn test_squash_partial() {
// If we specify only a non-existent file, then the squash still succeeds and
// creates unchanged commits.
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b", "nonexistent"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "nonexistent"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl 5e297967 c | (no description set)
Parent commit : kkmpptxz ac258609 b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
// We get a warning if we pass a positional argument that looks like a revset
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "b"]);
insta::assert_snapshot!(stderr, @r###"
warning: The argument "b" is being interpreted as a path. To specify a revset, pass -r "b" instead.
@ -267,7 +274,7 @@ fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
#[test]
fn test_squash_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();
@ -276,42 +283,42 @@ fn test_squash_description() {
// If both descriptions are empty, the resulting description is empty
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["squash"]);
test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @"");
// If the destination's description is empty and the source's description is
// non-empty, the resulting description is from the source
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
test_env.jj_cmd_success(&repo_path, &["squash"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "source"]);
test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
source
"###);
// If the destination description is non-empty and the source's description is
// empty, the resulting description is from the destination
test_env.jj_cmd_success(&repo_path, &["op", "restore", "@--"]);
test_env.jj_cmd_success(&repo_path, &["describe", "@-", "-m", "destination"]);
test_env.jj_cmd_success(&repo_path, &["squash"]);
test_env.jj_cmd_ok(&repo_path, &["op", "restore", "@--"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "@-", "-m", "destination"]);
test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
destination
"###);
// An explicit description on the command-line overrides this
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["squash", "-m", "custom"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["squash", "-m", "custom"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
custom
"###);
// If both descriptions were non-empty, we get asked for a combined description
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "source"]);
std::fs::write(&edit_script, "dump editor0").unwrap();
test_env.jj_cmd_success(&repo_path, &["squash"]);
test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
destination
@ -331,16 +338,16 @@ fn test_squash_description() {
// An explicit description on the command-line overrides prevents launching an
// editor
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["squash", "-m", "custom"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["squash", "-m", "custom"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
custom
"###);
// If the source's *content* doesn't become empty, then the source remains and
// both descriptions are unchanged
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["squash", "file1"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["squash", "file1"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
destination
"###);
@ -352,23 +359,24 @@ fn test_squash_description() {
#[test]
fn test_squash_empty() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "parent"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "parent"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["squash"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: kkmpptxz e45abe2c (empty) (no description set)
Parent commit : qpvuntsm 1265289b (empty) parent
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
parent
"###);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "child"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "child"]);
test_env.set_up_fake_editor();
test_env.jj_cmd_success(&repo_path, &["squash"]);
test_env.jj_cmd_ok(&repo_path, &["squash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
parent

View file

@ -19,15 +19,15 @@ pub mod common;
#[test]
fn test_status_merge() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "base").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "-m=left"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "left"]);
test_env.jj_cmd_success(&repo_path, &["new", "@-", "-m=right"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m=left"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]);
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m=right"]);
std::fs::write(repo_path.join("file"), "right").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "left", "@"]);
test_env.jj_cmd_ok(&repo_path, &["new", "left", "@"]);
// The output should mention each parent, and the diff should be empty (compared
// to the auto-merged parents)
@ -44,7 +44,7 @@ fn test_status_merge() {
#[test]
fn test_status_ignored_gitignore() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::create_dir(repo_path.join("untracked")).unwrap();

View file

@ -23,7 +23,7 @@ fn test_templater_branches() {
let test_env = TestEnvironment::default();
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "origin"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "origin"]);
let origin_path = test_env.env_root().join("origin");
let origin_git_repo_path = origin_path
.join(".jj")
@ -32,14 +32,14 @@ fn test_templater_branches() {
.join("git");
// Created some branches on the remote
test_env.jj_cmd_success(&origin_path, &["describe", "-m=description 1"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "branch1"]);
test_env.jj_cmd_success(&origin_path, &["new", "root()", "-m=description 2"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "branch2"]);
test_env.jj_cmd_success(&origin_path, &["new", "root()", "-m=description 3"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "branch3"]);
test_env.jj_cmd_success(&origin_path, &["git", "export"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&origin_path, &["describe", "-m=description 1"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "branch1"]);
test_env.jj_cmd_ok(&origin_path, &["new", "root()", "-m=description 2"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "branch2"]);
test_env.jj_cmd_ok(&origin_path, &["new", "root()", "-m=description 3"]);
test_env.jj_cmd_ok(&origin_path, &["branch", "create", "branch3"]);
test_env.jj_cmd_ok(&origin_path, &["git", "export"]);
test_env.jj_cmd_ok(
test_env.env_root(),
&[
"git",
@ -52,17 +52,17 @@ fn test_templater_branches() {
// Rewrite branch1, move branch2 forward, create conflict in branch3, add
// new-branch
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&workspace_root,
&["describe", "branch1", "-m", "modified branch1 commit"],
);
test_env.jj_cmd_success(&workspace_root, &["new", "branch2"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "branch2"]);
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "new-branch"]);
test_env.jj_cmd_success(&workspace_root, &["describe", "branch3", "-m=local"]);
test_env.jj_cmd_success(&origin_path, &["describe", "branch3", "-m=origin"]);
test_env.jj_cmd_success(&origin_path, &["git", "export"]);
test_env.jj_cmd_success(&workspace_root, &["git", "fetch"]);
test_env.jj_cmd_ok(&workspace_root, &["new", "branch2"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "branch2"]);
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "new-branch"]);
test_env.jj_cmd_ok(&workspace_root, &["describe", "branch3", "-m=local"]);
test_env.jj_cmd_ok(&origin_path, &["describe", "branch3", "-m=origin"]);
test_env.jj_cmd_ok(&origin_path, &["git", "export"]);
test_env.jj_cmd_ok(&workspace_root, &["git", "fetch"]);
let template = r#"commit_id.short() ++ " " ++ branches"#;
let output = test_env.jj_cmd_success(&workspace_root, &["log", "-T", template]);
@ -82,7 +82,7 @@ fn test_templater_branches() {
#[test]
fn test_templater_parsed_tree() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_template_output(&test_env, &repo_path, "@-", template);
@ -111,7 +111,7 @@ fn test_templater_parsed_tree() {
#[test]
fn test_templater_parse_error() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render_err = |template| test_env.jj_cmd_failure(&repo_path, &["log", "-T", template]);
@ -267,7 +267,7 @@ fn test_templater_parse_error() {
#[test]
fn test_templater_list_method() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_template_output(&test_env, &repo_path, "@-", template);
let render_err = |template| test_env.jj_cmd_failure(&repo_path, &["log", "-T", template]);
@ -363,9 +363,9 @@ fn test_templater_list_method() {
#[test]
fn test_templater_string_method() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["commit", "-m=description 1"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m=description 1"]);
let render = |template| get_template_output(&test_env, &repo_path, "@-", template);
insta::assert_snapshot!(render(r#""fooo".contains("foo")"#), @"true");
@ -416,18 +416,18 @@ fn test_templater_string_method() {
#[test]
fn test_templater_signature() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_template_output(&test_env, &repo_path, "@", template);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
insta::assert_snapshot!(render(r#"author"#), @"Test User <test.user@example.com>");
insta::assert_snapshot!(render(r#"author.name()"#), @"Test User");
insta::assert_snapshot!(render(r#"author.email()"#), @"test.user@example.com");
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["--config-toml=user.name='Another Test User'", "new"],
);
@ -437,7 +437,7 @@ fn test_templater_signature() {
insta::assert_snapshot!(render(r#"author.email()"#), @"test.user@example.com");
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&[
"--config-toml=user.email='test.user@invalid@example.com'",
@ -450,13 +450,13 @@ fn test_templater_signature() {
insta::assert_snapshot!(render(r#"author.email()"#), @"test.user@invalid@example.com");
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user");
test_env.jj_cmd_success(&repo_path, &["--config-toml=user.email='test.user'", "new"]);
test_env.jj_cmd_ok(&repo_path, &["--config-toml=user.email='test.user'", "new"]);
insta::assert_snapshot!(render(r#"author"#), @"Test User <test.user>");
insta::assert_snapshot!(render(r#"author.email()"#), @"test.user");
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user");
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&[
"--config-toml=user.email='test.user+tag@example.com'",
@ -468,7 +468,7 @@ fn test_templater_signature() {
insta::assert_snapshot!(render(r#"author.email()"#), @"test.user+tag@example.com");
insta::assert_snapshot!(render(r#"author.username()"#), @"test.user+tag");
test_env.jj_cmd_success(&repo_path, &["--config-toml=user.email='x@y'", "new"]);
test_env.jj_cmd_ok(&repo_path, &["--config-toml=user.email='x@y'", "new"]);
insta::assert_snapshot!(render(r#"author"#), @"Test User <x@y>");
insta::assert_snapshot!(render(r#"author.email()"#), @"x@y");
@ -506,7 +506,7 @@ fn test_templater_signature() {
#[test]
fn test_templater_timestamp_method() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_template_output(&test_env, &repo_path, "@-", template);
let render_err = |template| test_env.jj_cmd_failure(&repo_path, &["log", "-T", template]);
@ -573,7 +573,7 @@ fn test_templater_timestamp_method() {
#[test]
fn test_templater_fill_function() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_colored_template_output(&test_env, &repo_path, "@-", template);
@ -672,7 +672,7 @@ fn test_templater_fill_function() {
#[test]
fn test_templater_indent_function() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_colored_template_output(&test_env, &repo_path, "@-", template);
@ -720,7 +720,7 @@ fn test_templater_indent_function() {
#[test]
fn test_templater_label_function() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_colored_template_output(&test_env, &repo_path, "@-", template);
@ -739,7 +739,7 @@ fn test_templater_label_function() {
#[test]
fn test_templater_concat_function() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_colored_template_output(&test_env, &repo_path, "@-", template);
@ -753,7 +753,7 @@ fn test_templater_concat_function() {
#[test]
fn test_templater_separate_function() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_colored_template_output(&test_env, &repo_path, "@-", template);
@ -804,7 +804,7 @@ fn test_templater_separate_function() {
#[test]
fn test_templater_upper_lower() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_colored_template_output(&test_env, &repo_path, "@-", template);
@ -818,7 +818,7 @@ fn test_templater_upper_lower() {
#[test]
fn test_templater_alias() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let render = |template| get_template_output(&test_env, &repo_path, "@-", template);
let render_err = |template| test_env.jj_cmd_failure(&repo_path, &["log", "-T", template]);
@ -954,7 +954,7 @@ fn test_templater_alias() {
#[test]
fn test_templater_alias_override() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(
@ -984,7 +984,7 @@ fn test_templater_alias_override() {
#[test]
fn test_templater_bad_alias_decl() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(

View file

@ -20,16 +20,16 @@ pub mod common;
fn test_enable_tree_level_conflicts() {
let test_env = TestEnvironment::default();
test_env.add_config(r#"format.tree-level-conflicts = false"#);
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
// Create a few commits before we enable tree-level conflicts
let file_path = repo_path.join("file");
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m=left"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m=left"]);
std::fs::write(&file_path, "left").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "root()", "-m=right"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m=right"]);
std::fs::write(&file_path, "right").unwrap();
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&[
"new",
@ -38,7 +38,7 @@ fn test_enable_tree_level_conflicts() {
"-m=merge",
],
);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
@ mzvwutvl test.user@example.com 2001-02-03 04:05:11.000 +07:00 f2101bed conflict
@ -74,7 +74,7 @@ fn test_enable_tree_level_conflicts() {
// If we create new commit off of an unconflicted commit, it correctly appears
// empty
test_env.jj_cmd_success(&repo_path, &["new", "k"]);
test_env.jj_cmd_ok(&repo_path, &["new", "k"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r=@"]);
insta::assert_snapshot!(stdout, @r###"
@ yostqsxw test.user@example.com 2001-02-03 04:05:15.000 +07:00 112f0ac2

View file

@ -22,21 +22,21 @@ fn test_undo_rewrite_with_child() {
// Test that if we undo an operation that rewrote some commit, any descendants
// after that will be rebased on top of the un-rewritten commit.
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "modified"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "modified"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
let op_id_hex = stdout[3..15].to_string();
test_env.jj_cmd_success(&repo_path, &["new", "-m", "child"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "child"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description"]);
insta::assert_snapshot!(stdout, @r###"
@ child
modified
"###);
test_env.jj_cmd_success(&repo_path, &["undo", &op_id_hex]);
test_env.jj_cmd_ok(&repo_path, &["undo", &op_id_hex]);
// Since we undid the description-change, the child commit should now be on top
// of the initial commit
@ -54,15 +54,15 @@ fn test_git_push_undo() {
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
let git_repo_path = test_env.env_root().join("git-repo");
git2::Repository::init_bare(git_repo_path).unwrap();
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "git-repo", "repo"]);
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "git-repo", "repo"]);
let repo_path = test_env.env_root().join("repo");
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "AA"]);
test_env.jj_cmd_success(&repo_path, &["git", "push"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "AA"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push"]);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "BB"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "BB"]);
// Refs at this point look as follows (-- means no ref)
// | jj refs | jj's | git
// | | git | repo
@ -75,7 +75,7 @@ fn test_git_push_undo() {
@origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 0cffb614 (empty) AA
"###);
let pre_push_opid = test_env.current_operation_id(&repo_path);
test_env.jj_cmd_success(&repo_path, &["git", "push"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push"]);
// | jj refs | jj's | git
// | | git | repo
// | |tracking|
@ -87,7 +87,7 @@ fn test_git_push_undo() {
"###);
// Undo the push
test_env.jj_cmd_success(&repo_path, &["op", "restore", &pre_push_opid]);
test_env.jj_cmd_ok(&repo_path, &["op", "restore", &pre_push_opid]);
// | jj refs | jj's | git
// | | git | repo
// | |tracking|
@ -99,8 +99,8 @@ fn test_git_push_undo() {
@origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 0cffb614 (empty) AA
"###);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "CC"]);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "CC"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
// TODO: The user would probably not expect a conflict here. It currently is
// because the undo made us forget that the remote was at v2, so the fetch
// made us think it updated from v1 to v2 (instead of the no-op it could
@ -126,15 +126,15 @@ fn test_git_push_undo_with_import() {
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
let git_repo_path = test_env.env_root().join("git-repo");
git2::Repository::init_bare(git_repo_path).unwrap();
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "git-repo", "repo"]);
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "git-repo", "repo"]);
let repo_path = test_env.env_root().join("repo");
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "AA"]);
test_env.jj_cmd_success(&repo_path, &["git", "push"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "AA"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push"]);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "BB"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "BB"]);
// Refs at this point look as follows (-- means no ref)
// | jj refs | jj's | git
// | | git | repo
@ -147,7 +147,7 @@ fn test_git_push_undo_with_import() {
@origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 0cffb614 (empty) AA
"###);
let pre_push_opid = test_env.current_operation_id(&repo_path);
test_env.jj_cmd_success(&repo_path, &["git", "push"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push"]);
// | jj refs | jj's | git
// | | git | repo
// | |tracking|
@ -159,7 +159,7 @@ fn test_git_push_undo_with_import() {
"###);
// Undo the push
test_env.jj_cmd_success(&repo_path, &["op", "restore", &pre_push_opid]);
test_env.jj_cmd_ok(&repo_path, &["op", "restore", &pre_push_opid]);
// | jj refs | jj's | git
// | | git | repo
// | |tracking|
@ -174,7 +174,7 @@ fn test_git_push_undo_with_import() {
// PROBLEM: inserting this import changes the outcome compared to previous test
// TODO: decide if this is the better behavior, and whether import of
// remote-tracking branches should happen on every operation.
test_env.jj_cmd_success(&repo_path, &["git", "import"]);
test_env.jj_cmd_ok(&repo_path, &["git", "import"]);
// | jj refs | jj's | git
// | | git | repo
// | |tracking|
@ -185,8 +185,8 @@ fn test_git_push_undo_with_import() {
main: qpvuntsm 8c05de15 (empty) BB
"###);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "CC"]);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "CC"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
// There is not a conflict. This seems like a good outcome; undoing `git push`
// was essentially a no-op.
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
@ -205,14 +205,14 @@ fn test_git_push_undo_colocated() {
git2::Repository::init_bare(git_repo_path.clone()).unwrap();
let repo_path = test_env.env_root().join("clone");
git2::Repository::clone(git_repo_path.to_str().unwrap(), &repo_path).unwrap();
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]);
test_env.jj_cmd_ok(&repo_path, &["init", "--git-repo=."]);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "AA"]);
test_env.jj_cmd_success(&repo_path, &["git", "push"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "AA"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push"]);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "BB"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "BB"]);
// Refs at this point look as follows (-- means no ref)
// | jj refs | jj's | git
// | | git | repo
@ -225,7 +225,7 @@ fn test_git_push_undo_colocated() {
@origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 0cffb614 (empty) AA
"###);
let pre_push_opid = test_env.current_operation_id(&repo_path);
test_env.jj_cmd_success(&repo_path, &["git", "push"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push"]);
// | jj refs | jj's | git
// | | git | repo
// | |tracking|
@ -237,7 +237,7 @@ fn test_git_push_undo_colocated() {
"###);
// Undo the push
test_env.jj_cmd_success(&repo_path, &["op", "restore", &pre_push_opid]);
test_env.jj_cmd_ok(&repo_path, &["op", "restore", &pre_push_opid]);
// === Before auto-export ====
// | jj refs | jj's | git
// | | git | repo
@ -257,8 +257,8 @@ fn test_git_push_undo_colocated() {
@origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 0cffb614 (empty) AA
"###);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "CC"]);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "CC"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
// We have the same conflict as `test_git_push_undo`. TODO: why did we get the
// same result in a seemingly different way?
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
@ -280,27 +280,27 @@ fn test_git_push_undo_repo_only() {
test_env.add_config(r#"revset-aliases."immutable_heads()" = "none()""#);
let git_repo_path = test_env.env_root().join("git-repo");
git2::Repository::init_bare(git_repo_path).unwrap();
test_env.jj_cmd_success(test_env.env_root(), &["git", "clone", "git-repo", "repo"]);
test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "git-repo", "repo"]);
let repo_path = test_env.env_root().join("repo");
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "AA"]);
test_env.jj_cmd_success(&repo_path, &["git", "push"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "AA"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
main: qpvuntsm 0cffb614 (empty) AA
"###);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "BB"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "BB"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
main: qpvuntsm 8c05de15 (empty) BB
@origin (ahead by 1 commits, behind by 1 commits): qpvuntsm 0cffb614 (empty) AA
"###);
let pre_push_opid = test_env.current_operation_id(&repo_path);
test_env.jj_cmd_success(&repo_path, &["git", "push"]);
test_env.jj_cmd_ok(&repo_path, &["git", "push"]);
// Undo the push, but keep both the git_refs and the remote-tracking branches
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&repo_path,
&["op", "restore", "--what=repo", &pre_push_opid],
);
@ -308,8 +308,8 @@ fn test_git_push_undo_repo_only() {
main: qpvuntsm 8c05de15 (empty) BB
"###);
test_env.advance_test_rng_seed_to_multiple_of(100_000);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "CC"]);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "CC"]);
test_env.jj_cmd_ok(&repo_path, &["git", "fetch"]);
// This currently gives an identical result to `test_git_push_undo_import`.
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
main: qpvuntsm 0a3e99f0 (empty) CC

View file

@ -21,16 +21,16 @@ pub mod common;
#[test]
fn test_unsquash() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ -41,11 +41,12 @@ fn test_unsquash() {
"###);
// Unsquashes into the working copy from its parent by default
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: mzvwutvl 1b10d78f c | (no description set)
Parent commit : qpvuntsm 90aeefd0 a b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 1b10d78f6136 c
90aeefd03044 a b
@ -57,13 +58,14 @@ fn test_unsquash() {
"###);
// Can unsquash into a given commit from its parent
test_env.jj_cmd_success(&repo_path, &["undo"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash", "-r", "b"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash", "-r", "b"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl 45b8b3dd c | (no description set)
Parent commit : kkmpptxz 9146bcc8 b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 45b8b3ddc25a c
9146bcc8d996 b
@ -80,13 +82,13 @@ fn test_unsquash() {
// Cannot unsquash into a merge commit (because it's unclear which parent it
// should come from)
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["edit", "b"]);
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "d"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["edit", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
std::fs::write(repo_path.join("file2"), "d\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new", "-m", "merge", "c", "d"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "e"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "merge", "c", "d"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "e"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 1f8f152ff48e e
@ -103,14 +105,15 @@ fn test_unsquash() {
"###);
// Can unsquash from a merge commit
test_env.jj_cmd_success(&repo_path, &["co", "e"]);
test_env.jj_cmd_ok(&repo_path, &["co", "e"]);
std::fs::write(repo_path.join("file1"), "e\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: pzsxstzt 3217340c merge
Parent commit : mzvwutvl 90fe0a96 c e?? | (no description set)
Parent commit : xznxytkn 5658521e d e?? | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 3217340cb761
@ -130,18 +133,18 @@ fn test_unsquash() {
#[test]
fn test_unsquash_partial() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
std::fs::write(repo_path.join("file2"), "c\n").unwrap();
// Test the setup
@ -155,12 +158,13 @@ fn test_unsquash_partial() {
// If we don't make any changes in the diff-editor, the whole change is moved
// from the parent
let edit_script = test_env.set_up_fake_diff_editor();
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash", "-r", "b", "-i"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash", "-r", "b", "-i"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl 37c961d0 c | (no description set)
Parent commit : kkmpptxz 000af220 b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 37c961d0d1e2 c
000af22057b9 b
@ -173,13 +177,14 @@ fn test_unsquash_partial() {
"###);
// Can unsquash only some changes in interactive mode
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
std::fs::write(edit_script, "reset file1").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash", "-i"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash", "-i"]);
insta::assert_snapshot!(stdout, @r###"
Working copy now at: mzvwutvl a8e8fded c | (no description set)
Parent commit : kkmpptxz 46cc0667 b | (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ a8e8fded1021 c
46cc06672a99 b
@ -212,7 +217,7 @@ fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
#[test]
fn test_unsquash_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();
@ -221,35 +226,35 @@ fn test_unsquash_description() {
// If both descriptions are empty, the resulting description is empty
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["new"]);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
test_env.jj_cmd_success(&repo_path, &["unsquash"]);
test_env.jj_cmd_ok(&repo_path, &["unsquash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @"");
// If the destination's description is empty and the source's description is
// non-empty, the resulting description is from the source
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["describe", "@-", "-m", "source"]);
test_env.jj_cmd_success(&repo_path, &["unsquash"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "@-", "-m", "source"]);
test_env.jj_cmd_ok(&repo_path, &["unsquash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
source
"###);
// If the destination description is non-empty and the source's description is
// empty, the resulting description is from the destination
test_env.jj_cmd_success(&repo_path, &["op", "restore", "@--"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "destination"]);
test_env.jj_cmd_success(&repo_path, &["unsquash"]);
test_env.jj_cmd_ok(&repo_path, &["op", "restore", "@--"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "destination"]);
test_env.jj_cmd_ok(&repo_path, &["unsquash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
destination
"###);
// If both descriptions were non-empty, we get asked for a combined description
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_success(&repo_path, &["describe", "@-", "-m", "source"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["describe", "@-", "-m", "source"]);
std::fs::write(&edit_script, "dump editor0").unwrap();
test_env.jj_cmd_success(&repo_path, &["unsquash"]);
test_env.jj_cmd_ok(&repo_path, &["unsquash"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
destination
@ -269,7 +274,7 @@ fn test_unsquash_description() {
// If the source's *content* doesn't become empty, then the source remains and
// both descriptions are unchanged
test_env.jj_cmd_success(&repo_path, &["undo"]);
test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
source
"###);

View file

@ -22,7 +22,7 @@ pub mod common;
fn test_untrack() {
let test_env = TestEnvironment::default();
test_env.add_config(r#"ui.allow-init-native = true"#);
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "initial").unwrap();
@ -35,7 +35,7 @@ fn test_untrack() {
// Run a command so all the files get tracked, then add "*.bak" to the ignore
// patterns
test_env.jj_cmd_success(&repo_path, &["st"]);
test_env.jj_cmd_ok(&repo_path, &["st"]);
std::fs::write(repo_path.join(".gitignore"), "*.bak\n").unwrap();
let files_before = test_env.jj_cmd_success(&repo_path, &["files"]);
@ -68,8 +68,9 @@ fn test_untrack() {
// Can untrack a single file
assert!(files_before.contains("file1.bak\n"));
let stdout = test_env.jj_cmd_success(&repo_path, &["untrack", "file1.bak"]);
assert_eq!(stdout, "");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "file1.bak"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let files_after = test_env.jj_cmd_success(&repo_path, &["files"]);
// The file is no longer tracked
assert!(!files_after.contains("file1.bak"));
@ -92,8 +93,9 @@ fn test_untrack() {
// Can untrack after adding to ignore patterns
std::fs::write(repo_path.join(".gitignore"), ".bak\ntarget/\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["untrack", "target"]);
assert_eq!(stdout, "");
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "target"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let files_after = test_env.jj_cmd_success(&repo_path, &["files"]);
assert!(!files_after.contains("target"));
}
@ -102,7 +104,7 @@ fn test_untrack() {
fn test_untrack_sparse() {
let test_env = TestEnvironment::default();
test_env.add_config(r#"ui.allow-init-native = true"#);
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "contents").unwrap();
@ -116,9 +118,10 @@ fn test_untrack_sparse() {
file1
file2
"###);
test_env.jj_cmd_success(&repo_path, &["sparse", "set", "--clear", "--add", "file1"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["untrack", "file2"]);
test_env.jj_cmd_ok(&repo_path, &["sparse", "set", "--clear", "--add", "file1"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "file2"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
let stdout = test_env.jj_cmd_success(&repo_path, &["files"]);
insta::assert_snapshot!(stdout, @r###"
file1

View file

@ -19,7 +19,7 @@ pub mod common;
#[test]
fn test_snapshot_large_file() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(r#"snapshot.max-new-file-size = "10""#);

View file

@ -22,19 +22,19 @@ pub mod common;
#[test]
fn test_workspaces_add_second_workspace() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
let main_path = test_env.env_root().join("main");
let secondary_path = test_env.env_root().join("secondary");
std::fs::write(main_path.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&main_path, &["commit", "-m", "initial"]);
test_env.jj_cmd_ok(&main_path, &["commit", "-m", "initial"]);
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
insta::assert_snapshot!(stdout, @r###"
default: rlvkpnrz e0e6d567 (empty) (no description set)
"###);
let stdout = test_env.jj_cmd_success(
let (stdout, stderr) = test_env.jj_cmd_ok(
&main_path,
&["workspace", "add", "--name", "second", "../secondary"],
);
@ -44,6 +44,7 @@ fn test_workspaces_add_second_workspace() {
Parent commit : qpvuntsm 7d308bc9 initial
Added 1 files, modified 0 files, removed 0 files
"###);
insta::assert_snapshot!(stderr.replace('\\', "/"), @"");
// Can see the working-copy commit in each workspace in the log output. The "@"
// node in the graph indicates the current workspace's working-copy commit.
@ -75,14 +76,14 @@ fn test_workspaces_add_second_workspace() {
#[test]
fn test_workspaces_conflicting_edits() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
let main_path = test_env.env_root().join("main");
let secondary_path = test_env.env_root().join("secondary");
std::fs::write(main_path.join("file"), "contents\n").unwrap();
test_env.jj_cmd_success(&main_path, &["new"]);
test_env.jj_cmd_ok(&main_path, &["new"]);
test_env.jj_cmd_success(&main_path, &["workspace", "add", "../secondary"]);
test_env.jj_cmd_ok(&main_path, &["workspace", "add", "../secondary"]);
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
265af0cdbcc7bb33e3734ad72565c943ce3fb0d4 secondary@
@ -97,12 +98,13 @@ fn test_workspaces_conflicting_edits() {
std::fs::write(secondary_path.join("file"), "changed in second\n").unwrap();
// Squash the changes from the main workspace into the initial commit (before
// running any command in the secondary workspace
let stdout = test_env.jj_cmd_success(&main_path, &["squash"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&main_path, &["squash"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl fe8f41ed (empty) (no description set)
Parent commit : qpvuntsm c0d4a99e (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
// The secondary workspace's working-copy commit was updated
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
@ -125,7 +127,7 @@ fn test_workspaces_conflicting_edits() {
Hint: Run `jj workspace update-stale` to update it.
See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-working-copy for more information.
"###);
let stdout = test_env.jj_cmd_success(&secondary_path, &["workspace", "update-stale"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["workspace", "update-stale"]);
// It was detected that the working copy is now stale.
// Since there was an uncommitted change in the working copy, it should
// have been committed first (causing divergence)
@ -135,6 +137,7 @@ fn test_workspaces_conflicting_edits() {
Working copy now at: pmmvwywv a1896a17 (empty) (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &secondary_path),
@r###"
a3c96849ef9f124cbfc2416dc13bf17309d5020a (divergent)
@ -163,14 +166,14 @@ fn test_workspaces_conflicting_edits() {
#[test]
fn test_workspaces_updated_by_other() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
let main_path = test_env.env_root().join("main");
let secondary_path = test_env.env_root().join("secondary");
std::fs::write(main_path.join("file"), "contents\n").unwrap();
test_env.jj_cmd_success(&main_path, &["new"]);
test_env.jj_cmd_ok(&main_path, &["new"]);
test_env.jj_cmd_success(&main_path, &["workspace", "add", "../secondary"]);
test_env.jj_cmd_ok(&main_path, &["workspace", "add", "../secondary"]);
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
265af0cdbcc7bb33e3734ad72565c943ce3fb0d4 secondary@
@ -182,12 +185,13 @@ fn test_workspaces_updated_by_other() {
// Rewrite the check-out commit in one workspace.
std::fs::write(main_path.join("file"), "changed in main\n").unwrap();
let stdout = test_env.jj_cmd_success(&main_path, &["squash"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&main_path, &["squash"]);
insta::assert_snapshot!(stdout, @r###"
Rebased 1 descendant commits
Working copy now at: mzvwutvl fe8f41ed (empty) (no description set)
Parent commit : qpvuntsm c0d4a99e (no description set)
"###);
insta::assert_snapshot!(stderr, @"");
// The secondary workspace's working-copy commit was updated.
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
@ -203,13 +207,14 @@ fn test_workspaces_updated_by_other() {
Hint: Run `jj workspace update-stale` to update it.
See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-working-copy for more information.
"###);
let stdout = test_env.jj_cmd_success(&secondary_path, &["workspace", "update-stale"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["workspace", "update-stale"]);
// It was detected that the working copy is now stale, but clean. So no
// divergent commit should be created.
insta::assert_snapshot!(stdout, @r###"
Working copy now at: pmmvwywv a1896a17 (empty) (no description set)
Added 0 files, modified 1 files, removed 0 files
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &secondary_path),
@r###"
fe8f41ed01d693b2d4365cd89e42ad9c531a939b default@
@ -223,13 +228,14 @@ fn test_workspaces_updated_by_other() {
#[test]
fn test_workspaces_update_stale_noop() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
let main_path = test_env.env_root().join("main");
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "update-stale"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&main_path, &["workspace", "update-stale"]);
insta::assert_snapshot!(stdout, @r###"
Nothing to do (the working copy is not stale).
"###);
insta::assert_snapshot!(stderr, @"");
let stderr = test_env.jj_cmd_failure(
&main_path,
@ -251,25 +257,26 @@ fn test_workspaces_update_stale_noop() {
#[test]
fn test_workspaces_update_stale_snapshot() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
let main_path = test_env.env_root().join("main");
let secondary_path = test_env.env_root().join("secondary");
std::fs::write(main_path.join("file"), "changed in main\n").unwrap();
test_env.jj_cmd_success(&main_path, &["new"]);
test_env.jj_cmd_success(&main_path, &["workspace", "add", "../secondary"]);
test_env.jj_cmd_ok(&main_path, &["new"]);
test_env.jj_cmd_ok(&main_path, &["workspace", "add", "../secondary"]);
// Record new operation in one workspace.
test_env.jj_cmd_success(&main_path, &["new"]);
test_env.jj_cmd_ok(&main_path, &["new"]);
// Snapshot the other working copy, which unfortunately results in concurrent
// operations, but should be resolved cleanly.
std::fs::write(secondary_path.join("file"), "changed in second\n").unwrap();
let stdout = test_env.jj_cmd_success(&secondary_path, &["workspace", "update-stale"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["workspace", "update-stale"]);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
Nothing to do (the working copy is not stale).
"###);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &secondary_path), @r###"
@ 4976dfa88529814c4dd8c06253fbd82d076b79f8 secondary@
@ -285,15 +292,16 @@ fn test_workspaces_update_stale_snapshot() {
#[test]
fn test_workspaces_forget() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
let main_path = test_env.env_root().join("main");
std::fs::write(main_path.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&main_path, &["new"]);
test_env.jj_cmd_ok(&main_path, &["new"]);
test_env.jj_cmd_success(&main_path, &["workspace", "add", "../secondary"]);
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "forget"]);
test_env.jj_cmd_ok(&main_path, &["workspace", "add", "../secondary"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&main_path, &["workspace", "forget"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
// When listing workspaces, only the secondary workspace shows up
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
@ -302,10 +310,11 @@ fn test_workspaces_forget() {
"###);
// `jj status` tells us that there's no working copy here
let stdout = test_env.jj_cmd_success(&main_path, &["st"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&main_path, &["st"]);
insta::assert_snapshot!(stdout, @r###"
No working copy
"###);
insta::assert_snapshot!(stderr, @"");
// The old working copy doesn't get an "@" in the log output
// TODO: We should abandon the empty working copy commit
@ -334,8 +343,9 @@ fn test_workspaces_forget() {
"###);
// Forget the secondary workspace
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "forget", "secondary"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&main_path, &["workspace", "forget", "secondary"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
// No workspaces left
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
insta::assert_snapshot!(stdout, @"");
@ -345,7 +355,7 @@ fn test_workspaces_forget() {
#[test]
fn test_list_workspaces_template() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
test_env.add_config(
r#"
templates.commit_summary = """commit_id.short() ++ " " ++ description.first_line() ++
@ -356,8 +366,8 @@ fn test_list_workspaces_template() {
let secondary_path = test_env.env_root().join("secondary");
std::fs::write(main_path.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&main_path, &["commit", "-m", "initial"]);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(&main_path, &["commit", "-m", "initial"]);
test_env.jj_cmd_ok(
&main_path,
&["workspace", "add", "--name", "second", "../secondary"],
);
@ -380,7 +390,7 @@ fn test_list_workspaces_template() {
#[test]
fn test_workspaces_root() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "--git", "main"]);
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
let main_path = test_env.env_root().join("main");
let secondary_path = test_env.env_root().join("secondary");
@ -395,7 +405,7 @@ fn test_workspaces_root() {
$TEST_ENV/main
"###);
test_env.jj_cmd_success(
test_env.jj_cmd_ok(
&main_path,
&["workspace", "add", "--name", "secondary", "../secondary"],
);