use temp_env::with_var;
use super::*;
fn setup_branch(ctx: TestContext) -> TestContext {
run(&ctx.dir, &["git", "checkout", "-b", "other-branch"]);
commit(&ctx.dir, "new-file", "hello");
run(&ctx.dir, &["git", "checkout", "main"]);
ctx
}
fn setup_branches(ctx: TestContext) -> TestContext {
run(&ctx.dir, &["git", "checkout", "-b", "feature-a"]);
commit(&ctx.dir, "feature-a commit", "");
run(&ctx.dir, &["git", "checkout", "main"]);
run(&ctx.dir, &["git", "checkout", "-b", "feature-b"]);
commit(&ctx.dir, "feature-b commit", "");
run(&ctx.dir, &["git", "checkout", "main"]);
run(&ctx.dir, &["git", "checkout", "-b", "bugfix-123"]);
commit(&ctx.dir, "bugfix commit", "");
run(&ctx.dir, &["git", "checkout", "main"]);
run(&ctx.dir, &["git", "tag", "v1.0.0", "feature-a"]);
run(&ctx.dir, &["git", "tag", "v2.0.0", "feature-b"]);
ctx
}
fn setup_branch_tag_same_name(ctx: TestContext) -> TestContext {
run(&ctx.dir, &["git", "checkout", "-b", "v1.0.0"]);
commit(&ctx.dir, "branch commit", "");
run(&ctx.dir, &["git", "checkout", "main"]);
run(&ctx.dir, &["git", "checkout", "-b", "other"]);
commit(&ctx.dir, "other commit", "");
run(&ctx.dir, &["git", "tag", "v1.0.0"]);
run(&ctx.dir, &["git", "checkout", "main"]);
ctx
}
#[test]
fn merge_menu() {
snapshot!(setup_branch(setup_clone!()), "m");
}
#[test]
fn merge_picker() {
snapshot!(setup_branches(setup_clone!()), "mm");
}
#[test]
fn merge_picker_custom_input() {
snapshot!(setup_branches(setup_clone!()), "mmHEAD~2");
}
#[test]
fn merge_picker_cancel() {
snapshot!(setup_branches(setup_clone!()), "mm<esc>");
}
#[test]
fn merge_select_from_list() {
with_var("GIT_MERGE_AUTOEDIT", Some("no"), || {
snapshot!(setup_branches(setup_clone!()), "mmfeature-a<enter>");
});
}
#[test]
fn merge_picker_duplicate_names_select_branch() {
with_var("GIT_MERGE_AUTOEDIT", Some("no"), || {
snapshot!(
setup_branch_tag_same_name(setup_clone!()),
"mmv1.0.0<enter>"
);
});
}
#[test]
fn merge_picker_duplicate_names_select_tag() {
with_var("GIT_MERGE_AUTOEDIT", Some("no"), || {
snapshot!(setup_branch_tag_same_name(setup_clone!()), "mmtag:<enter>");
});
}
#[test]
fn merge_use_custom_input() {
with_var("GIT_MERGE_AUTOEDIT", Some("no"), || {
snapshot!(
setup_branches(setup_clone!()),
"mmb66a0bf82020d6a386e94d0fceedec1f817d20c7<enter>"
);
});
}
#[test]
fn merge_ff_only() {
snapshot!(setup_branch(setup_clone!()), "m-fmother-branch<enter>");
}
#[test]
fn merge_no_ff() {
with_var("GIT_MERGE_AUTOEDIT", Some("no"), || {
snapshot!(setup_branch(setup_clone!()), "m-nmother-branch<enter>");
});
}