@@ -70,18 +70,18 @@ type gitRepo struct {
7070 * vcs.GitRepo
7171}
7272
73- func newVcsRemoteErrorOr (msg string , err error , out string ) error {
73+ func newVcsRemoteErrorOr (err error , args [] string , out , msg string ) error {
7474 if err == context .Canceled || err == context .DeadlineExceeded {
7575 return err
7676 }
77- return vcs .NewRemoteError (msg , err , out )
77+ return vcs .NewRemoteError (msg , errors . Wrapf ( err , "command failed: %v" , args ) , out )
7878}
7979
80- func newVcsLocalErrorOr (msg string , err error , out string ) error {
80+ func newVcsLocalErrorOr (err error , args [] string , out , msg string ) error {
8181 if err == context .Canceled || err == context .DeadlineExceeded {
8282 return err
8383 }
84- return vcs .NewLocalError (msg , err , out )
84+ return vcs .NewLocalError (msg , errors . Wrapf ( err , "command failed: %v" , args ) , out )
8585}
8686
8787func (r * gitRepo ) get (ctx context.Context ) error {
@@ -96,11 +96,8 @@ func (r *gitRepo) get(ctx context.Context) error {
9696 r .LocalPath (),
9797 )
9898 if out , err := cmd .CombinedOutput (); err != nil {
99- return newVcsRemoteErrorOr (
100- "unable to get repository" ,
101- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
102- string (out ),
103- )
99+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
100+ "unable to get repository" )
104101 }
105102
106103 return nil
@@ -117,10 +114,8 @@ func (r *gitRepo) fetch(ctx context.Context) error {
117114 )
118115 cmd .SetDir (r .LocalPath ())
119116 if out , err := cmd .CombinedOutput (); err != nil {
120- return newVcsRemoteErrorOr (
121- "unable to update repository" ,
122- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
123- string (out ))
117+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
118+ "unable to update repository" )
124119 }
125120 return nil
126121}
@@ -129,10 +124,8 @@ func (r *gitRepo) updateVersion(ctx context.Context, v string) error {
129124 cmd := commandContext (ctx , "git" , "checkout" , v )
130125 cmd .SetDir (r .LocalPath ())
131126 if out , err := cmd .CombinedOutput (); err != nil {
132- return newVcsLocalErrorOr (
133- "unable to update checked out version" ,
134- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
135- string (out ))
127+ return newVcsLocalErrorOr (err , cmd .Args (), string (out ),
128+ "unable to update checked out version" )
136129 }
137130
138131 return r .defendAgainstSubmodules (ctx )
@@ -153,11 +146,8 @@ func (r *gitRepo) defendAgainstSubmodules(ctx context.Context) error {
153146 )
154147 cmd .SetDir (r .LocalPath ())
155148 if out , err := cmd .CombinedOutput (); err != nil {
156- return newVcsLocalErrorOr (
157- "unexpected error while defensively updating submodules" ,
158- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
159- string (out ),
160- )
149+ return newVcsLocalErrorOr (err , cmd .Args (), string (out ),
150+ "unexpected error while defensively updating submodules" )
161151 }
162152 }
163153
@@ -167,11 +157,8 @@ func (r *gitRepo) defendAgainstSubmodules(ctx context.Context) error {
167157 cmd := commandContext (ctx , "git" , "clean" , "-x" , "-d" , "-f" , "-f" )
168158 cmd .SetDir (r .LocalPath ())
169159 if out , err := cmd .CombinedOutput (); err != nil {
170- return newVcsLocalErrorOr (
171- "unexpected error while defensively cleaning up after possible derelict submodule directories" ,
172- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
173- string (out ),
174- )
160+ return newVcsLocalErrorOr (err , cmd .Args (), string (out ),
161+ "unexpected error while defensively cleaning up after possible derelict submodule directories" )
175162 }
176163 }
177164
@@ -188,11 +175,8 @@ func (r *gitRepo) defendAgainstSubmodules(ctx context.Context) error {
188175 )
189176 cmd .SetDir (r .LocalPath ())
190177 if out , err := cmd .CombinedOutput (); err != nil {
191- return newVcsLocalErrorOr (
192- "unexpected error while defensively cleaning up after possible derelict nested submodule directories" ,
193- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
194- string (out ),
195- )
178+ return newVcsLocalErrorOr (err , cmd .Args (), string (out ),
179+ "unexpected error while defensively cleaning up after possible derelict nested submodule directories" )
196180 }
197181 }
198182
@@ -208,17 +192,14 @@ func (r *bzrRepo) get(ctx context.Context) error {
208192 if _ , err := os .Stat (basePath ); os .IsNotExist (err ) {
209193 err = os .MkdirAll (basePath , 0755 )
210194 if err != nil {
211- return newVcsLocalErrorOr (" unable to create directory" , err , " " )
195+ return newVcsLocalErrorOr (err , nil , "" , " unable to create directory" )
212196 }
213197 }
214198
215199 cmd := commandContext (ctx , "bzr" , "branch" , r .Remote (), r .LocalPath ())
216200 if out , err := cmd .CombinedOutput (); err != nil {
217- return newVcsRemoteErrorOr (
218- "unable to get repository" ,
219- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
220- string (out ),
221- )
201+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
202+ "unable to get repository" )
222203 }
223204
224205 return nil
@@ -228,11 +209,8 @@ func (r *bzrRepo) fetch(ctx context.Context) error {
228209 cmd := commandContext (ctx , "bzr" , "pull" )
229210 cmd .SetDir (r .LocalPath ())
230211 if out , err := cmd .CombinedOutput (); err != nil {
231- return newVcsRemoteErrorOr (
232- "unable to update repository" ,
233- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
234- string (out ),
235- )
212+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
213+ "unable to update repository" )
236214 }
237215 return nil
238216}
@@ -241,11 +219,8 @@ func (r *bzrRepo) updateVersion(ctx context.Context, version string) error {
241219 cmd := commandContext (ctx , "bzr" , "update" , "-r" , version )
242220 cmd .SetDir (r .LocalPath ())
243221 if out , err := cmd .CombinedOutput (); err != nil {
244- return newVcsLocalErrorOr (
245- "unable to update checked out version" ,
246- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
247- string (out ),
248- )
222+ return newVcsLocalErrorOr (err , cmd .Args (), string (out ),
223+ "unable to update checked out version" )
249224 }
250225 return nil
251226}
@@ -257,11 +232,8 @@ type hgRepo struct {
257232func (r * hgRepo ) get (ctx context.Context ) error {
258233 cmd := commandContext (ctx , "hg" , "clone" , r .Remote (), r .LocalPath ())
259234 if out , err := cmd .CombinedOutput (); err != nil {
260- return newVcsRemoteErrorOr (
261- "unable to get repository" ,
262- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
263- string (out ),
264- )
235+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
236+ "unable to get repository" )
265237 }
266238
267239 return nil
@@ -271,11 +243,8 @@ func (r *hgRepo) fetch(ctx context.Context) error {
271243 cmd := commandContext (ctx , "hg" , "pull" )
272244 cmd .SetDir (r .LocalPath ())
273245 if out , err := cmd .CombinedOutput (); err != nil {
274- return newVcsRemoteErrorOr (
275- "unable to fetch latest changes" ,
276- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
277- string (out ),
278- )
246+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
247+ "unable to fetch latest changes" )
279248 }
280249 return nil
281250}
@@ -284,11 +253,8 @@ func (r *hgRepo) updateVersion(ctx context.Context, version string) error {
284253 cmd := commandContext (ctx , "hg" , "update" , version )
285254 cmd .SetDir (r .LocalPath ())
286255 if out , err := cmd .CombinedOutput (); err != nil {
287- return newVcsRemoteErrorOr (
288- "unable to update checked out version" ,
289- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
290- string (out ),
291- )
256+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
257+ "unable to update checked out version" )
292258 }
293259
294260 return nil
@@ -308,11 +274,8 @@ func (r *svnRepo) get(ctx context.Context) error {
308274
309275 cmd := commandContext (ctx , "svn" , "checkout" , remote , r .LocalPath ())
310276 if out , err := cmd .CombinedOutput (); err != nil {
311- return newVcsRemoteErrorOr (
312- "unable to get repository" ,
313- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
314- string (out ),
315- )
277+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
278+ "unable to get repository" )
316279 }
317280
318281 return nil
@@ -322,11 +285,8 @@ func (r *svnRepo) fetch(ctx context.Context) error {
322285 cmd := commandContext (ctx , "svn" , "update" )
323286 cmd .SetDir (r .LocalPath ())
324287 if out , err := cmd .CombinedOutput (); err != nil {
325- return newVcsRemoteErrorOr (
326- "unable to update repository" ,
327- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
328- string (out ),
329- )
288+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
289+ "unable to update repository" )
330290 }
331291
332292 return nil
@@ -336,11 +296,8 @@ func (r *svnRepo) updateVersion(ctx context.Context, version string) error {
336296 cmd := commandContext (ctx , "svn" , "update" , "-r" , version )
337297 cmd .SetDir (r .LocalPath ())
338298 if out , err := cmd .CombinedOutput (); err != nil {
339- return newVcsRemoteErrorOr (
340- "unable to update checked out version" ,
341- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
342- string (out ),
343- )
299+ return newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
300+ "unable to update checked out version" )
344301 }
345302
346303 return nil
@@ -364,15 +321,14 @@ func (r *svnRepo) CommitInfo(id string) (*vcs.CommitInfo, error) {
364321 cmd .SetDir (r .LocalPath ())
365322 out , err := cmd .CombinedOutput ()
366323 if err != nil {
367- return nil , newVcsLocalErrorOr ("unable to retrieve commit information" ,
368- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
369- string (out ),
370- )
324+ return nil , newVcsLocalErrorOr (err , cmd .Args (), string (out ),
325+ "unable to retrieve commit information" )
371326 }
372327
373328 infos := new (info )
374329 if err := xml .Unmarshal (out , & infos ); err != nil {
375- return nil , newVcsLocalErrorOr ("unable to retrieve commit information" , err , string (out ))
330+ return nil , newVcsLocalErrorOr (err , cmd .Args (), string (out ),
331+ "unable to retrieve commit information" )
376332 }
377333
378334 id = infos .Commit .Revision
@@ -385,10 +341,8 @@ func (r *svnRepo) CommitInfo(id string) (*vcs.CommitInfo, error) {
385341 cmd .SetDir (r .LocalPath ())
386342 out , err := cmd .CombinedOutput ()
387343 if err != nil {
388- return nil , newVcsRemoteErrorOr ("unable to retrieve commit information" ,
389- errors .Wrapf (err , "command failed: %v" , cmd .Args ()),
390- string (out ),
391- )
344+ return nil , newVcsRemoteErrorOr (err , cmd .Args (), string (out ),
345+ "unable to retrieve commit information" )
392346 }
393347
394348 type logentry struct {
@@ -404,7 +358,8 @@ func (r *svnRepo) CommitInfo(id string) (*vcs.CommitInfo, error) {
404358
405359 logs := new (log )
406360 if err := xml .Unmarshal (out , & logs ); err != nil {
407- return nil , newVcsLocalErrorOr ("unable to retrieve commit information" , err , string (out ))
361+ return nil , newVcsLocalErrorOr (err , cmd .Args (), string (out ),
362+ "unable to retrieve commit information" )
408363 }
409364
410365 if len (logs .Logs ) == 0 {
@@ -420,7 +375,8 @@ func (r *svnRepo) CommitInfo(id string) (*vcs.CommitInfo, error) {
420375 if len (logs .Logs [0 ].Date ) > 0 {
421376 ci .Date , err = time .Parse (time .RFC3339Nano , logs .Logs [0 ].Date )
422377 if err != nil {
423- return nil , newVcsLocalErrorOr ("unable to retrieve commit information" , err , string (out ))
378+ return nil , newVcsLocalErrorOr (err , cmd .Args (), string (out ),
379+ "unable to retrieve commit information" )
424380 }
425381 }
426382
0 commit comments