diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-18 09:31:52 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-18 09:36:06 +0100 |
| commit | 47f4bf046eb0cb7f45fe2f26359a177ef40cd68e (patch) | |
| tree | 923a09ca8a82a91076f70fd85aadb0657975dcf2 | |
| parent | acfb3c2f18bc0d1e04056018fe93297d8f9ab925 (diff) | |
feat(remote): push report copy
improved for push to each git server. report now reflects new
branch / tag, delete branch / tag and force flag.
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 52 |
1 files 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( | |||
| 434 | let existing_lines = reporter.count_all_existing_lines(); | 434 | let existing_lines = reporter.count_all_existing_lines(); |
| 435 | 435 | ||
| 436 | for update in updates { | 436 | for update in updates { |
| 437 | let msg = format!( | 437 | let dst_refname = update |
| 438 | "push: {}..{} {} -> {}", | 438 | .dst_refname() |
| 439 | oid_to_shorthand_string(update.src()).unwrap(), | 439 | .unwrap_or("") |
| 440 | oid_to_shorthand_string(update.dst()).unwrap(), | 440 | .replace("refs/heads/", "") |
| 441 | update | 441 | .replace("refs/tags/", "tags/"); |
| 442 | .src_refname() | 442 | let msg = if update.dst().is_zero() { |
| 443 | .unwrap_or("") | 443 | format!("push: - [delete] {dst_refname}") |
| 444 | .replace("refs/heads/", "") | 444 | } else if update.src().is_zero() { |
| 445 | .replace("refs/tags/", "tags/"), | 445 | if update.dst_refname().unwrap_or("").contains("refs/tags") { |
| 446 | update | 446 | format!("push: * [new tag] {dst_refname}") |
| 447 | .dst_refname() | 447 | } else { |
| 448 | .unwrap_or("") | 448 | format!("push: * [new branch] {dst_refname}") |
| 449 | .replace("refs/heads/", "") | 449 | } |
| 450 | .replace("refs/tags/", "tags/"), | 450 | } else { |
| 451 | ); | 451 | let force = remote_refspecs |
| 452 | .iter() | ||
| 453 | .any(|r| r.contains(&dst_refname) && r.contains('+')); | ||
| 454 | format!( | ||
| 455 | "push: {} {}..{} {} -> {dst_refname}", | ||
| 456 | if force { "+" } else { " " }, | ||
| 457 | oid_to_shorthand_string(update.src()).unwrap(), | ||
| 458 | oid_to_shorthand_string(update.dst()).unwrap(), | ||
| 459 | update | ||
| 460 | .src_refname() | ||
| 461 | .unwrap_or("") | ||
| 462 | .replace("refs/heads/", "") | ||
| 463 | .replace("refs/tags/", "tags/"), | ||
| 464 | ) | ||
| 465 | }; | ||
| 466 | // other possibilities will result in push to fail but better reporting is | ||
| 467 | // needed: | ||
| 468 | // deleting a non-existant branch: | ||
| 469 | // ! [remote rejected] <old-branch-name> -> <old-branch-name> (not found) | ||
| 470 | // adding a branch that already exists: | ||
| 471 | // ! [remote rejected] <new-branch-name> -> <new-branch-name> (already exists) | ||
| 472 | // pushing without non-fast-forward without force: | ||
| 473 | // ! [rejected] <branch-name> -> <branch-name> (non-fast-forward) | ||
| 452 | reporter.negotiation.push(msg); | 474 | reporter.negotiation.push(msg); |
| 453 | } | 475 | } |
| 454 | reporter.write_all(existing_lines); | 476 | reporter.write_all(existing_lines); |