aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/protocol/packp/report_status.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-12-19 23:36:44 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-12-19 23:36:44 +0100
commit90d67bb648ae32d5b1a0f7b1af011da6dfb24315 (patch)
treefc8c14e82974be6ff49e842328ec3206ebf1b4c2 /plumbing/protocol/packp/report_status.go
parent725ade0de6f60549e65cc4d94094b1f5ed48587f (diff)
downloadgo-git-90d67bb648ae32d5b1a0f7b1af011da6dfb24315.tar.gz
remote: add Push (#178)
* remote: add Push. * add Push method to Remote. * add method Push to Repository. * examples: add push example. * requested changes * add tests, fixes
Diffstat (limited to 'plumbing/protocol/packp/report_status.go')
-rw-r--r--plumbing/protocol/packp/report_status.go29
1 files changed, 22 insertions, 7 deletions
diff --git a/plumbing/protocol/packp/report_status.go b/plumbing/protocol/packp/report_status.go
index ead4bb6..29c1a4c 100644
--- a/plumbing/protocol/packp/report_status.go
+++ b/plumbing/protocol/packp/report_status.go
@@ -26,9 +26,19 @@ func NewReportStatus() *ReportStatus {
return &ReportStatus{}
}
-// Ok returns true if the report status reported no error.
-func (s *ReportStatus) Ok() bool {
- return s.UnpackStatus == ok
+// Error returns the first error if any.
+func (s *ReportStatus) Error() error {
+ if s.UnpackStatus != ok {
+ return fmt.Errorf("unpack error: %s", s.UnpackStatus)
+ }
+
+ for _, s := range s.CommandStatuses {
+ if err := s.Error(); err != nil {
+ return err
+ }
+ }
+
+ return nil
}
// Encode writes the report status to a writer.
@@ -135,14 +145,19 @@ type CommandStatus struct {
Status string
}
-// Ok returns true if the command status reported no error.
-func (s *CommandStatus) Ok() bool {
- return s.Status == ok
+// Error returns the error, if any.
+func (s *CommandStatus) Error() error {
+ if s.Status == ok {
+ return nil
+ }
+
+ return fmt.Errorf("command error on %s: %s",
+ s.ReferenceName.String(), s.Status)
}
func (s *CommandStatus) encode(w io.Writer) error {
e := pktline.NewEncoder(w)
- if s.Ok() {
+ if s.Error() == nil {
return e.Encodef("ok %s\n", s.ReferenceName.String())
}