diff --git a/pkg/vendir/cmd/sync.go b/pkg/vendir/cmd/sync.go index 9673d49d..9262c5f8 100644 --- a/pkg/vendir/cmd/sync.go +++ b/pkg/vendir/cmd/sync.go @@ -88,7 +88,6 @@ func (o *SyncOptions) Run() error { } if len(dirs) > 0 { - conf, err = conf.Subset(dirOverrides(dirs).Paths()) if err != nil { return err diff --git a/pkg/vendir/config/lock_config.go b/pkg/vendir/config/lock_config.go index 29b945d0..c6a688b8 100644 --- a/pkg/vendir/config/lock_config.go +++ b/pkg/vendir/config/lock_config.go @@ -53,16 +53,6 @@ func NewLockConfigFromBytes(bs []byte) (LockConfig, error) { return config, nil } -func LockFileExists(path string) bool { - if _, err := os.Stat(path); err != nil { - if errors.Is(err, fs.ErrNotExist) { - return false - } - panic(fmt.Errorf("can not stat file '%v': %v", path, err)) - } - return true -} - func (c LockConfig) WriteToFile(path string) error { existingBytes, err := os.ReadFile(path) if err != nil && !errors.Is(err, fs.ErrNotExist) { @@ -138,7 +128,7 @@ func (c *LockConfig) Merge(other LockConfig) error { } } if !replaced { - c.AppendDirectory(dir) + c.Directories = append(c.Directories, dir) } } return nil @@ -160,7 +150,7 @@ func (c *LockConfig) ReplaceContents(path string, replaceCon LockDirectoryConten return false } -func (c LockConfig) AppendContents(path string, appendCon LockDirectoryContents) bool { +func (c *LockConfig) AppendContents(path string, appendCon LockDirectoryContents) bool { for i, dir := range c.Directories { if dir.Path == path { c.Directories[i].Contents = append(dir.Contents, appendCon) @@ -169,6 +159,3 @@ func (c LockConfig) AppendContents(path string, appendCon LockDirectoryContents) } return false } -func (c *LockConfig) AppendDirectory(dir LockDirectory) { - c.Directories = append(c.Directories, dir) -} diff --git a/pkg/vendir/config/lock_config_test.go b/pkg/vendir/config/lock_config_test.go index 68444355..0f0d5650 100644 --- a/pkg/vendir/config/lock_config_test.go +++ b/pkg/vendir/config/lock_config_test.go @@ -216,26 +216,41 @@ func TestLockConfig_AppendContents(t *testing.T) { }) } -func TestLockConfig_AppendDirectory(t *testing.T) { +func TestLockConfig_Merge(t *testing.T) { lockConfig := config.LockConfig{ - APIVersion: "vendir.k14s.io/v1alpha1", - Kind: "LockConfig", - Directories: []config.LockDirectory{}, - } - lockDirectory := config.LockDirectory{ - Contents: []config.LockDirectoryContents{ + APIVersion: "vendir.k14s.io/v1alpha1", + Kind: "LockConfig", + Directories: []config.LockDirectory{ { - Path: "gitpath", + Path: "gitpath-1", + Contents: []config.LockDirectoryContents{ + { + Path: "gitpath-1", + }, + }, }, + }, + } + lockConfig2 := config.LockConfig{ + APIVersion: "vendir.k14s.io/v1alpha1", + Kind: "LockConfig", + Directories: []config.LockDirectory{ { - Path: "dirpath", + Path: "gitpath-2", + Contents: []config.LockDirectoryContents{ + { + Path: "gitpath-2", + }, + }, }, }, } t.Run("append directory to config", func(t *testing.T) { - lockConfig.AppendDirectory(lockDirectory) - require.Equal(t, 1, len(lockConfig.Directories)) - require.Equal(t, 2, len(lockConfig.Directories[0].Contents)) - require.Equal(t, config.LockDirectoryContents{Path: "gitpath"}, lockConfig.Directories[0].Contents[0]) + lockConfig.Merge(lockConfig2) + require.Equal(t, 2, len(lockConfig.Directories)) + require.Equal(t, 1, len(lockConfig.Directories[0].Contents)) + require.Equal(t, 1, len(lockConfig.Directories[1].Contents)) + require.Equal(t, config.LockDirectoryContents{Path: "gitpath-1"}, lockConfig.Directories[0].Contents[0]) + require.Equal(t, config.LockDirectoryContents{Path: "gitpath-2"}, lockConfig.Directories[1].Contents[0]) }) }