huskies: merge 675_bug_mergemaster_silently_exits_when_feature_branch_has_zero_commits_ahead_of_master
This commit is contained in:
@@ -28,6 +28,34 @@ pub(crate) fn run_squash_merge(
|
||||
.lock()
|
||||
.map_err(|e| format!("Merge lock poisoned: {e}"))?;
|
||||
|
||||
// ── Pre-flight: verify the branch has commits ahead of base ──────────────
|
||||
// A zero-commit branch produces an empty squash and a silent "nothing to
|
||||
// commit" failure. Catch it early with a grep-able error before any merge
|
||||
// work starts.
|
||||
let base_branch = crate::config::ProjectConfig::load(project_root)
|
||||
.ok()
|
||||
.and_then(|c| c.base_branch.clone())
|
||||
.unwrap_or_else(|| "master".to_string());
|
||||
|
||||
let ahead_out = Command::new("git")
|
||||
.args(["rev-list", "--count", &format!("{base_branch}..{branch}")])
|
||||
.current_dir(project_root)
|
||||
.output()
|
||||
.map_err(|e| format!("Failed to count commits ahead: {e}"))?;
|
||||
|
||||
if ahead_out.status.success() {
|
||||
let ahead: u64 = String::from_utf8_lossy(&ahead_out.stdout)
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap_or(1); // parse failure → don't false-positive; let merge proceed
|
||||
if ahead == 0 {
|
||||
return Err(format!(
|
||||
"{story_id}: no commits to merge — feature branch '{branch}' \
|
||||
has 0 commits ahead of '{base_branch}'"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let mut all_output = String::new();
|
||||
let merge_branch = format!("merge-queue/{story_id}");
|
||||
let merge_wt_path = project_root.join(".huskies").join("merge_workspace");
|
||||
@@ -827,16 +855,25 @@ mod tests {
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
let result = run_squash_merge(repo, "feature/story-empty_test", "empty_test").unwrap();
|
||||
let result = run_squash_merge(repo, "feature/story-empty_test", "empty_test");
|
||||
|
||||
// Bug 226: empty diff must NOT be treated as success.
|
||||
assert!(
|
||||
!result.success,
|
||||
"empty diff merge must fail, not silently succeed: {}",
|
||||
result.output
|
||||
);
|
||||
// Bug 226 / 675: a zero-commit branch must not be treated as success.
|
||||
// The pre-flight check (bug 675) returns Err for zero commits ahead;
|
||||
// the older code path returned Ok(SquashMergeResult { success: false }).
|
||||
// Either form is a failure — just not success.
|
||||
match result {
|
||||
Ok(r) => assert!(
|
||||
!r.success,
|
||||
"empty diff merge must fail, not silently succeed: {}",
|
||||
r.output
|
||||
),
|
||||
Err(e) => assert!(
|
||||
e.contains("no commits to merge") || e.contains("nothing to commit"),
|
||||
"unexpected error: {e}"
|
||||
),
|
||||
}
|
||||
|
||||
// Cleanup should still happen.
|
||||
// Cleanup should still happen (no workspace was created for the Err path).
|
||||
assert!(
|
||||
!repo.join(".huskies/merge_workspace").exists(),
|
||||
"merge workspace should be cleaned up"
|
||||
|
||||
Reference in New Issue
Block a user