In the DSH workflow, the branch pills of git-related plugins (such as @linxin666/dsh-client-ui-git-graph) depend on the workspace directory being a git repository. If git has not been initialized in the directory, the related features become unavailable. dsh-auto-git solves this problem by listening to workspace registration events and automatically running git init for each new workspace, making git capabilities available in all workspaces.
Core Features¶
- Automatic initialization: Listens to the
domain/changedevent and runsgit init -b mainin the new workspace root directory. - Initial commit: By default, creates an empty commit (
git commit --allow-empty) to ensure HEAD is not in a detached state, so branch pills can display the branch name normally. - Idempotent handling: Within the same host process, the same path is processed only once; if the repository already exists, it is skipped.
- Zero runtime dependencies: Uses only Node.js native modules (
node:child_process/node:fs/promises) with no extra dependencies. - No nesting: Initialization is skipped if the parent directory is already a repository or the current directory is a git worktree checkout.
Installation and Activation¶
Install from GitHub:
dsh plugin --profile web add github:zhitiaojun/dsh-auto-git
For local development, use link: to point to a checkout:
dsh plugin --profile web add link:D:/Project/1/dsh-auto-git
Important: After installation, you must restart dsh web for it to be loaded into the host process.
Configuration¶
After installation, the profile’s bundle patch (cordis.patch.yml) provides the configuration lines. The available fields are as follows:
| Field | Default | Meaning |
|---|---|---|
enabled |
true |
Master switch; when false, the plugin does nothing |
branch |
main |
Initial branch name |
initialCommit |
true |
Whether to add an empty commit (if disabled, the branch name of a new repository may show as detached) |
sweepExisting |
true |
Whether to also process workspaces registered before startup (by default, all currently registered workspaces that are not yet repositories are processed) |
timeoutMs |
30000 |
Timeout for each git command |
Verification¶
- Run the core tests:
Execute in the repository root directory:
node D:\Project\1\dsh-auto-git\test\smoke.mjs
- Check the logs:
View the installation log:
~\.dsh\profiles\web\.dsh-market\log.ndjson
There should be an `install` record for this package and a subsequent `restart` record.
- Check the Git status:
Execute in any newly registered DSH workspace directory:
git -C <新目录> log --oneline
You should be able to see `chore: initial commit`.
Notes¶
sweepExistingbehavior: The default istrue. After installation and restart, all currently registered workspaces that are not yet repositories will be initialized. If you only want to affect workspaces created afterward, setsweepExistingtofalse.- Uninstall rollback: Uninstalling the plugin does not roll back repositories that have already been created.
- Dependency version: Requires DSH version
>=0.1.5-rc.1. - Runtime environment: A pure host-side plugin with no browser-side contribution code.
Summary¶
dsh-auto-git solves the issue of git-related plugins being unavailable in non-repository directories by automatically initializing a git repository when a DSH workspace is registered. It is a lightweight host-side plugin suitable for DSH workflow environments that require unified git management.
For more details and source code, visit: GitHub | Plugin directory