mod common;
use common::fixtures::WorkspaceBuilder;
use common::git_helpers;
#[test]
fn test_prune_dry_run_lists_merged_branches() {
let ws = WorkspaceBuilder::new().add_repo("alpha").build();
let repo_path = ws.repo_path("alpha");
git_helpers::create_branch(&repo_path, "feat/merged");
git_helpers::commit_file(&repo_path, "feature.txt", "content", "Add feature");
git_helpers::checkout(&repo_path, "main");
std::process::Command::new("git")
.args(["merge", "feat/merged", "--no-ff", "-m", "Merge feat/merged"])
.current_dir(&repo_path)
.output()
.unwrap();
let repo = gitgrip::git::open_repo(&repo_path).unwrap();
let is_merged = gitgrip::git::branch::is_branch_merged(&repo, "feat/merged", "main").unwrap();
assert!(is_merged, "Branch should be merged");
let manifest = ws.load_manifest();
let result = gitgrip::cli::commands::prune::run_prune(
&ws.workspace_root,
&manifest,
false, false,
None,
None,
);
assert!(result.is_ok());
assert!(git_helpers::branch_exists(&repo_path, "feat/merged"));
}
#[test]
fn test_prune_execute_deletes_merged_branches() {
let ws = WorkspaceBuilder::new().add_repo("alpha").build();
let repo_path = ws.repo_path("alpha");
git_helpers::create_branch(&repo_path, "feat/to-delete");
git_helpers::commit_file(&repo_path, "feature.txt", "content", "Add feature");
git_helpers::checkout(&repo_path, "main");
std::process::Command::new("git")
.args([
"merge",
"feat/to-delete",
"--no-ff",
"-m",
"Merge feat/to-delete",
])
.current_dir(&repo_path)
.output()
.unwrap();
let manifest = ws.load_manifest();
let result = gitgrip::cli::commands::prune::run_prune(
&ws.workspace_root,
&manifest,
true, false,
None,
None,
);
assert!(result.is_ok());
assert!(!git_helpers::branch_exists(&repo_path, "feat/to-delete"));
}
#[test]
fn test_prune_skips_current_and_default() {
let ws = WorkspaceBuilder::new().add_repo("alpha").build();
let repo_path = ws.repo_path("alpha");
let manifest = ws.load_manifest();
let result = gitgrip::cli::commands::prune::run_prune(
&ws.workspace_root,
&manifest,
true, false,
None,
None,
);
assert!(result.is_ok());
assert!(git_helpers::branch_exists(&repo_path, "main"));
}
#[test]
fn test_prune_no_merged_branches() {
let ws = WorkspaceBuilder::new().add_repo("alpha").build();
let repo_path = ws.repo_path("alpha");
git_helpers::create_branch(&repo_path, "feat/unmerged");
git_helpers::commit_file(&repo_path, "feature.txt", "content", "Add feature");
git_helpers::checkout(&repo_path, "main");
let manifest = ws.load_manifest();
let result = gitgrip::cli::commands::prune::run_prune(
&ws.workspace_root,
&manifest,
true,
false,
None,
None,
);
assert!(result.is_ok());
assert!(git_helpers::branch_exists(&repo_path, "feat/unmerged"));
}