GitVeilVS Code extension that keeps local changes to a Git repository outside the normal versioning flow, using three native Git mechanisms:
The extension shows everything in a single view, Hidden Files, in the Activity Bar. You can enable or suspend filters without losing their configuration, and it offers protected Pull, Checkout and Switch Branch operations, which preserve local changes before the Git operation runs. Contents
Requirements
Development
To test in VS Code: open the project folder, run Scripts
UsageSidebarThe GitVeil icon opens the container with a single view, Hidden Files. It lists the repositories and the hidden files in each one. You do not choose the mechanism: Hide file decides how to hide (see How GitVeil chooses). Each item shows an icon, the mechanism used and a state description:
When a managed file has local changes that Git cannot carry over to another branch, the view shows a warning under the repository: Switching to X would be blocked by local changes in: Y. The warning is computed from Git's state and does not intercept anything. It is refreshed when the window gains focus, when With GitLens installed, each local branch listed in the GitLens view has a Switch branch with GitVeil button, which runs the protected switch without opening another picker. This integration reads GitLens' internal item structure, which is not a public API: if GitLens changes, the button shows an error instead of acting. Remote branches are not supported. When a branch switch made by VS Code's built-in Git (SCM or command palette) fails and there are known blocks, GitVeil shows a notification with the Switch with GitVeil button, which runs the protected switch. Detection is by inference: VS Code does not report the error or the target branch, so GitVeil compares HEAD before and after the checkout. There are false positives, such as In the view toolbar: Refresh, Hide file, Add exclude pattern, Reveal all files. On repositories: enable/suspend all filters, protected Pull, protected Checkout, protected Switch Branch and recover an interrupted operation. On items: enable/suspend, open file, reveal in Explorer, Reveal file and show status. Context menusRight-click a file or folder in the Explorer, the editor tab, the text editor or a file in Source Control. The GitVeil items appear directly in the menu, and only where they apply:
Multiple selection is supported. The repository that owns each file is identified automatically, including in multi-root workspaces and nested repositories. Adding from the extensionThe Hide file button lets you pick files or folders with the visual picker, or type a relative path with real-time validation. You do not need to choose the mechanism: GitVeil decides it (see below). Glob patterns are added with the Add exclude pattern button. How GitVeil chooses
Assume Unchanged is not part of this choice. It is still read and removed for earlier filters, but it is not offered for new files. Reveal file and Reveal all files remove only the rule or flag that GitVeil created. No file content is changed. If the repository is active, the filter is applied immediately. If it is suspended, the item is only recorded for the next activation. The three mechanismsExclude (
|
| Setting | Default | Effect |
|---|---|---|
gitveil.enabled |
true |
When false, the view shows only the deactivation notice. The commands remain available. |
gitveil.autoRefresh |
true |
Refreshes the view when the window gains focus and when .git/index or .git/info/exclude change. |
gitveil.showNotifications |
true |
Shows informational notifications (errors are always shown). |
gitveil.defaultFilterType |
exclude |
Mechanism preselected when adding files. |
gitveil.restoreFiltersAfterOperation |
true |
After a successful protected operation, reapplies the repository configuration to fix divergences. |
gitveil.showExternalFlags |
true |
Shows flags and exclude lines created outside GitVeil. |
Interface preferences are global, but the state of each repository (active/suspended and items) is independent and stored in the repository itself.
Security guarantees
- Never runs destructive commands without consent: no
reset --hard,checkout --forceorclean -fd. - Never stashes the whole project: the stash is always restricted to the registered paths with changes.
- Never removes the stash before confirming the restoration.
- Never treats a Git failure as success: exit codes are checked and stderr is preserved.
- Git processes run without a shell (
execFilewith argv), which prevents command injection with file names containing spaces, accents or special characters. - Never changes files outside the selected repository. Paths that escape the root (
.., absolute, inside.git) are rejected. - Persisted data and Git output are treated as untrusted input and validated. A corrupted record or journal raises an error and is not silently discarded, so that no data is lost.
- Concurrent Git operations on the same repository are serialized within the extension.
Real API limitations
This section matters. Read it before relying on GitVeil as your main workflow.
- A checkout made outside GitVeil is not protected. The view's warning helps anticipate the block, but it does not prevent the switch. Protection for external checkouts (an adapter via
git.path) is planned in issue #1, with a setting to turn it on or off. - There is no public API to intercept native Git Pull, Checkout or Switch. The extension does not use monkey patching or override internal commands. Therefore, operations run from the native Pull button, the terminal, another extension or Git's own UI do not go through the protection. To have protection, use the GitVeil: Protected Pull / Checkout / Switch Branch commands.
- Items in the Git menus (Source Control) are limited. The SCM resource menu is used for the submenu commands, but the extension cannot add entries inside the native Git menu.
- Context menus depend on the state the extension can compute, not on live Git checks. VS Code only evaluates
whenclauses against context keys published by the extension. GitVeil publishes the list of paths Git tracks or does not ignore, and the list of paths it manages, and refreshes them on index, exclude and.gitignorechanges, on branch switches and on view refresh. A rule change made in a way GitVeil does not watch (for example, a global ignore file outside the workspace) can leave the menu out of date until the next refresh. The commands still check the real Git state before acting, so a stale menu does not change files. - Assume Unchanged is not protection and is no longer offered for new files. This is a limitation of Git itself: Git may overwrite the file during Pull or Checkout.
info/excludeis shared between worktrees. A pattern registered in one worktree also appears in the others, because Git uses the same file. Paths are anchored, but the effect is shared. The extension keeps the union of all worktrees so it does not erase another worktree's entries.- Concurrency between VS Code windows. Serialization happens inside one instance of the extension. Two windows operating on the same repository at the same time are not coordinated by a file lock.
stash push --pathspec-from-file. It depends on a Git version that supports the option. The exact minimum version has not been verified; the project was tested only with Git 2.56.- Ignored and untracked files are not stashed. They are protected by a backup copy verified by size, not by automatic restoration. The backup lives in
.git/gitveil/backups/and is never deleted by the extension. - Git operations can be refused. When there are protected changes, the extension uses stash; if Git itself refuses the operation, the extension shows the error and restores everything, without bypassing the refusal.
- Permissions on Windows. Permission errors are detected from Git's messages (
Permission denied,Access is denied). There is no automated test simulating permissions, becausechmoddoes not apply to Windows. - Content conflicts in managed files are resolved in favor of the local version. This is a deliberate choice, so that local customization does not block a branch switch or get revealed by conflict markers. The consequence is that the remote change does not appear in the worktree while the file is hidden. It remains available in the index and HEAD. The notification lists the files where the local version prevailed: check them against the target branch if its changes matter, because the merge is not done in the worktree.
- Renames that take a file out of a hidden folder are reported. The warning shows the old and new path. The file is visible at the new path and must be hidden again if needed.
- Symbolic links and Sparse Checkout have not been tested. The extension's behavior with symlinks and sparse checkout is not verified by automated tests.
- CRLF line endings are preserved byte for byte with
core.autocrlf=falseandcore.autocrlf=true, in the conflict cases tested.
Architecture
The extension follows Clean Architecture, with the dependency rule pointing inward:
src/
├── domain/ # entities, value objects, rules and state machine (no vscode, Node or Git)
├── application/ # use cases, ports (interfaces) and orchestration services
│ ├── ports/ # GitInspectionPort, GitMutationPort, RegistryPort, JournalPort, ...
│ ├── services/ # FilterEnforcer, RepositoryStore, ProtectionAssessor, RepositoryLock, ...
│ └── usecases/ # AddFilter, RemoveFilter, ProtectedOperation, RecoverTransaction, ...
├── infrastructure/ # adapters: Git CLI, JSON persistence, info/exclude, backups, clock/ids
├── composition/ # composition root (createServices): wires adapters and use cases
├── presentation/ # TreeView, commands, dialogs, notifications, i18n (the only layer that imports vscode)
└── extension.ts # activation: connects presentation and composition
Relevant design points:
- Pure domain:
FilterTarget,FilterEntry,RepositoryFilters,TransactionandRelativePathare discriminated, immutable types. States such asFilterStatusandTransaction.stageare validated by a transition table. - Small ports (ISP): Git querying, Git mutation, registry, journal, exclude file, file system and user decisions are separate interfaces.
- Presentation does not decide rules: commands resolve targets from the arguments (Uri,
SourceControlResourceState, TreeView nodes, multi-selection arrays) and delegate to use cases. - Composition without a DI framework:
createServiceswires everything through constructors. Integration tests use the same composition with real adapters. - Error messages are typed codes (
UseCaseFailureCode). The message map is a typedRecord, so a new code without a translation does not compile.
Persistence
| Data | Location | Shared between worktrees? |
|---|---|---|
| Filter registry (repositories, entries, mechanism, suspension, ownership) | <git-common-dir>/gitveil/registry.json |
Yes (one file per repository) |
| Managed block of the exclude file | <git-common-dir>/info/exclude |
Yes (Git's behavior) |
| Journal of an in-progress protected operation | <git-dir>/gitveil-transaction.json |
No (per worktree) |
| Backups of untracked/ignored files | <git-dir>/gitveil/backups/<transaction>/ |
No |
| Index flags | each worktree's index | No |
Persistence lives inside .git, so it survives restarts, closing and reopening projects, branch switches and window reloads. Writes are atomic (temporary file + rename).
Divergences between the registry and the real Git state are detected on every refresh and shown as Divergent. The extension does not overwrite external changes automatically.
Internationalization
- Code messages use
vscode.l10n.t(...)with literals (required for extraction). - Manifest:
package.nls.json(English, base) andpackage.nls.pt-br.json. - Extension messages:
l10n/bundle.l10n.json(English, base) andl10n/bundle.l10n.pt-br.json. - The language is detected automatically by VS Code; English is the fallback.
Tests in tests/i18n/localization.test.ts verify:
- that
pt-brhas exactly the same keys as the base; - that the placeholders
{0},{1}… are the same in the translation; - that every
vscode.l10n.t('…')call in the source exists in the bundle (the check uses the TypeScript API, not regex); - that every
%key%inpackage.jsonexists in both manifest files; - that a text identical to English appears only for technical terms explicitly listed.
To add a language: copy bundle.l10n.pt-br.json and package.nls.pt-br.json with the new language suffix and translate them. No business logic changes.
Tests and quality
pnpm run test
| Suite | Files | What it covers |
|---|---|---|
| Domain unit tests | tests/unit/domain/ |
Path normalization, exclude escaping, derived status, aggregate invariants, transaction state machine, directory split, menu candidate rules. |
| Infrastructure unit tests | tests/unit/infrastructure/ |
Decoding of the ls-files -v letters (H, S, h, s), status/stash/worktree parsers, validation of corrupted registry and journal. |
| Presentation unit tests | tests/unit/presentation/ |
Menu target resolution (Uri, SCM, arrays), owning repository with nesting, TreeView grouping, folder-first ordering, placeholder for fully hidden folders. |
| Integration (real Git) | tests/integration/filters.integration.test.ts |
The three mechanisms in temporary repositories; exclude preserving external lines; suspension and resumption; external flags; flag ownership; paths with spaces, accents and globs; persistence across instances; worktrees. |
| Integration (real Git) | tests/integration/protected-operations.integration.test.ts |
Pull without changes (no stash); restricted stash with flag restoration; staged and unstaged preserved on checkout; operation failure with full restoration; conflict on reapplication with stash kept; cancellation; "continue without stash" with confirmation; merge in progress; backup of untracked files; dirty editor; recovery of an interrupted transaction; protected branch switch. |
| Reapplication of divergent flags (real Git) | tests/integration/reapply-divergent.integration.test.ts |
Reapplication of Skip Worktree and Assume Unchanged after external flag removal; staged file not hidden; suspended entries and disabled repository ignored; pending transaction; idempotence. |
| Conflict recovery (real Git) | tests/integration/conflict-recovery.integration.test.ts |
Per-path revert with fingerprint, refusal after a later edit, reapplication, conflict markers, injected failures (restoration, flags, stash removal) with recovery on the second attempt, idempotence, user stash preserved, pending backup, persistence after restart, isolation between repositories. |
| Revealing inside a hidden folder (real Git) | tests/integration/reveal-within-directory.integration.test.ts |
Splitting a hidden folder into children when a file is revealed, and re-hiding it. |
| Menu candidates (real Git) | tests/integration/menu-candidates.integration.test.ts |
Candidate list across nested .gitignore, info/exclude, core.excludesFile, ignored directories and negations, tracked files matching a pattern, third-party flags, branch switches, worktrees and multiple repositories. |
| i18n | tests/i18n/localization.test.ts |
Integrity of translations and manifests. |
Integration tests create real Git repositories and remotes in temporary directories and remove them at the end. They require git on the PATH.
Current coverage: pnpm run test:coverage generates the report. The src/extension.ts layer is excluded. The presentation layer (TreeView and commands) has no automated Extension Host test, because that requires downloading VS Code. It has not been validated in VS Code by an automated test, so the visual behavior of the menus, the tree and the placeholder should be checked manually.
Mandatory gate before any delivery: pnpm run check.
Packaging (.vsix), CI and release
pnpm run package # generates gitveil.vsix (the project has no runtime dependencies)
.vscodeignore includes out/, l10n/, package.nls*.json and media/, and excludes sources, tests, configs and pnpm-lock.yaml.
The extension is published as brederdev.gitveil under the MIT license (see LICENSE). The package.json declares "private": true to prevent accidental publication to npm.
Workflows:
.github/workflows/ci.ymlruns on every push tomainand on every pull request: install with--frozen-lockfile --engine-strict, lint, typecheck, i18n tests, full tests and build..github/workflows/release.ymlruns when a tagvX.Y.Zis pushed. It runs the quality gate, packages the.vsix, checks that the tag matches thepackage.jsonversion, publishes to the VS Marketplace with theVSCE_PATsecret, and only then creates the GitHub Release with the.vsixattached.
To publish a new version: update version in package.json, commit, and push a tag with the same number.
Not implemented
- Bulk actions per group (enable/suspend all items of a mechanism). The action is optional in the requirement; today it exists per repository and per item.
- Integration with the native Git menu (API limitation, see above).
- Extension Host tests (they require downloading VS Code).
- Automated tests for permission failures (not reliably reproducible on Windows).
- Tests for a file removed after being added and for multiple repositories in the same workspace. The logic exists, but there is no dedicated integration test for these two scenarios.
- Coordination between VS Code windows (see limitations).