@@ -229,7 +229,7 @@ func (cmd *getCmd) doGet(reposPathList []pathutil.ReposPath, lockJSON *lockjson.
229
229
} else {
230
230
added := cmd .updateReposVersion (lockJSON , r .reposPath , r .reposType , r .hash , profile )
231
231
if added && strings .Contains (status , "already exists" ) {
232
- status = fmt .Sprintf (fmtAddedRepos , statusPrefixInstalled , r .reposPath )
232
+ status = fmt .Sprintf (fmtAddedRepos , r .reposPath )
233
233
}
234
234
updatedLockJSON = true
235
235
}
@@ -291,21 +291,19 @@ type getParallelResult struct {
291
291
}
292
292
293
293
const (
294
- statusPrefixFailed = "!"
295
- statusPrefixNoChange = "#"
296
- statusPrefixInstalled = "+"
297
- statusPrefixUpgraded = "*"
298
- )
299
-
300
- const (
301
- fmtInstallFailed = "%s %s > install failed > %s"
302
- fmtUpgradeFailed = "%s %s > upgrade failed > %s"
303
- fmtNoChange = "%s %s > no change"
304
- fmtAlreadyExists = "%s %s > already exists"
305
- fmtAddedRepos = "%s %s > added repository to current profile"
306
- fmtInstalled = "%s %s > installed"
307
- fmtRevUpdate = "%s %s > updated lock.json revision (%s..%s)"
308
- fmtUpgraded = "%s %s > upgraded (%s..%s)"
294
+ statusPrefixFailed = "!"
295
+ // Failed
296
+ fmtInstallFailed = "! %s > install failed > %s"
297
+ fmtUpgradeFailed = "! %s > upgrade failed > %s"
298
+ // No change
299
+ fmtNoChange = "# %s > no change"
300
+ fmtAlreadyExists = "# %s > already exists"
301
+ // Installed
302
+ fmtAddedRepos = "+ %s > added repository to current profile"
303
+ fmtInstalled = "+ %s > installed"
304
+ // Upgraded
305
+ fmtRevUpdate = "* %s > updated lock.json revision (%s..%s)"
306
+ fmtUpgraded = "* %s > upgraded (%s..%s)"
309
307
)
310
308
311
309
// This function is executed in goroutine of each plugin.
@@ -328,6 +326,7 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
328
326
// true:upgrade, false:install
329
327
fullReposPath := pathutil .FullReposPath (reposPath )
330
328
doUpgrade := cmd .upgrade && pathutil .Exists (fullReposPath )
329
+ doInstall := ! pathutil .Exists (fullReposPath )
331
330
332
331
var fromHash string
333
332
var err error
@@ -343,7 +342,7 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
343
342
}
344
343
done <- getParallelResult {
345
344
reposPath : reposPath ,
346
- status : fmt .Sprintf (fmtInstallFailed , statusPrefixFailed , reposPath , result .Error ()),
345
+ status : fmt .Sprintf (fmtInstallFailed , reposPath , result .Error ()),
347
346
err : result ,
348
347
}
349
348
return
@@ -352,14 +351,15 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
352
351
353
352
var status string
354
353
var upgraded bool
354
+ var checkRevision bool
355
355
356
356
if doUpgrade {
357
357
// when cmd.upgrade is true, repos must not be nil.
358
358
if repos == nil {
359
359
msg := "-u was specified but repos == nil"
360
360
done <- getParallelResult {
361
361
reposPath : reposPath ,
362
- status : fmt .Sprintf (fmtUpgradeFailed , statusPrefixFailed , reposPath , msg ),
362
+ status : fmt .Sprintf (fmtUpgradeFailed , reposPath , msg ),
363
363
err : errors .New ("failed to upgrade plugin: " + msg ),
364
364
}
365
365
return
@@ -376,22 +376,21 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
376
376
}
377
377
done <- getParallelResult {
378
378
reposPath : reposPath ,
379
- status : fmt .Sprintf (fmtUpgradeFailed , statusPrefixFailed , reposPath , err .Error ()),
379
+ status : fmt .Sprintf (fmtUpgradeFailed , reposPath , err .Error ()),
380
380
err : result ,
381
381
}
382
382
return
383
383
}
384
384
if err == git .NoErrAlreadyUpToDate {
385
- status = fmt .Sprintf (fmtNoChange , statusPrefixNoChange , reposPath )
385
+ status = fmt .Sprintf (fmtNoChange , reposPath )
386
386
} else {
387
387
upgraded = true
388
388
}
389
- } else if ! pathutil . Exists ( fullReposPath ) {
389
+ } else if doInstall {
390
390
// Install plugin
391
391
logger .Debug ("Installing " + reposPath + " ..." )
392
392
err := cmd .fetchPlugin (reposPath )
393
- // if err == errRepoExists, silently skip
394
- if err != nil && err != errRepoExists {
393
+ if err != nil {
395
394
result := errors .New ("failed to install plugin: " + err .Error ())
396
395
logger .Debug ("Rollbacking " + fullReposPath + " ..." )
397
396
err = cmd .rollbackRepos (fullReposPath )
@@ -400,16 +399,15 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
400
399
}
401
400
done <- getParallelResult {
402
401
reposPath : reposPath ,
403
- status : fmt .Sprintf (fmtInstallFailed , statusPrefixFailed , reposPath , result .Error ()),
402
+ status : fmt .Sprintf (fmtInstallFailed , reposPath , result .Error ()),
404
403
err : result ,
405
404
}
406
405
return
407
406
}
408
- if err == errRepoExists {
409
- status = fmt .Sprintf (fmtAlreadyExists , statusPrefixNoChange , reposPath )
410
- } else {
411
- status = fmt .Sprintf (fmtInstalled , statusPrefixInstalled , reposPath )
412
- }
407
+ status = fmt .Sprintf (fmtInstalled , reposPath )
408
+ } else {
409
+ status = fmt .Sprintf (fmtAlreadyExists , reposPath )
410
+ checkRevision = true
413
411
}
414
412
415
413
var toHash string
@@ -426,7 +424,7 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
426
424
}
427
425
done <- getParallelResult {
428
426
reposPath : reposPath ,
429
- status : fmt .Sprintf (fmtInstallFailed , statusPrefixFailed , reposPath , result .Error ()),
427
+ status : fmt .Sprintf (fmtInstallFailed , reposPath , result .Error ()),
430
428
err : result ,
431
429
}
432
430
return
@@ -435,13 +433,11 @@ func (cmd *getCmd) installPlugin(reposPath pathutil.ReposPath, repos *lockjson.R
435
433
436
434
// Show old and new revisions: "upgraded ({from}..{to})".
437
435
if upgraded {
438
- status = fmt .Sprintf (fmtUpgraded , statusPrefixUpgraded , reposPath , fromHash , toHash )
436
+ status = fmt .Sprintf (fmtUpgraded , reposPath , fromHash , toHash )
439
437
}
440
438
441
- if repos != nil && repos .Version != toHash {
442
- status = fmt .Sprintf (fmtRevUpdate , statusPrefixUpgraded , reposPath , repos .Version , toHash )
443
- } else {
444
- status = fmt .Sprintf (fmtNoChange , statusPrefixNoChange , reposPath )
439
+ if checkRevision && repos != nil && repos .Version != toHash {
440
+ status = fmt .Sprintf (fmtRevUpdate , reposPath , repos .Version , toHash )
445
441
}
446
442
447
443
done <- getParallelResult {
@@ -466,7 +462,7 @@ func (cmd *getCmd) installPlugconf(reposPath pathutil.ReposPath, pluginResult *g
466
462
}
467
463
done <- getParallelResult {
468
464
reposPath : reposPath ,
469
- status : fmt .Sprintf (fmtInstallFailed , statusPrefixFailed , reposPath , result .Error ()),
465
+ status : fmt .Sprintf (fmtInstallFailed , reposPath , result .Error ()),
470
466
err : result ,
471
467
}
472
468
return
@@ -566,7 +562,7 @@ func (cmd *getCmd) fetchPlugconf(reposPath pathutil.ReposPath) error {
566
562
}
567
563
content , err := plugconf .GenPlugconfByTemplate (tmpl , filename )
568
564
if err != nil {
569
- return err
565
+ return fmt . Errorf ( "parse error in fetched plugconf %s: %s" , reposPath , err . Error ())
570
566
}
571
567
os .MkdirAll (filepath .Dir (filename ), 0755 )
572
568
err = ioutil .WriteFile (filename , content , 0644 )
0 commit comments