Skip to content

Commit

Permalink
test_git_push: Adds a test for branch creation
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.
  • Loading branch information
ilyagr committed Apr 17, 2024
1 parent a0e98d2 commit a7aef50
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,41 @@ 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"]);
let assert = test_env
.jj_cmd(&workspace_root, &["branch", "list", "--all"])
.assert()
.success();
insta::assert_snapshot!(get_stdout_string(&assert), @r###"
branch1: yostqsxw 4c595cf9 new branch1
branch2: rlzusymt 8476341e (empty) description 2
@origin: rlzusymt 8476341e (empty) description 2
"###);
insta::assert_snapshot!(get_stderr_string(&assert), @"");

let assert = test_env
.jj_cmd(&workspace_root, &["git", "push"])
.assert()
.failure();
insta::assert_snapshot!(get_stdout_string(&assert), @"");
insta::assert_snapshot!(get_stderr_string(&assert), @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 a7aef50

Please sign in to comment.