From 47f4bf046eb0cb7f45fe2f26359a177ef40cd68e Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 18 Sep 2024 09:31:52 +0100 Subject: feat(remote): push report copy improved for push to each git server. report now reflects new branch / tag, delete branch / tag and force flag. --- src/bin/git_remote_nostr/push.rs | 52 ++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index dab0103..a0bcea3 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -434,21 +434,43 @@ fn push_to_remote_url( let existing_lines = reporter.count_all_existing_lines(); for update in updates { - let msg = format!( - "push: {}..{} {} -> {}", - oid_to_shorthand_string(update.src()).unwrap(), - oid_to_shorthand_string(update.dst()).unwrap(), - update - .src_refname() - .unwrap_or("") - .replace("refs/heads/", "") - .replace("refs/tags/", "tags/"), - update - .dst_refname() - .unwrap_or("") - .replace("refs/heads/", "") - .replace("refs/tags/", "tags/"), - ); + let dst_refname = update + .dst_refname() + .unwrap_or("") + .replace("refs/heads/", "") + .replace("refs/tags/", "tags/"); + let msg = if update.dst().is_zero() { + format!("push: - [delete] {dst_refname}") + } else if update.src().is_zero() { + if update.dst_refname().unwrap_or("").contains("refs/tags") { + format!("push: * [new tag] {dst_refname}") + } else { + format!("push: * [new branch] {dst_refname}") + } + } else { + let force = remote_refspecs + .iter() + .any(|r| r.contains(&dst_refname) && r.contains('+')); + format!( + "push: {} {}..{} {} -> {dst_refname}", + if force { "+" } else { " " }, + oid_to_shorthand_string(update.src()).unwrap(), + oid_to_shorthand_string(update.dst()).unwrap(), + update + .src_refname() + .unwrap_or("") + .replace("refs/heads/", "") + .replace("refs/tags/", "tags/"), + ) + }; + // other possibilities will result in push to fail but better reporting is + // needed: + // deleting a non-existant branch: + // ! [remote rejected] -> (not found) + // adding a branch that already exists: + // ! [remote rejected] -> (already exists) + // pushing without non-fast-forward without force: + // ! [rejected] -> (non-fast-forward) reporter.negotiation.push(msg); } reporter.write_all(existing_lines); -- cgit v1.2.3