use super::super::apply;
use super::{git, init_repo, write};
use crate::template::GitRunner;
fn seed_descriptions(wt: &std::path::Path) {
let g = git();
write(wt, "descriptions/tools/bash.json", "{}\n");
write(wt, "descriptions/tools/slack_post.json", "{}\n");
g.run(wt, &["add", "-A"]).unwrap();
g.run(wt, &["commit", "-m", "seed descriptions"]).unwrap();
}
fn make_pruning_child(wt: &std::path::Path, feature_contents: &str) -> String {
let g = git();
g.run(wt, &["checkout", "-b", "child"]).unwrap();
g.run(wt, &["rm", "descriptions/tools/slack_post.json"])
.unwrap();
write(wt, "feature.txt", feature_contents);
g.run(wt, &["add", "-A"]).unwrap();
g.run(wt, &["commit", "-m", "dispatch prune + child work"])
.unwrap();
let terminal = g.run_capture(wt, &["rev-parse", "HEAD"]).unwrap();
g.run(wt, &["checkout", "main"]).unwrap();
terminal
}
#[test]
fn apply_excludes_descriptions_so_a_childs_role_prune_never_reaches_the_parent() {
let dir = init_repo();
let wt = dir.path();
seed_descriptions(wt);
let terminal = make_pruning_child(wt, "feature\n");
apply(wt, "p-child", &terminal, &git()).unwrap();
assert_eq!(
std::fs::read_to_string(wt.join("feature.txt")).unwrap(),
"feature\n"
);
assert!(wt.join("descriptions/tools/bash.json").exists());
assert!(wt.join("descriptions/tools/slack_post.json").exists());
}
#[test]
fn apply_declines_on_a_real_conflict_even_when_the_child_also_pruned_descriptions() {
let dir = init_repo();
let wt = dir.path();
seed_descriptions(wt);
let terminal = make_pruning_child(wt, "child version\n");
write(wt, "feature.txt", "parent version\n");
git().run(wt, &["add", "-A"]).unwrap();
git().run(wt, &["commit", "-m", "parent diverged"]).unwrap();
apply(wt, "p-child", &terminal, &git()).unwrap();
let subject = git()
.run_capture(wt, &["log", "-1", "--pretty=%s"])
.unwrap();
assert_eq!(subject, "parent diverged");
let marked = git()
.run_capture(wt, &["rev-parse", "refs/lernie/conflicted/p-child"])
.unwrap();
assert_eq!(marked, terminal);
assert!(wt.join("descriptions/tools/bash.json").exists());
assert!(wt.join("descriptions/tools/slack_post.json").exists());
}