From a7aef50dd2319bb6092affd024e58e69cc2fcbb8 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Tue, 16 Apr 2024 17:21:05 -0700 Subject: [PATCH] test_git_push: Adds a test for branch creation This tests `git push` attempting to create a branch when the branch already unexpectedly exists on the remote. This should (and does) fail. --- cli/tests/test_git_push.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/cli/tests/test_git_push.rs b/cli/tests/test_git_push.rs index da3a331174..d09c36c774 100644 --- a/cli/tests/test_git_push.rs +++ b/cli/tests/test_git_push.rs @@ -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();