2022-03-09 23:57:12 +00:00
|
|
|
// Copyright 2022 Google LLC
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-05-27 15:54:47 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-06-06 22:50:45 +00:00
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
use crate::common::{get_stderr_string, get_stdout_string, TestEnvironment};
|
2022-03-30 17:47:11 +00:00
|
|
|
|
|
|
|
pub mod common;
|
2022-03-09 23:57:12 +00:00
|
|
|
|
2022-05-27 15:54:47 +00:00
|
|
|
fn set_up() -> (TestEnvironment, PathBuf) {
|
2022-03-09 23:57:12 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
|
|
|
git2::Repository::init(&git_repo_path).unwrap();
|
|
|
|
|
2022-03-26 21:06:48 +00:00
|
|
|
test_env.jj_cmd_success(
|
|
|
|
test_env.env_root(),
|
|
|
|
&["git", "clone", "git-repo", "jj-repo"],
|
|
|
|
);
|
2022-03-09 23:57:12 +00:00
|
|
|
let workspace_root = test_env.env_root().join("jj-repo");
|
2022-05-27 15:54:47 +00:00
|
|
|
(test_env, workspace_root)
|
|
|
|
}
|
2022-03-09 23:57:12 +00:00
|
|
|
|
2022-05-27 15:54:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_git_push_nothing() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
2022-03-09 23:57:12 +00:00
|
|
|
// No branches to push yet
|
2022-03-26 21:06:48 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Nothing changed.
|
|
|
|
"###);
|
2022-05-27 15:54:47 +00:00
|
|
|
}
|
2022-03-09 23:57:12 +00:00
|
|
|
|
2022-05-27 15:54:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_git_push_open() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
2022-03-05 17:28:18 +00:00
|
|
|
// When pushing everything, won't push an open commit even if there's a branch
|
|
|
|
// on it
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "my-branch"]);
|
2022-03-26 21:06:48 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-03-05 17:28:18 +00:00
|
|
|
Skipping branch 'my-branch' since it points to an open commit.
|
|
|
|
Nothing changed.
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// When pushing a specific branch, won't push it if it points to an open commit
|
2022-04-07 06:25:01 +00:00
|
|
|
let stderr =
|
2022-04-02 16:45:02 +00:00
|
|
|
test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--branch", "my-branch"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Won't push open commit
|
|
|
|
"###);
|
2022-04-29 03:58:41 +00:00
|
|
|
// When pushing with `--change`, won't push if it points to an open commit
|
2022-06-06 22:50:45 +00:00
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(&workspace_root, &["git", "push", "--change", "my-branch"])
|
|
|
|
.assert();
|
|
|
|
let branch_pattern = Regex::new("push-[0-9a-f]+").unwrap();
|
|
|
|
insta::assert_snapshot!(branch_pattern.replace(&get_stdout_string(&assert), "<branch>"), @r###"
|
|
|
|
Creating branch <branch> for revision my-branch
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
|
2022-04-29 03:58:41 +00:00
|
|
|
Error: Won't push open commit
|
|
|
|
"###);
|
2022-05-27 15:54:47 +00:00
|
|
|
}
|
2022-03-05 17:28:18 +00:00
|
|
|
|
2022-05-27 15:54:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_git_push_conflict() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
2022-03-09 23:57:12 +00:00
|
|
|
std::fs::write(workspace_root.join("file"), "first").unwrap();
|
2022-03-26 21:06:48 +00:00
|
|
|
test_env.jj_cmd_success(&workspace_root, &["close", "-m", "first"]);
|
2022-03-09 23:57:12 +00:00
|
|
|
std::fs::write(workspace_root.join("file"), "second").unwrap();
|
2022-03-26 21:06:48 +00:00
|
|
|
test_env.jj_cmd_success(&workspace_root, &["close", "-m", "second"]);
|
2022-03-09 23:57:12 +00:00
|
|
|
std::fs::write(workspace_root.join("file"), "third").unwrap();
|
2022-04-14 06:53:35 +00:00
|
|
|
test_env.jj_cmd_success(&workspace_root, &["rebase", "-r", "@", "-d", "@--"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&workspace_root, &["branch", "set", "my-branch"]);
|
2022-03-26 21:06:48 +00:00
|
|
|
test_env.jj_cmd_success(&workspace_root, &["close", "-m", "third"]);
|
2022-04-07 06:25:01 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2022-05-27 15:54:47 +00:00
|
|
|
Error: Won't push commit 50ccff1aeab0 since it has conflicts
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_git_push_no_description() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "my-branch"]);
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["close", "-m", ""]);
|
|
|
|
let stderr =
|
|
|
|
test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--branch", "my-branch"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Won't push commit 4e5f01c842af since it has no description
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_git_push_missing_author() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
|
|
|
let run_without_var = |var: &str, args: &[&str]| {
|
|
|
|
test_env
|
|
|
|
.jj_cmd(&workspace_root, args)
|
|
|
|
.env_remove(var)
|
|
|
|
.assert()
|
|
|
|
.success();
|
|
|
|
};
|
|
|
|
run_without_var("JJ_USER", &["checkout", "root"]);
|
|
|
|
run_without_var("JJ_USER", &["branch", "create", "missing-name"]);
|
|
|
|
run_without_var("JJ_USER", &["close", "-m", "initial"]);
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&workspace_root,
|
|
|
|
&["git", "push", "--branch", "missing-name"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Won't push commit 567e1ab3da0e since it has no author and/or committer set
|
|
|
|
"###);
|
|
|
|
run_without_var("JJ_EMAIL", &["checkout", "root"]);
|
|
|
|
run_without_var("JJ_EMAIL", &["branch", "create", "missing-email"]);
|
|
|
|
run_without_var("JJ_EMAIL", &["close", "-m", "initial"]);
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&workspace_root,
|
|
|
|
&["git", "push", "--branch", "missing-email"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Won't push commit ce7b456bb11a since it has no author and/or committer set
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_git_push_missing_committer() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
|
|
|
let run_without_var = |var: &str, args: &[&str]| {
|
|
|
|
test_env
|
|
|
|
.jj_cmd(&workspace_root, args)
|
|
|
|
.env_remove(var)
|
|
|
|
.assert()
|
|
|
|
.success();
|
|
|
|
};
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "missing-name"]);
|
|
|
|
run_without_var("JJ_USER", &["close", "-m", "no committer name"]);
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&workspace_root,
|
|
|
|
&["git", "push", "--branch", "missing-name"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Won't push commit df8d9f6cf625 since it has no author and/or committer set
|
|
|
|
"###);
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["checkout", "root"]);
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "missing-email"]);
|
|
|
|
run_without_var("JJ_EMAIL", &["close", "-m", "no committer email"]);
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&workspace_root,
|
|
|
|
&["git", "push", "--branch", "missing-email"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Won't push commit 61b8a14387d7 since it has no author and/or committer set
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Test message when there are multiple reasons (missing committer and
|
|
|
|
// description)
|
|
|
|
run_without_var("JJ_EMAIL", &["describe", "-m", "", "missing-email"]);
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&workspace_root,
|
|
|
|
&["git", "push", "--branch", "missing-email"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Won't push commit 9e1aae45b6a3 since it has no description and it has no author and/or committer set
|
2022-04-28 23:32:18 +00:00
|
|
|
"###);
|
2022-03-09 23:57:12 +00:00
|
|
|
}
|