Skip to content

Commit

Permalink
Pass through paths argument to libs/sync (#1689)
Browse files Browse the repository at this point in the history
## Changes

Requires #1684. 

## Tests

Ran the sync integration tests.
  • Loading branch information
pietern authored Aug 19, 2024
1 parent 7de7583 commit 2b8cbc3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
8 changes: 5 additions & 3 deletions bundle/deploy/files/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion cmd/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cmd/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
14 changes: 8 additions & 6 deletions libs/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion libs/sync/watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2b8cbc3

Please sign in to comment.