mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-06 03:22:59 +00:00
tests: demo jj branch forget
behavior in colocated repos
This commit is contained in:
parent
8df945b71d
commit
d5e8896d1b
2 changed files with 87 additions and 0 deletions
|
@ -70,6 +70,7 @@ fn test_branch_empty_name() {
|
|||
For more information, try '--help'.
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_branch_forget_glob() {
|
||||
let test_env = TestEnvironment::default();
|
||||
|
@ -113,6 +114,63 @@ fn test_branch_forget_glob() {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_branch_forget_export() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
test_env.jj_cmd_success(&repo_path, &["new"]);
|
||||
test_env.jj_cmd_success(&repo_path, &["branch", "set", "foo"]);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
foo: 65b6b74e0897 (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"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "forget", "foo"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
// Forgetting a branch does not delete its local-git tracking branch. This is
|
||||
// the opposite of what happens to remote-tracking branches.
|
||||
// TODO: Consider allowing forgetting local-git tracking branches as an option
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
foo (deleted)
|
||||
@git: 65b6b74e0897 (no description set)
|
||||
"###);
|
||||
|
||||
// Aside: the way we currently resolve git refs means that `foo`
|
||||
// resolves to `foo@git` when actual `foo` doesn't exist.
|
||||
// Short-term TODO: This behavior will be changed in a subsequent commit.
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r=foo", "--no-graph"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
rlvkpnrzqnoo test.user@example.com 2001-02-03 04:05:08.000 +07:00 65b6b74e0897
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
|
||||
// The presence of the @git branch means that a `jj git import` is a no-op...
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "import"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Nothing changed.
|
||||
"###);
|
||||
// ... and a `jj git export` will delete the branch from git and will delete the
|
||||
// git-tracking branch. In a colocated repo, 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"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
|
||||
// Note that if `jj branch forget` *did* delete foo@git, a subsequent `jj
|
||||
// git export` would be a no-op and a `jj git import` would resurrect
|
||||
// the branch. In a normal repo, that might be OK. In a colocated repo,
|
||||
// this would automatically happen before the next command, making `jj
|
||||
// branch forget` useless.
|
||||
}
|
||||
|
||||
// TODO: Test `jj branch list` with a remote named `git`
|
||||
|
||||
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
|
||||
|
|
|
@ -216,6 +216,35 @@ fn test_git_colocated_branches() {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
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"]);
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &workspace_root), @r###"
|
||||
@ 65b6b74e08973b88d38404430f119c8c79465250 foo
|
||||
◉ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 master HEAD@git
|
||||
◉ 0000000000000000000000000000000000000000
|
||||
"###);
|
||||
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
foo: 65b6b74e0897 (no description set)
|
||||
master: 230dd059e1b0 (no description set)
|
||||
"###);
|
||||
|
||||
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "forget", "foo"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
// 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"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
master: 230dd059e1b0 (no description set)
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_colocated_conflicting_git_refs() {
|
||||
let test_env = TestEnvironment::default();
|
||||
|
|
Loading…
Reference in a new issue