Pass through paths argument to libs/sync (#1689)

## Changes

Requires #1684. 

## Tests

Ran the sync integration tests.
This commit is contained in:
Pieter Noordhuis 2024-08-19 17:41:02 +02:00 committed by GitHub
parent 7de7583b37
commit 2b8cbc31cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 13 deletions

View File

@ -28,10 +28,12 @@ func GetSyncOptions(ctx context.Context, rb bundle.ReadOnlyBundle) (*sync.SyncOp
}
opts := &sync.SyncOptions{
LocalPath: rb.BundleRoot(),
LocalRoot: rb.BundleRoot(),
Paths: []string{"."},
Include: includes,
Exclude: rb.Config().Sync.Exclude,
RemotePath: rb.Config().Workspace.FilePath,
Include: includes,
Exclude: rb.Config().Sync.Exclude,
Host: rb.WorkspaceClient().Config.Host,
Full: false,

View File

@ -47,7 +47,11 @@ func (f *syncFlags) syncOptionsFromArgs(cmd *cobra.Command, args []string) (*syn
}
opts := sync.SyncOptions{
LocalPath: vfs.MustNew(args[0]),
LocalRoot: vfs.MustNew(args[0]),
Paths: []string{"."},
Include: nil,
Exclude: nil,
RemotePath: args[1],
Full: f.full,
PollInterval: f.interval,

View File

@ -33,7 +33,7 @@ func TestSyncOptionsFromBundle(t *testing.T) {
f := syncFlags{}
opts, err := f.syncOptionsFromBundle(New(), []string{}, b)
require.NoError(t, err)
assert.Equal(t, tempDir, opts.LocalPath.Native())
assert.Equal(t, tempDir, opts.LocalRoot.Native())
assert.Equal(t, "/Users/jane@doe.com/path", opts.RemotePath)
assert.Equal(t, filepath.Join(tempDir, ".databricks", "bundle", "default"), opts.SnapshotBasePath)
assert.NotNil(t, opts.WorkspaceClient)
@ -59,6 +59,6 @@ func TestSyncOptionsFromArgs(t *testing.T) {
cmd.SetContext(root.SetWorkspaceClient(context.Background(), nil))
opts, err := f.syncOptionsFromArgs(cmd, []string{local, remote})
require.NoError(t, err)
assert.Equal(t, local, opts.LocalPath.Native())
assert.Equal(t, local, opts.LocalRoot.Native())
assert.Equal(t, remote, opts.RemotePath)
}

View File

@ -16,10 +16,12 @@ import (
)
type SyncOptions struct {
LocalPath vfs.Path
LocalRoot vfs.Path
Paths []string
Include []string
Exclude []string
RemotePath string
Include []string
Exclude []string
Full bool
@ -51,7 +53,7 @@ type Sync struct {
// New initializes and returns a new [Sync] instance.
func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
fileSet, err := git.NewFileSet(opts.LocalPath)
fileSet, err := git.NewFileSet(opts.LocalRoot, opts.Paths)
if err != nil {
return nil, err
}
@ -61,12 +63,12 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
return nil, err
}
includeFileSet, err := fileset.NewGlobSet(opts.LocalPath, opts.Include)
includeFileSet, err := fileset.NewGlobSet(opts.LocalRoot, opts.Include)
if err != nil {
return nil, err
}
excludeFileSet, err := fileset.NewGlobSet(opts.LocalPath, opts.Exclude)
excludeFileSet, err := fileset.NewGlobSet(opts.LocalRoot, opts.Exclude)
if err != nil {
return nil, err
}

View File

@ -57,7 +57,7 @@ func (s *Sync) applyMkdir(ctx context.Context, localName string) error {
func (s *Sync) applyPut(ctx context.Context, localName string) error {
s.notifyProgress(ctx, EventActionPut, localName, 0.0)
localFile, err := s.LocalPath.Open(localName)
localFile, err := s.LocalRoot.Open(localName)
if err != nil {
return err
}