a73x

1418d875

Polish commit-link warning and test helper

alex emery   2026-04-12 09:01

- scan_and_link's append_event failure warning now prefixes with the
  commit SHA, matching every other warning in the function.
- make_commit_with_message test helper drops the unused cluster param;
  the seeding fallback only needs the repo handle.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

diff --git a/src/commit_link.rs b/src/commit_link.rs
index f4ffa51..f23078e 100644
--- a/src/commit_link.rs
+++ b/src/commit_link.rs
@@ -257,8 +257,8 @@ pub fn scan_and_link(
                        }
                        Err(e) => {
                            eprintln!(
                                "warning: failed to emit IssueCommitLink on {}: {}",
                                resolved_ref, e
                                "warning: commit {}: failed to emit IssueCommitLink on {}: {}",
                                oid, resolved_ref, e
                            );
                        }
                    }
diff --git a/tests/sync_test.rs b/tests/sync_test.rs
index b7a7729..b91c656 100644
--- a/tests/sync_test.rs
+++ b/tests/sync_test.rs
@@ -1192,8 +1192,7 @@ fn test_corrupted_state_file_handled_gracefully() {

use git_collab::commit_link;

fn make_commit_with_message(cluster: &TestCluster, repo: &Repository, message: &str) -> git2::Oid {
    let _ = cluster; // silence unused if not needed
fn make_commit_with_message(repo: &Repository, message: &str) -> git2::Oid {
    let sig = git2::Signature::now("Alice", "alice@example.com").unwrap();
    // The TestCluster bare repo commits onto refs/heads/main but its HEAD
    // remains the default refs/heads/master, so clones don't get a local
@@ -1233,7 +1232,7 @@ fn commit_link_scan_emits_event_for_matching_trailer() {

    // Create a commit whose trailer references that issue.
    let message = format!("Fix walker\n\nIssue: {}", &issue_id[..8]);
    let commit_oid = make_commit_with_message(&cluster, &alice_repo, &message);
    let commit_oid = make_commit_with_message(&alice_repo, &message);

    // Run the scanner directly (we test the sync integration in later tests).
    let author = git_collab::identity::get_author(&alice_repo).unwrap();
@@ -1261,7 +1260,7 @@ fn sync_entry_point_emits_commit_link_events_and_pushes_them() {

    // Alice makes a real commit with an Issue: trailer.
    let message = format!("Fix the thing\n\nIssue: {}", &issue_id[..8]);
    make_commit_with_message(&cluster, &alice_repo, &message);
    make_commit_with_message(&alice_repo, &message);

    // Running sync should scan, emit the link, and push it.
    sync::sync(&alice_repo, "origin").unwrap();
@@ -1281,7 +1280,7 @@ fn commit_link_scan_is_idempotent_across_runs() {
    let (issue_ref, issue_id) = open_issue(&alice_repo, &alice(), "bug");

    let message = format!("Fix thing\n\nIssue: {}", &issue_id[..8]);
    make_commit_with_message(&cluster, &alice_repo, &message);
    make_commit_with_message(&alice_repo, &message);

    let author = git_collab::identity::get_author(&alice_repo).unwrap();
    let sk = signing::load_signing_key(&signing::signing_key_dir().unwrap()).unwrap();
@@ -1302,7 +1301,7 @@ fn commit_link_scan_walks_all_local_branches_and_dedups_shared_ancestors() {

    // Commit on main with the trailer. Both branches will reach it.
    let message = format!("Fix\n\nIssue: {}", &issue_id[..8]);
    let linked_commit = make_commit_with_message(&cluster, &alice_repo, &message);
    let linked_commit = make_commit_with_message(&alice_repo, &message);

    // Create a second branch pointing at the same commit.
    {
@@ -1332,7 +1331,7 @@ fn commit_link_scan_handles_multiple_issue_trailers_on_one_commit() {
        &id_a[..8],
        &id_b[..8]
    );
    make_commit_with_message(&cluster, &alice_repo, &message);
    make_commit_with_message(&alice_repo, &message);

    let author = git_collab::identity::get_author(&alice_repo).unwrap();
    let sk = signing::load_signing_key(&signing::signing_key_dir().unwrap()).unwrap();
@@ -1351,7 +1350,6 @@ fn commit_link_scan_skips_unknown_prefix_without_error() {

    // No issue exists. Commit uses a completely unrelated prefix.
    make_commit_with_message(
        &cluster,
        &alice_repo,
        "Fix\n\nIssue: zzzzzzzz",
    );
@@ -1385,7 +1383,6 @@ fn commit_link_scan_skips_ambiguous_prefix_without_error() {
    };

    make_commit_with_message(
        &cluster,
        &alice_repo,
        &format!("Touch\n\nIssue: {}", shared_prefix),
    );
@@ -1406,7 +1403,6 @@ fn commit_link_scan_skips_archived_issues_with_warning() {
    state::archive_issue_ref(&alice_repo, &issue_id).unwrap();

    make_commit_with_message(
        &cluster,
        &alice_repo,
        &format!("Reference old\n\nIssue: {}", &issue_id[..8]),
    );
@@ -1430,7 +1426,7 @@ fn commit_link_scan_no_op_on_detached_head_with_no_branches() {

    // Seed refs/heads/main so HEAD resolves to a commit we can detach onto.
    // make_commit_with_message creates refs/heads/main if missing.
    make_commit_with_message(&cluster, &alice_repo, "seed for detached head test");
    make_commit_with_message(&alice_repo, "seed for detached head test");

    // Put HEAD in detached state pointing at the current main tip, then
    // delete all local branches so scan_and_link has nothing to walk.
@@ -1470,7 +1466,7 @@ fn commit_link_scan_dedups_against_remote_originated_events() {
    // Alice writes a commit and pushes it to the bare remote so Bob can
    // fetch it. First the regular git push; then sync for the link event.
    let message = format!("Fix thing\n\nIssue: {}", &issue_id[..8]);
    let linked_commit = make_commit_with_message(&cluster, &alice_repo, &message);
    let linked_commit = make_commit_with_message(&alice_repo, &message);
    // Push the branch so Bob sees the commit too.
    let mut cmd = Command::new("git");
    cmd.args(["push", "origin", "main"])