Skip to content

Commit

Permalink
test_git_push: add a test for creating unexpectedly existing branch
Browse files Browse the repository at this point in the history
This tests `git push` attempting to create a branch when the branch
already unexpectedly exists on the remote. This should (and does)
fail.

Also changes another test to use `jj_cmd_failure`.
  • Loading branch information
ilyagr committed May 29, 2024
1 parent 221cd44 commit 1e1507d
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,8 @@ fn test_git_push_not_fast_forward() {
test_env.jj_cmd_ok(&workspace_root, &["branch", "set", "branch1"]);

// Pushing should fail
let assert = test_env
.jj_cmd(&workspace_root, &["git", "push"])
.assert()
.code(1);
insta::assert_snapshot!(get_stdout_string(&assert), @"");
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stderr, @r###"
Branch changes to push to origin:
Move branch branch1 from 45a3aa29e907 to c35839cb8e8c
Error: The push conflicts with changes made on the remote (it is not fast-forwardable).
Expand Down Expand Up @@ -325,6 +321,32 @@ fn test_git_push_deletion_unexpectedly_moved() {
"###);
}

#[test]
fn test_git_push_creation_unexpectedly_already_exists() {
let (test_env, workspace_root) = set_up();

// Forget branch1 locally
test_env.jj_cmd_ok(&workspace_root, &["branch", "forget", "branch1"]);

// Create a new branh1
test_env.jj_cmd_ok(&workspace_root, &["new", "root()", "-m=new branch1"]);
std::fs::write(workspace_root.join("local"), "local").unwrap();
test_env.jj_cmd_ok(&workspace_root, &["branch", "create", "branch1"]);
insta::assert_snapshot!(get_branch_output(&test_env, &workspace_root), @r###"
branch1: yostqsxw 4c595cf9 new branch1
branch2: rlzusymt 8476341e (empty) description 2
@origin: rlzusymt 8476341e (empty) description 2
"###);

let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push"]);
insta::assert_snapshot!(stderr, @r###"
Branch changes to push to origin:
Add branch branch1 to 4c595cf9ac0a
Error: The push conflicts with changes made on the remote (it is not fast-forwardable).
Hint: Try fetching from the remote, then make the branch point to where you want it to be, and push again.
"###);
}

#[test]
fn test_git_push_locally_created_and_rewritten() {
let (test_env, workspace_root) = set_up();
Expand Down

0 comments on commit 1e1507d

Please sign in to comment.