@@ -33,7 +33,7 @@ func NewGitRepo(remote, local string) (*GitRepo, error) {
33
33
c .Env = envForDir (c .Dir )
34
34
out , err := c .CombinedOutput ()
35
35
if err != nil {
36
- return nil , err
36
+ return nil , NewLocalError ( "Unable to retrieve local repo information" , err , string ( out ))
37
37
}
38
38
39
39
localRemote := strings .TrimSpace (string (out ))
@@ -75,58 +75,63 @@ func (s *GitRepo) Get() error {
75
75
if _ , err := os .Stat (basePath ); os .IsNotExist (err ) {
76
76
err = os .MkdirAll (basePath , 0755 )
77
77
if err != nil {
78
- return NewGetError ( err , "" )
78
+ return NewLocalError ( "Unable to create directory" , err , "" )
79
79
}
80
80
81
81
out , err = s .run ("git" , "clone" , s .Remote (), s .LocalPath ())
82
82
if err != nil {
83
- return NewGetError ( err , string (out ))
83
+ return NewRemoteError ( "Unable to get repository" , err , string (out ))
84
84
}
85
85
return err
86
86
}
87
87
88
88
} else if err != nil {
89
- return NewGetError ( err , string (out ))
89
+ return NewRemoteError ( "Unable to get repository" , err , string (out ))
90
90
}
91
91
92
- return err
92
+ return nil
93
93
}
94
94
95
95
// Update performs an Git fetch and pull to an existing checkout.
96
96
func (s * GitRepo ) Update () error {
97
97
// Perform a fetch to make sure everything is up to date.
98
- _ , err := s .RunFromDir ("git" , "fetch" , s .RemoteLocation )
98
+ out , err := s .RunFromDir ("git" , "fetch" , s .RemoteLocation )
99
99
if err != nil {
100
- return err
100
+ return NewRemoteError ( "Unable to update repository" , err , string ( out ))
101
101
}
102
102
103
103
// When in a detached head state, such as when an individual commit is checked
104
104
// out do not attempt a pull. It will cause an error.
105
105
detached , err := isDetachedHead (s .LocalPath ())
106
-
107
106
if err != nil {
108
- return err
107
+ return NewLocalError ( "Unable to update repository" , err , "" )
109
108
}
110
109
111
110
if detached == true {
112
111
return nil
113
112
}
114
113
115
- _ , err = s .RunFromDir ("git" , "pull" )
116
- return err
114
+ out , err = s .RunFromDir ("git" , "pull" )
115
+ if err != nil {
116
+ return NewRemoteError ("Unable to update repository" , err , string (out ))
117
+ }
118
+ return nil
117
119
}
118
120
119
121
// UpdateVersion sets the version of a package currently checked out via Git.
120
122
func (s * GitRepo ) UpdateVersion (version string ) error {
121
- _ , err := s .RunFromDir ("git" , "checkout" , version )
122
- return err
123
+ out , err := s .RunFromDir ("git" , "checkout" , version )
124
+ if err != nil {
125
+ return NewLocalError ("Unable to update checked out version" , err , string (out ))
126
+ }
127
+ return nil
123
128
}
124
129
125
130
// Version retrieves the current version.
126
131
func (s * GitRepo ) Version () (string , error ) {
127
132
out , err := s .RunFromDir ("git" , "rev-parse" , "HEAD" )
128
133
if err != nil {
129
- return "" , err
134
+ return "" , NewLocalError ( "Unable to retrieve checked out version" , err , string ( out ))
130
135
}
131
136
132
137
return strings .TrimSpace (string (out )), nil
@@ -136,11 +141,11 @@ func (s *GitRepo) Version() (string, error) {
136
141
func (s * GitRepo ) Date () (time.Time , error ) {
137
142
out , err := s .RunFromDir ("git" , "log" , "-1" , "--date=iso" , "--pretty=format:%cd" )
138
143
if err != nil {
139
- return time.Time {}, err
144
+ return time.Time {}, NewLocalError ( "Unable to retrieve revision date" , err , string ( out ))
140
145
}
141
146
t , err := time .Parse (longForm , string (out ))
142
147
if err != nil {
143
- return time.Time {}, err
148
+ return time.Time {}, NewLocalError ( "Unable to retrieve revision date" , err , string ( out ))
144
149
}
145
150
return t , nil
146
151
}
@@ -149,7 +154,7 @@ func (s *GitRepo) Date() (time.Time, error) {
149
154
func (s * GitRepo ) Branches () ([]string , error ) {
150
155
out , err := s .RunFromDir ("git" , "show-ref" )
151
156
if err != nil {
152
- return []string {}, err
157
+ return []string {}, NewLocalError ( "Unable to retrieve branches" , err , string ( out ))
153
158
}
154
159
branches := s .referenceList (string (out ), `(?m-s)(?:` + s .RemoteLocation + `)/(\S+)$` )
155
160
return branches , nil
@@ -159,7 +164,7 @@ func (s *GitRepo) Branches() ([]string, error) {
159
164
func (s * GitRepo ) Tags () ([]string , error ) {
160
165
out , err := s .RunFromDir ("git" , "show-ref" )
161
166
if err != nil {
162
- return []string {}, err
167
+ return []string {}, NewLocalError ( "Unable to retrieve tags" , err , string ( out ))
163
168
}
164
169
tags := s .referenceList (string (out ), `(?m-s)(?:tags)/(\S+)$` )
165
170
return tags , nil
@@ -216,12 +221,12 @@ func (s *GitRepo) CommitInfo(id string) (*CommitInfo, error) {
216
221
}{}
217
222
err = xml .Unmarshal (out , & cis )
218
223
if err != nil {
219
- return nil , err
224
+ return nil , NewLocalError ( "Unable to retrieve commit information" , err , string ( out ))
220
225
}
221
226
222
227
t , err := time .Parse ("Mon, _2 Jan 2006 15:04:05 -0700" , cis .Date )
223
228
if err != nil {
224
- return nil , err
229
+ return nil , NewLocalError ( "Unable to retrieve commit information" , err , string ( out ))
225
230
}
226
231
227
232
ci := & CommitInfo {
0 commit comments