Commit 60d4de5
workspace import-dir: default-exclude .git, .databricks, node_modules (#5118)
## Summary
`databricks workspace import-dir` walks the source tree and copies every
entry into the workspace verbatim — it has no awareness of `.gitignore`
or default exclusions. This change adds a name-based skip for `.git`,
`.databricks`, and `node_modules` directories during the walk.
`.gitignore` and other dotfiles at the root remain copied. If a user
explicitly passes `.git` (or any of the others) as the source root, that
root is still copied — the skip rule applies to entries encountered
during recursion.
## Motivation: align `import-dir` with `sync`'s existing defaults
`databricks sync` already hard-codes skips for the same two directories
that cause the most trouble:
- `libs/git/repository.go` — `// Always ignore root .git directory.`
adds `.git` to the default ignore rules unconditionally.
- `libs/git/view.go` (`SetupDefaults`) — `// Hard code .databricks
ignore pattern so that we never sync it (irrespective of .gitignore
patterns)`.
So `sync` and `import-dir` currently produce different workspace
contents for the same source tree: `sync` skips `.git/` and
`.databricks/`, `import-dir` copies them. This PR closes that gap for
`import-dir` so the two commands behave consistently.
`node_modules` is the one entry that goes beyond what `sync` does by
default. For any project with a typical `.gitignore`, `sync` would
already skip it via gitignore rules; `import-dir` ignores `.gitignore`
entirely, so adding it to the name-based skip list keeps the behavior
aligned with what users get from `sync`.
## Why this matters in practice
`databricks workspace import-dir` is commonly reached for as the inverse
of `databricks workspace export-dir`. Without these defaults, the
imported tree carries:
1. The local repo's `.git/` directory, including its config and history.
2. The local `.databricks/` bundle cache, which can clobber state that
bundle commands maintain remotely.
3. `node_modules/` for JS/TS projects — large, slow to upload, and
recreated by the runtime install step anyway.
The canonical answer is `databricks sync`, which respects `.gitignore`
and already excludes the first two by default. This PR is not a
substitute for `sync` — it just brings `import-dir`'s defaults into line
for users who reach for it anyway.
## Test plan
- [x] Unit tests covering: root `.git/` skipped, nested `.git/` skipped,
`.databricks/` skipped, `node_modules/` skipped, `.gitignore` file kept,
explicit `.git` root copied (escape hatch).
- [x] `go test ./cmd/workspace/workspace/` — pass
- [x] `golangci-lint run ./cmd/workspace/workspace/` — clean
- [ ] Existing integration `TestImportDir` — unchanged, no `.git` in its
testdata so behavior is identical.
This pull request and its description were written by Isaac.
---------
Co-authored-by: simon <4305831+simonfaltum@users.noreply.github.com>
Co-authored-by: simon <simon.faltum@databricks.com>1 parent 209fa87 commit 60d4de5
3 files changed
Lines changed: 186 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
26 | 42 | | |
27 | 43 | | |
28 | 44 | | |
| |||
48 | 64 | | |
49 | 65 | | |
50 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
51 | 76 | | |
52 | 77 | | |
53 | 78 | | |
| |||
117 | 142 | | |
118 | 143 | | |
119 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
120 | 149 | | |
121 | 150 | | |
122 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
0 commit comments