| 1 | # ABSTRACT: Per-ref outcomes from a Remote fetch or push | ||
| 2 | |||
| 3 | package Git::Native::Remote::Result; | ||
| 4 | our $VERSION = '0.006'; | ||
| 5 | use Moo; | ||
| 6 | use Carp (); | ||
| 7 | use namespace::clean; | ||
| 8 | |||
| 9 | # Result of a Git::Native::Remote fetch or push. libgit2 returns 0 even when | ||
| 10 | # individual refs were rejected or skipped; the only way to learn about it | ||
| 11 | # is via the per-ref callbacks (update_tips for fetch, push_update_reference | ||
| 12 | # for push). This class is the structured surface for those outcomes. | ||
| 13 | # | ||
| 14 | # $remote->fetch(...); # returns $result | ||
| 15 | # for my $u (@{$result->updated}) { say "$u->{ref}: $u->{from} -> $u->{to}" } | ||
| 16 | # for my $r (@{$result->rejected}) { say "$r->{ref}: $r->{reason}" } | ||
| 17 | # | ||
| 18 | # updated entries always carry the SAME four keys, whichever operation | ||
| 19 | # produced them — { ref, from, to, reason } — so a caller can read any of | ||
| 20 | # them without knowing where the Result came from, and a missing value is an | ||
| 21 | # explicit undef rather than an absent key: | ||
| 22 | # | ||
| 23 | # fetch: { ref => $local_name, from => $oid_hex|undef, to => $oid_hex|undef, reason => '' } | ||
| 24 | # push: { ref => $remote_name, from => undef, to => $oid_hex|undef, reason => '' } | ||
| 25 | # | ||
| 26 | # from is undef on push: push_update_reference reports a per-ref verdict, | ||
| 27 | # not the oid range, and the previous remote-side oid would cost an extra | ||
| 28 | # git_remote_ls round trip. to is recovered from the local source ref. | ||
| 29 | # to is undef when the ref was deleted (fetch prune, push delete refspec). | ||
| 30 | # reason is '' on both — a non-empty reason means rejected, see below. | ||
| 31 | # rejected entries: { ref => $name, reason => $status_str } | ||
| 32 | # - On push: reason is the libgit2 status string the server sent (e.g. | ||
| 33 | # "non-fast-forward", "pre-receive hook declined"). reason is "" (empty | ||
| 34 | # string, not undef) when the server reported success for that ref with | ||
| 35 | # no specific message. | ||
| 36 | # - On fetch: reason is currently always "" — the update_tips callback only | ||
| 37 | # fires on accepted updates; libgit2's "non-fast-forward skipped" path | ||
| 38 | # does NOT route through it. Kept for API symmetry. | ||
| 39 | # | ||
| 40 | # ok() returns true iff both lists are empty — i.e. every ref succeeded | ||
| 41 | # without an explicit "skipped" or "rejected" signal. Note that on a | ||
| 42 | # successful push of N refs, all N land in `updated` and `ok` is false; | ||
| 43 | # `ok` is mostly useful for "I expected N updates, did anything fail?". | ||
| 44 | has updated => ( is => 'ro', default => sub { [] } ); | ||
| 45 | has rejected => ( is => 'ro', default => sub { [] } ); | ||
| 46 | |||
| 47 | sub ok { !@{ $_[0]->updated } && !@{ $_[0]->rejected } } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ |