@@ -2,6 +2,7 @@ package exec
2
2
3
3
import (
4
4
"fmt"
5
+ "net/url"
5
6
"os"
6
7
"path/filepath"
7
8
"strings"
@@ -18,6 +19,7 @@ import (
18
19
"github.com/cloudposse/atmos/internal/tui/templates/term"
19
20
"github.com/cloudposse/atmos/pkg/schema"
20
21
"github.com/cloudposse/atmos/pkg/ui/theme"
22
+ u "github.com/cloudposse/atmos/pkg/utils"
21
23
)
22
24
23
25
type pkgType int
@@ -330,8 +332,9 @@ func max(a, b int) int {
330
332
331
333
func downloadAndInstall (p * pkgAtmosVendor , dryRun bool , atmosConfig * schema.AtmosConfiguration ) tea.Cmd {
332
334
return func () tea.Msg {
335
+ log .Debug ("Downloading and installing package" , "package" , p .name )
333
336
if dryRun {
334
- return handleDryRunInstall (p )
337
+ return handleDryRunInstall (p , atmosConfig )
335
338
}
336
339
tempDir , err := createTempDir ()
337
340
if err != nil {
@@ -385,15 +388,77 @@ func (p *pkgAtmosVendor) installer(tempDir *string, atmosConfig *schema.AtmosCon
385
388
return nil
386
389
}
387
390
388
- func handleDryRunInstall (p * pkgAtmosVendor ) tea.Msg {
389
- // Simulate the action
391
+ func handleDryRunInstall (p * pkgAtmosVendor , atmosConfig * schema.AtmosConfiguration ) tea.Msg {
392
+ log .Debug ("Entering dry-run flow for generic (non component/mixin) vendoring " , "package" , p .name )
393
+
394
+ if needsCustomDetection (p .uri ) {
395
+ log .Debug ("Custom detection required for URI" , "uri" , p .uri )
396
+ detector := & CustomGitDetector {AtmosConfig : * atmosConfig , source : "" }
397
+ _ , _ , err := detector .Detect (p .uri , "" )
398
+ if err != nil {
399
+ return installedPkgMsg {
400
+ err : fmt .Errorf ("dry-run: detection failed: %w" , err ),
401
+ name : p .name ,
402
+ }
403
+ }
404
+ } else {
405
+ log .Debug ("Skipping custom detection; URI already supported by go getter" , "uri" , p .uri )
406
+ }
407
+
390
408
time .Sleep (500 * time .Millisecond )
391
409
return installedPkgMsg {
392
410
err : nil ,
393
411
name : p .name ,
394
412
}
395
413
}
396
414
415
+ // Thie is a replica of getForce method from go getter library, had to make it as it is not exported.
416
+ // The idea is to call Detect method in dry run only for those links where go getter does this.
417
+ // Otherwise, Detect is run for every link being vendored which isn't correct.
418
+ func needsCustomDetection (src string ) bool {
419
+ _ , getSrc := "" , src
420
+ if idx := strings .Index (src , "::" ); idx >= 0 {
421
+ _ , getSrc = src [:idx ], src [idx + 2 :]
422
+ }
423
+
424
+ getSrc , _ = getter .SourceDirSubdir (getSrc )
425
+
426
+ if absPath , err := filepath .Abs (getSrc ); err == nil {
427
+ if u .FileExists (absPath ) {
428
+ return false
429
+ }
430
+ isDir , err := u .IsDirectory (absPath )
431
+ if err == nil && isDir {
432
+ return false
433
+ }
434
+ }
435
+
436
+ parsed , err := url .Parse (getSrc )
437
+ if err != nil || parsed .Scheme == "" {
438
+ return true
439
+ }
440
+
441
+ supportedSchemes := map [string ]bool {
442
+ "http" : true ,
443
+ "https" : true ,
444
+ "git" : true ,
445
+ "hg" : true ,
446
+ "s3" : true ,
447
+ "gcs" : true ,
448
+ "file" : true ,
449
+ "oci" : true ,
450
+ "ssh" : true ,
451
+ "git+ssh" : true ,
452
+ "git+https" : true ,
453
+ }
454
+
455
+ if _ , ok := supportedSchemes [parsed .Scheme ]; ok {
456
+ return false
457
+ }
458
+
459
+ return true
460
+ }
461
+
397
462
func createTempDir () (string , error ) {
398
463
// Create temp directory
399
464
tempDir , err := os .MkdirTemp ("" , "atmos-vendor" )
0 commit comments