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-19 03:05:08 +00:00
|
|
|
use crate::common::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");
|
2022-07-02 02:50:51 +00:00
|
|
|
let git_repo = git2::Repository::init_bare(&git_repo_path).unwrap();
|
|
|
|
let signature =
|
|
|
|
git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap();
|
|
|
|
let empty_tree_oid = git_repo.treebuilder(None).unwrap().write().unwrap();
|
|
|
|
let empty_tree = git_repo.find_tree(empty_tree_oid).unwrap();
|
|
|
|
git_repo
|
|
|
|
.commit(
|
|
|
|
Some("refs/heads/branch1"),
|
|
|
|
&signature,
|
|
|
|
&signature,
|
2022-09-26 17:37:49 +00:00
|
|
|
"description 1",
|
2022-07-02 02:50:51 +00:00
|
|
|
&empty_tree,
|
|
|
|
&[],
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
git_repo
|
|
|
|
.commit(
|
|
|
|
Some("refs/heads/branch2"),
|
|
|
|
&signature,
|
|
|
|
&signature,
|
2022-09-26 17:37:49 +00:00
|
|
|
"description 2",
|
2022-07-02 02:50:51 +00:00
|
|
|
&empty_tree,
|
|
|
|
&[],
|
|
|
|
)
|
|
|
|
.unwrap();
|
2022-03-09 23:57:12 +00:00
|
|
|
|
2022-03-26 21:06:48 +00:00
|
|
|
test_env.jj_cmd_success(
|
|
|
|
test_env.env_root(),
|
2022-07-02 02:50:51 +00:00
|
|
|
&[
|
|
|
|
"git",
|
|
|
|
"clone",
|
|
|
|
test_env.env_root().join("git-repo").to_str().unwrap(),
|
|
|
|
"jj-repo",
|
|
|
|
],
|
2022-03-26 21:06:48 +00:00
|
|
|
);
|
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-07-13 04:14:02 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--all"]);
|
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-07-02 02:50:51 +00:00
|
|
|
#[test]
|
2022-07-13 04:14:02 +00:00
|
|
|
fn test_git_push_current_branch() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
|
|
|
// Update some branches. `branch1` is not a current branch, but `branch2` and
|
|
|
|
// `my-branch` are.
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
&workspace_root,
|
|
|
|
&["describe", "branch1", "-m", "modified branch1 commit"],
|
|
|
|
);
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
&workspace_root,
|
|
|
|
&["branch", "set", "--allow-backwards", "branch2"],
|
|
|
|
);
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "my-branch"]);
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
|
|
|
|
// Check the setup
|
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
branch1: 5d0d85ed3da7 modified branch1 commit
|
2022-09-26 17:37:49 +00:00
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): a3ccc578ea7b description 1
|
2022-07-13 04:14:02 +00:00
|
|
|
branch2: 7840c9885676 foo
|
2022-09-26 17:37:49 +00:00
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): 7fd4b07286b3 description 2
|
2022-07-13 04:14:02 +00:00
|
|
|
my-branch: 7840c9885676 foo
|
|
|
|
"###);
|
|
|
|
// First dry-run. `branch1` should not get pushed.
|
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--dry-run"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Branch changes to push to origin:
|
2022-09-26 17:37:49 +00:00
|
|
|
Move branch branch2 from 7fd4b07286b3 to 7840c9885676
|
2022-07-13 04:14:02 +00:00
|
|
|
Add branch my-branch to 7840c9885676
|
|
|
|
Dry-run requested, not pushing.
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Branch changes to push to origin:
|
2022-09-26 17:37:49 +00:00
|
|
|
Move branch branch2 from 7fd4b07286b3 to 7840c9885676
|
2022-07-13 04:14:02 +00:00
|
|
|
Add branch my-branch to 7840c9885676
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
branch1: 5d0d85ed3da7 modified branch1 commit
|
2022-09-26 17:37:49 +00:00
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): a3ccc578ea7b description 1
|
2022-07-13 04:14:02 +00:00
|
|
|
branch2: 7840c9885676 foo
|
|
|
|
my-branch: 7840c9885676 foo
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_git_push_no_current_branch() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["new"]);
|
|
|
|
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: No current branch.
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_git_push_all() {
|
2022-07-02 02:50:51 +00:00
|
|
|
let (test_env, workspace_root) = set_up();
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["branch", "delete", "branch1"]);
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
&workspace_root,
|
|
|
|
&["branch", "set", "--allow-backwards", "branch2"],
|
|
|
|
);
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["branch", "create", "my-branch"]);
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
|
|
|
|
// Check the setup
|
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
branch1 (deleted)
|
2022-09-26 17:37:49 +00:00
|
|
|
@origin: a3ccc578ea7b description 1
|
2022-07-02 02:50:51 +00:00
|
|
|
branch2: 7840c9885676 foo
|
2022-09-26 17:37:49 +00:00
|
|
|
@origin (ahead by 1 commits, behind by 1 commits): 7fd4b07286b3 description 2
|
2022-07-02 02:50:51 +00:00
|
|
|
my-branch: 7840c9885676 foo
|
|
|
|
"###);
|
2022-06-29 02:10:45 +00:00
|
|
|
// First dry-run
|
2022-07-13 04:14:02 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--all", "--dry-run"]);
|
2022-06-29 02:10:45 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Branch changes to push to origin:
|
2022-09-26 17:37:49 +00:00
|
|
|
Delete branch branch1 from a3ccc578ea7b
|
|
|
|
Move branch branch2 from 7fd4b07286b3 to 7840c9885676
|
2022-06-29 02:10:45 +00:00
|
|
|
Add branch my-branch to 7840c9885676
|
|
|
|
Dry-run requested, not pushing.
|
|
|
|
"###);
|
2022-07-13 04:14:02 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--all"]);
|
2022-06-29 02:10:45 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Branch changes to push to origin:
|
2022-09-26 17:37:49 +00:00
|
|
|
Delete branch branch1 from a3ccc578ea7b
|
|
|
|
Move branch branch2 from 7fd4b07286b3 to 7840c9885676
|
2022-06-29 02:10:45 +00:00
|
|
|
Add branch my-branch to 7840c9885676
|
|
|
|
"###);
|
2022-07-02 02:50:51 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&workspace_root, &["branch", "list"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
branch2: 7840c9885676 foo
|
|
|
|
my-branch: 7840c9885676 foo
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2022-07-05 06:14:39 +00:00
|
|
|
#[test]
|
|
|
|
fn test_git_push_unsnapshotted_change() {
|
|
|
|
let (test_env, workspace_root) = set_up();
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["describe", "-m", "foo"]);
|
|
|
|
std::fs::write(workspace_root.join("file"), "contents").unwrap();
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change", "@"]);
|
|
|
|
std::fs::write(workspace_root.join("file"), "modified").unwrap();
|
|
|
|
test_env.jj_cmd_success(&workspace_root, &["git", "push", "--change", "@"]);
|
|
|
|
}
|
|
|
|
|
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-07-13 04:14:02 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push", "--all"]);
|
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
|
|
|
}
|