mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-05 15:32:49 +00:00
tests: port test_git_import_export.rs to TestWorkDir API
This commit is contained in:
parent
569a405cea
commit
ca616fade2
@ -11,7 +11,6 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use itertools::Itertools as _;
|
use itertools::Itertools as _;
|
||||||
use jj_lib::backend::CommitId;
|
use jj_lib::backend::CommitId;
|
||||||
@ -19,27 +18,28 @@ use testutils::git;
|
|||||||
|
|
||||||
use crate::common::CommandOutput;
|
use crate::common::CommandOutput;
|
||||||
use crate::common::TestEnvironment;
|
use crate::common::TestEnvironment;
|
||||||
|
use crate::common::TestWorkDir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolution_of_git_tracking_bookmarks() {
|
fn test_resolution_of_git_tracking_bookmarks() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
||||||
let repo_path = test_env.env_root().join("repo");
|
let work_dir = test_env.work_dir("repo");
|
||||||
test_env
|
work_dir
|
||||||
.run_jj_in(&repo_path, ["bookmark", "create", "-r@", "main"])
|
.run_jj(["bookmark", "create", "-r@", "main"])
|
||||||
.success();
|
.success();
|
||||||
test_env
|
work_dir
|
||||||
.run_jj_in(&repo_path, ["describe", "-r", "main", "-m", "old_message"])
|
.run_jj(["describe", "-r", "main", "-m", "old_message"])
|
||||||
.success();
|
.success();
|
||||||
|
|
||||||
// Create local-git tracking bookmark
|
// Create local-git tracking bookmark
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "export"]);
|
let output = work_dir.run_jj(["git", "export"]);
|
||||||
insta::assert_snapshot!(output, @"");
|
insta::assert_snapshot!(output, @"");
|
||||||
// Move the local bookmark somewhere else
|
// Move the local bookmark somewhere else
|
||||||
test_env
|
work_dir
|
||||||
.run_jj_in(&repo_path, ["describe", "-r", "main", "-m", "new_message"])
|
.run_jj(["describe", "-r", "main", "-m", "new_message"])
|
||||||
.success();
|
.success();
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r"
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
|
||||||
main: qpvuntsm b61d21b6 (empty) new_message
|
main: qpvuntsm b61d21b6 (empty) new_message
|
||||||
@git (ahead by 1 commits, behind by 1 commits): qpvuntsm hidden 03757d22 (empty) old_message
|
@git (ahead by 1 commits, behind by 1 commits): qpvuntsm hidden 03757d22 (empty) old_message
|
||||||
[EOF]
|
[EOF]
|
||||||
@ -48,10 +48,7 @@ fn test_resolution_of_git_tracking_bookmarks() {
|
|||||||
// Test that we can address both revisions
|
// Test that we can address both revisions
|
||||||
let query = |expr| {
|
let query = |expr| {
|
||||||
let template = r#"commit_id ++ " " ++ description"#;
|
let template = r#"commit_id ++ " " ++ description"#;
|
||||||
test_env.run_jj_in(
|
work_dir.run_jj(["log", "-r", expr, "-T", template, "--no-graph"])
|
||||||
&repo_path,
|
|
||||||
["log", "-r", expr, "-T", template, "--no-graph"],
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
insta::assert_snapshot!(query("main"), @r"
|
insta::assert_snapshot!(query("main"), @r"
|
||||||
b61d21b660c17a7191f3f73873bfe7d3f7938628 new_message
|
b61d21b660c17a7191f3f73873bfe7d3f7938628 new_message
|
||||||
@ -69,15 +66,15 @@ fn test_resolution_of_git_tracking_bookmarks() {
|
|||||||
fn test_git_export_conflicting_git_refs() {
|
fn test_git_export_conflicting_git_refs() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
||||||
let repo_path = test_env.env_root().join("repo");
|
let work_dir = test_env.work_dir("repo");
|
||||||
|
|
||||||
test_env
|
work_dir
|
||||||
.run_jj_in(&repo_path, ["bookmark", "create", "-r@", "main"])
|
.run_jj(["bookmark", "create", "-r@", "main"])
|
||||||
.success();
|
.success();
|
||||||
test_env
|
work_dir
|
||||||
.run_jj_in(&repo_path, ["bookmark", "create", "-r@", "main/sub"])
|
.run_jj(["bookmark", "create", "-r@", "main/sub"])
|
||||||
.success();
|
.success();
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "export"]);
|
let output = work_dir.run_jj(["git", "export"]);
|
||||||
insta::with_settings!({filters => vec![("Failed to set: .*", "Failed to set: ...")]}, {
|
insta::with_settings!({filters => vec![("Failed to set: .*", "Failed to set: ...")]}, {
|
||||||
insta::assert_snapshot!(output, @r#"
|
insta::assert_snapshot!(output, @r#"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
@ -95,19 +92,19 @@ fn test_git_export_conflicting_git_refs() {
|
|||||||
fn test_git_export_undo() {
|
fn test_git_export_undo() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
||||||
let repo_path = test_env.env_root().join("repo");
|
let work_dir = test_env.work_dir("repo");
|
||||||
let git_repo = git::open(repo_path.join(".jj/repo/store/git"));
|
let git_repo = git::open(work_dir.root().join(".jj/repo/store/git"));
|
||||||
|
|
||||||
test_env
|
work_dir
|
||||||
.run_jj_in(&repo_path, ["bookmark", "create", "-r@", "a"])
|
.run_jj(["bookmark", "create", "-r@", "a"])
|
||||||
.success();
|
.success();
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r"
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
|
||||||
a: qpvuntsm 230dd059 (empty) (no description set)
|
a: qpvuntsm 230dd059 (empty) (no description set)
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "export"]);
|
let output = work_dir.run_jj(["git", "export"]);
|
||||||
insta::assert_snapshot!(output, @"");
|
insta::assert_snapshot!(output, @"");
|
||||||
insta::assert_snapshot!(test_env.run_jj_in(&repo_path, ["log", "-ra@git"]), @r"
|
insta::assert_snapshot!(work_dir.run_jj(["log", "-ra@git"]), @r"
|
||||||
@ qpvuntsm test.user@example.com 2001-02-03 08:05:07 a 230dd059
|
@ qpvuntsm test.user@example.com 2001-02-03 08:05:07 a 230dd059
|
||||||
│ (empty) (no description set)
|
│ (empty) (no description set)
|
||||||
~
|
~
|
||||||
@ -116,7 +113,7 @@ fn test_git_export_undo() {
|
|||||||
|
|
||||||
// Exported refs won't be removed by undoing the export, but the git-tracking
|
// Exported refs won't be removed by undoing the export, but the git-tracking
|
||||||
// bookmark is. This is the same as remote-tracking bookmarks.
|
// bookmark is. This is the same as remote-tracking bookmarks.
|
||||||
let output = test_env.run_jj_in(&repo_path, ["op", "undo"]);
|
let output = work_dir.run_jj(["op", "undo"]);
|
||||||
insta::assert_snapshot!(output, @r"
|
insta::assert_snapshot!(output, @r"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
Undid operation: edb40232c741 (2001-02-03 08:05:10) export git refs
|
Undid operation: edb40232c741 (2001-02-03 08:05:10) export git refs
|
||||||
@ -132,7 +129,7 @@ fn test_git_export_undo() {
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
"#);
|
"#);
|
||||||
insta::assert_snapshot!(test_env.run_jj_in(&repo_path, ["log", "-ra@git"]), @r"
|
insta::assert_snapshot!(work_dir.run_jj(["log", "-ra@git"]), @r"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
Error: Revision `a@git` doesn't exist
|
Error: Revision `a@git` doesn't exist
|
||||||
Hint: Did you mean `a`?
|
Hint: Did you mean `a`?
|
||||||
@ -141,9 +138,9 @@ fn test_git_export_undo() {
|
|||||||
");
|
");
|
||||||
|
|
||||||
// This would re-export bookmark "a" and create git-tracking bookmark.
|
// This would re-export bookmark "a" and create git-tracking bookmark.
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "export"]);
|
let output = work_dir.run_jj(["git", "export"]);
|
||||||
insta::assert_snapshot!(output, @"");
|
insta::assert_snapshot!(output, @"");
|
||||||
insta::assert_snapshot!(test_env.run_jj_in(&repo_path, ["log", "-ra@git"]), @r"
|
insta::assert_snapshot!(work_dir.run_jj(["log", "-ra@git"]), @r"
|
||||||
@ qpvuntsm test.user@example.com 2001-02-03 08:05:07 a 230dd059
|
@ qpvuntsm test.user@example.com 2001-02-03 08:05:07 a 230dd059
|
||||||
│ (empty) (no description set)
|
│ (empty) (no description set)
|
||||||
~
|
~
|
||||||
@ -155,12 +152,12 @@ fn test_git_export_undo() {
|
|||||||
fn test_git_import_undo() {
|
fn test_git_import_undo() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
||||||
let repo_path = test_env.env_root().join("repo");
|
let work_dir = test_env.work_dir("repo");
|
||||||
let git_repo = git::open(repo_path.join(".jj/repo/store/git"));
|
let git_repo = git::open(work_dir.root().join(".jj/repo/store/git"));
|
||||||
|
|
||||||
// Create bookmark "a" in git repo
|
// Create bookmark "a" in git repo
|
||||||
let commit_id = test_env
|
let commit_id = work_dir
|
||||||
.run_jj_in(&repo_path, &["log", "-Tcommit_id", "--no-graph", "-r@"])
|
.run_jj(&["log", "-Tcommit_id", "--no-graph", "-r@"])
|
||||||
.success()
|
.success()
|
||||||
.stdout
|
.stdout
|
||||||
.into_raw();
|
.into_raw();
|
||||||
@ -175,37 +172,37 @@ fn test_git_import_undo() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Initial state we will return to after `undo`. There are no bookmarks.
|
// Initial state we will return to after `undo`. There are no bookmarks.
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
|
||||||
let base_operation_id = test_env.work_dir(&repo_path).current_operation_id();
|
let base_operation_id = work_dir.current_operation_id();
|
||||||
|
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "import"]);
|
let output = work_dir.run_jj(["git", "import"]);
|
||||||
insta::assert_snapshot!(output, @r"
|
insta::assert_snapshot!(output, @r"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
bookmark: a@git [new] tracked
|
bookmark: a@git [new] tracked
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r"
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
|
||||||
a: qpvuntsm 230dd059 (empty) (no description set)
|
a: qpvuntsm 230dd059 (empty) (no description set)
|
||||||
@git: qpvuntsm 230dd059 (empty) (no description set)
|
@git: qpvuntsm 230dd059 (empty) (no description set)
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
|
|
||||||
// "git import" can be undone by default.
|
// "git import" can be undone by default.
|
||||||
let output = test_env.run_jj_in(&repo_path, ["op", "restore", &base_operation_id]);
|
let output = work_dir.run_jj(["op", "restore", &base_operation_id]);
|
||||||
insta::assert_snapshot!(output, @r"
|
insta::assert_snapshot!(output, @r"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
Restored to operation: eac759b9ab75 (2001-02-03 08:05:07) add workspace 'default'
|
Restored to operation: eac759b9ab75 (2001-02-03 08:05:07) add workspace 'default'
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
|
||||||
// Try "git import" again, which should re-import the bookmark "a".
|
// Try "git import" again, which should re-import the bookmark "a".
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "import"]);
|
let output = work_dir.run_jj(["git", "import"]);
|
||||||
insta::assert_snapshot!(output, @r"
|
insta::assert_snapshot!(output, @r"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
bookmark: a@git [new] tracked
|
bookmark: a@git [new] tracked
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r"
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
|
||||||
a: qpvuntsm 230dd059 (empty) (no description set)
|
a: qpvuntsm 230dd059 (empty) (no description set)
|
||||||
@git: qpvuntsm 230dd059 (empty) (no description set)
|
@git: qpvuntsm 230dd059 (empty) (no description set)
|
||||||
[EOF]
|
[EOF]
|
||||||
@ -216,12 +213,12 @@ fn test_git_import_undo() {
|
|||||||
fn test_git_import_move_export_with_default_undo() {
|
fn test_git_import_move_export_with_default_undo() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
|
||||||
let repo_path = test_env.env_root().join("repo");
|
let work_dir = test_env.work_dir("repo");
|
||||||
let git_repo = git::open(repo_path.join(".jj/repo/store/git"));
|
let git_repo = git::open(work_dir.root().join(".jj/repo/store/git"));
|
||||||
|
|
||||||
// Create bookmark "a" in git repo
|
// Create bookmark "a" in git repo
|
||||||
let commit_id = test_env
|
let commit_id = work_dir
|
||||||
.run_jj_in(&repo_path, &["log", "-Tcommit_id", "--no-graph", "-r@"])
|
.run_jj(&["log", "-Tcommit_id", "--no-graph", "-r@"])
|
||||||
.success()
|
.success()
|
||||||
.stdout
|
.stdout
|
||||||
.into_raw();
|
.into_raw();
|
||||||
@ -237,34 +234,34 @@ fn test_git_import_move_export_with_default_undo() {
|
|||||||
|
|
||||||
// Initial state we will try to return to after `op restore`. There are no
|
// Initial state we will try to return to after `op restore`. There are no
|
||||||
// bookmarks.
|
// bookmarks.
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
|
||||||
let base_operation_id = test_env.work_dir(&repo_path).current_operation_id();
|
let base_operation_id = work_dir.current_operation_id();
|
||||||
|
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "import"]);
|
let output = work_dir.run_jj(["git", "import"]);
|
||||||
insta::assert_snapshot!(output, @r"
|
insta::assert_snapshot!(output, @r"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
bookmark: a@git [new] tracked
|
bookmark: a@git [new] tracked
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r"
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
|
||||||
a: qpvuntsm 230dd059 (empty) (no description set)
|
a: qpvuntsm 230dd059 (empty) (no description set)
|
||||||
@git: qpvuntsm 230dd059 (empty) (no description set)
|
@git: qpvuntsm 230dd059 (empty) (no description set)
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
|
|
||||||
// Move bookmark "a" and export to git repo
|
// Move bookmark "a" and export to git repo
|
||||||
test_env.run_jj_in(&repo_path, ["new"]).success();
|
work_dir.run_jj(["new"]).success();
|
||||||
test_env
|
work_dir
|
||||||
.run_jj_in(&repo_path, ["bookmark", "set", "a", "--to=@"])
|
.run_jj(["bookmark", "set", "a", "--to=@"])
|
||||||
.success();
|
.success();
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r"
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
|
||||||
a: yqosqzyt 096dc80d (empty) (no description set)
|
a: yqosqzyt 096dc80d (empty) (no description set)
|
||||||
@git (behind by 1 commits): qpvuntsm 230dd059 (empty) (no description set)
|
@git (behind by 1 commits): qpvuntsm 230dd059 (empty) (no description set)
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "export"]);
|
let output = work_dir.run_jj(["git", "export"]);
|
||||||
insta::assert_snapshot!(output, @"");
|
insta::assert_snapshot!(output, @"");
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r"
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
|
||||||
a: yqosqzyt 096dc80d (empty) (no description set)
|
a: yqosqzyt 096dc80d (empty) (no description set)
|
||||||
@git: yqosqzyt 096dc80d (empty) (no description set)
|
@git: yqosqzyt 096dc80d (empty) (no description set)
|
||||||
[EOF]
|
[EOF]
|
||||||
@ -273,7 +270,7 @@ fn test_git_import_move_export_with_default_undo() {
|
|||||||
// "git import" can be undone with the default `restore` behavior, as shown in
|
// "git import" can be undone with the default `restore` behavior, as shown in
|
||||||
// the previous test. However, "git export" can't: the bookmarks in the git
|
// the previous test. However, "git export" can't: the bookmarks in the git
|
||||||
// repo stay where they were.
|
// repo stay where they were.
|
||||||
let output = test_env.run_jj_in(&repo_path, ["op", "restore", &base_operation_id]);
|
let output = work_dir.run_jj(["op", "restore", &base_operation_id]);
|
||||||
insta::assert_snapshot!(output, @r"
|
insta::assert_snapshot!(output, @r"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
Restored to operation: eac759b9ab75 (2001-02-03 08:05:07) add workspace 'default'
|
Restored to operation: eac759b9ab75 (2001-02-03 08:05:07) add workspace 'default'
|
||||||
@ -281,7 +278,7 @@ fn test_git_import_move_export_with_default_undo() {
|
|||||||
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
|
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @"");
|
||||||
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r#"
|
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r#"
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
@ -295,13 +292,13 @@ fn test_git_import_move_export_with_default_undo() {
|
|||||||
|
|
||||||
// The last bookmark "a" state is imported from git. No idea what's the most
|
// The last bookmark "a" state is imported from git. No idea what's the most
|
||||||
// intuitive result here.
|
// intuitive result here.
|
||||||
let output = test_env.run_jj_in(&repo_path, ["git", "import"]);
|
let output = work_dir.run_jj(["git", "import"]);
|
||||||
insta::assert_snapshot!(output, @r"
|
insta::assert_snapshot!(output, @r"
|
||||||
------- stderr -------
|
------- stderr -------
|
||||||
bookmark: a@git [new] tracked
|
bookmark: a@git [new] tracked
|
||||||
[EOF]
|
[EOF]
|
||||||
");
|
");
|
||||||
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r"
|
insta::assert_snapshot!(get_bookmark_output(&work_dir), @r"
|
||||||
a: yqosqzyt 096dc80d (empty) (no description set)
|
a: yqosqzyt 096dc80d (empty) (no description set)
|
||||||
@git: yqosqzyt 096dc80d (empty) (no description set)
|
@git: yqosqzyt 096dc80d (empty) (no description set)
|
||||||
[EOF]
|
[EOF]
|
||||||
@ -309,8 +306,8 @@ fn test_git_import_move_export_with_default_undo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn get_bookmark_output(test_env: &TestEnvironment, repo_path: &Path) -> CommandOutput {
|
fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput {
|
||||||
test_env.run_jj_in(repo_path, ["bookmark", "list", "--all-remotes"])
|
work_dir.run_jj(["bookmark", "list", "--all-remotes"])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_git_repo_refs(git_repo: &gix::Repository) -> Vec<(bstr::BString, CommitId)> {
|
fn get_git_repo_refs(git_repo: &gix::Repository) -> Vec<(bstr::BString, CommitId)> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user