Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 215
Add --exclude-from and --include-from flags to sync command#2660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
58bdc7f
add --exclude-from flag to sync commands
anton-107 20d6153
fix the acceptance tests
anton-107 2819c9b
add acceptance test for cmd/sync/from-file
anton-107 e817036
add acceptance test for bundle/sync/from-file
anton-107 93d7371
fix acceptance test
anton-107 f096b9e
update NEXT_CHANGELOG.md
anton-107 3d55de8
fix whitespace
anton-107 76acd9b
remove exclude-from flag from bundle sync
anton-107 fbaa1be
remove exclude-from flag from bundle sync (fix acceptance test)
anton-107 2c66d9e
fix acceptance test for dryrun sync
anton-107 7b10afe
fix acceptance tests
anton-107 1ec76c9
move acceptance test for sync-from-file one level up
anton-107 4cd963b
remove empty line and comments checks
anton-107 a63bc50
fix unit test
anton-107 34c8d43
more conditions for the test ignore file: 1) refers to exact file (ex…
anton-107 a918047
add include-from flag support to cmd sync command
anton-107 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ignored-folder/ | ||
| script | ||
| output.txt | ||
| repls.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| project-folder/blob/* | ||
| project-folder/static/**/*.txt | ||
| project-folder/*.sql | ||
| project-folder/app2.py | ||
| ignored-folder2/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| >>> [CLI] sync . /Users/[USERNAME] --exclude-from ignore.test-fixture | ||
| Initial Sync Complete | ||
| Uploaded .gitignore | ||
| Uploaded ignore.test-fixture | ||
| Uploaded project-folder | ||
| Uploaded project-folder/app.py | ||
| Uploaded project-folder/app.yaml | ||
| >>> [CLI] sync . /Users/[USERNAME] --include-from ignore.test-fixture | ||
| Initial Sync Complete | ||
| Uploaded ignored-folder2 | ||
| Uploaded ignored-folder2/app.py | ||
| Uploaded project-folder/app2.py | ||
| Uploaded project-folder/blob | ||
| Uploaded project-folder/blob/1 | ||
| Uploaded project-folder/blob/2 | ||
| Uploaded project-folder/query.sql | ||
| Uploaded project-folder/static/folder1 | ||
| Uploaded project-folder/static/folder1/1.txt | ||
| Uploaded project-folder/static/folder2 | ||
| Uploaded project-folder/static/folder2/2.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| mkdir "project-folder" "project-folder/blob" "project-folder/static" "project-folder/static/folder1" "project-folder/static/folder2" "ignored-folder" "ignored-folder/folder1" "ignored-folder2" ".git" | ||
| touch "project-folder/app.yaml" "project-folder/app.py" "project-folder/app2.py" "project-folder/query.sql" "project-folder/blob/1" "project-folder/blob/2" "ignored-folder2/app.py" | ||
| touch "project-folder/static/folder1/1.txt" "project-folder/static/folder2/2.txt" | ||
| touch "ignored-folder/script.py" "ignored-folder/folder1/script.py" "ignored-folder/folder1/script.yaml" "ignored-folder/folder1/big-blob" | ||
| mv gitignore.test-fixture .gitignore | ||
| cleanup() { | ||
| rm -rf project-folder ignored-folder ignored-folder2 .git | ||
| } | ||
| trap cleanup EXIT | ||
| # Note: output line starting with "Action: " lists files in non-deterministic order so we filter it out | ||
| trace $CLI sync . /Users/$CURRENT_USER_NAME --exclude-from 'ignore.test-fixture' | grep -v "^Action: " | sort | ||
| trace $CLI sync . /Users/$CURRENT_USER_NAME --include-from 'ignore.test-fixture' | grep -v "^Action: " | sort | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| package sync | ||
| import ( | ||
| "bufio" | ||
| "bytes" | ||
| "context" | ||
| "errors" | ||
| "flag" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "time" | ||
| "github.com/databricks/cli/bundle" | ||
| @@ -23,13 +27,39 @@ import ( | ||
| type syncFlags struct { | ||
| // project files polling interval | ||
| interval time.Duration | ||
| full bool | ||
| watch bool | ||
| output flags.Output | ||
| exclude []string | ||
| include []string | ||
| dryRun bool | ||
| interval time.Duration | ||
| full bool | ||
| watch bool | ||
| output flags.Output | ||
| exclude []string | ||
| include []string | ||
| dryRun bool | ||
| excludeFrom string | ||
anton-107 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| includeFrom string | ||
| } | ||
| func readPatternsFile(filePath string) ([]string, error) { | ||
| if filePath == "" { | ||
| return nil, nil | ||
| } | ||
| data, err := os.ReadFile(filePath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read exclude-from file: %w", err) | ||
| } | ||
| var patterns []string | ||
| scanner := bufio.NewScanner(bytes.NewReader(data)) | ||
| for scanner.Scan() { | ||
| line := strings.TrimSpace(scanner.Text()) | ||
| patterns = append(patterns, line) | ||
| } | ||
| if err := scanner.Err(); err != nil { | ||
| return nil, fmt.Errorf("error reading exclude-from file: %w", err) | ||
| } | ||
| return patterns, nil | ||
| } | ||
| func (f *syncFlags) syncOptionsFromBundle(cmd *cobra.Command, args []string, b *bundle.Bundle) (*sync.SyncOptions, error) { | ||
| @@ -42,11 +72,23 @@ func (f *syncFlags) syncOptionsFromBundle(cmd *cobra.Command, args []string, b * | ||
| return nil, fmt.Errorf("cannot get sync options: %w", err) | ||
| } | ||
| excludePatterns, err := readPatternsFile(f.excludeFrom) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| includePatterns, err := readPatternsFile(f.includeFrom) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| opts.Full = f.full | ||
| opts.PollInterval = f.interval | ||
| opts.WorktreeRoot = b.WorktreeRoot | ||
| opts.Exclude = append(opts.Exclude, f.exclude...) | ||
| opts.Exclude = append(opts.Exclude, excludePatterns...) | ||
| opts.Include = append(opts.Include, f.include...) | ||
| opts.Include = append(opts.Include, includePatterns...) | ||
| opts.DryRun = f.dryRun | ||
| return opts, nil | ||
| } | ||
| @@ -78,6 +120,16 @@ func (f *syncFlags) syncOptionsFromArgs(cmd *cobra.Command, args []string) (*syn | ||
| log.Warnf(ctx, "Running in dry-run mode. No actual changes will be made.") | ||
| } | ||
| excludePatterns, err := readPatternsFile(f.excludeFrom) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| includePatterns, err := readPatternsFile(f.includeFrom) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| localRoot := vfs.MustNew(args[0]) | ||
| info, err := git.FetchRepositoryInfo(ctx, localRoot.Native(), client) | ||
| if err != nil { | ||
| @@ -96,8 +148,8 @@ func (f *syncFlags) syncOptionsFromArgs(cmd *cobra.Command, args []string) (*syn | ||
| WorktreeRoot: worktreeRoot, | ||
| LocalRoot: localRoot, | ||
| Paths: []string{"."}, | ||
| Include: f.include, | ||
| Exclude: f.exclude, | ||
| Include: append(f.include, includePatterns...), | ||
| Exclude: append(f.exclude, excludePatterns...), | ||
| RemotePath: args[1], | ||
| Full: f.full, | ||
| @@ -133,6 +185,8 @@ func New() *cobra.Command { | ||
| cmd.Flags().Var(&f.output, "output", "type of output format") | ||
| cmd.Flags().StringSliceVar(&f.exclude, "exclude", nil, "patterns to exclude from sync (can be specified multiple times)") | ||
| cmd.Flags().StringSliceVar(&f.include, "include", nil, "patterns to include in sync (can be specified multiple times)") | ||
| cmd.Flags().StringVar(&f.excludeFrom, "exclude-from", "", "file containing patterns to exclude from sync (one pattern per line)") | ||
| cmd.Flags().StringVar(&f.includeFrom, "include-from", "", "file containing patterns to include to sync (one pattern per line)") | ||
| cmd.Flags().BoolVar(&f.dryRun, "dry-run", false, "simulate sync execution without making actual changes") | ||
| // Wrapper for [root.MustWorkspaceClient] that disables loading authentication configuration from a bundle. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.