Skip to content

feat: CLI writes git local config during context setup#40

Merged
guodong-sq merged 1 commit intomainfrom
parity/6-cli-git-config-writes
Mar 27, 2026
Merged

feat: CLI writes git local config during context setup#40
guodong-sq merged 1 commit intomainfrom
parity/6-cli-git-config-writes

Conversation

@guodong-sq
Copy link
Collaborator

@guodong-sq guodong-sq commented Mar 21, 2026

Summary

Bridges the gap between CLI and plugin config writing, completing the work started in #23 which introduced CLI reading of wt.* git local config keys.

PR #23 added wt_read_git_config so the CLI could detect contexts created by the plugin via wt.* keys in .git/config. However, the CLI's own wt context add only wrote .conf files — it never wrote wt.* keys back. This meant:

  • Plugin-created contexts had both .conf + git config (plugin writes both)
  • CLI-created contexts had only .conf (CLI never wrote git config)

The plugin's ContextService.detectContext() checks git config first (primary, faster path) and falls back to .conf files. CLI-created contexts always hit the fallback path.

This PR closes that asymmetry so both CLI and plugin produce identical config artifacts:

  • Add _wt_write_git_config helper to lib/wt-context-setup that writes all 7 wt.* keys matching the plugin's GitConfigHelper.writeConfig exactly
  • Call it after .conf file write in wt_setup_context
  • Handle empty metadataPatterns with --unset (matching plugin behavior)
  • Gracefully skip when no .git exists
  • Update stale comment in GitConfigHelper.kt that incorrectly stated only the plugin writes git config

Test plan

  • CLI unit tests pass: cd test && bats unit/wt-context-setup.bats (6 new tests)
  • All 7 git config keys written with correct values
  • Round-trip: wt_read_git_config reads back all written keys
  • No-.git case warns and returns 0
  • ShellCheck passes on lib/wt-context-setup

🤖 Generated with Claude Code

Copy link
Collaborator Author

@guodong-sq guodong-sq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bezhermoso Heads up — this PR builds on your work in #23 (local-context-first config via git local config).

PR #23 added the CLI read path for wt.* git config keys so the CLI could detect plugin-created contexts. This PR adds the corresponding write path so that wt context add also writes those same 7 wt.* keys to .git/config, not just to .conf files.

This bridges two gaps:

  1. CLI read ↔ write parity: the CLI can now both read and produce wt.* git config keys
  2. CLI ↔ plugin parity: contexts created from either surface now produce identical config artifacts (both .conf + git local config), so the plugin's primary detection path (GitConfigHelper.readConfig) works for CLI-created contexts too — no need to fall back to .conf file matching

The key names and semantics match GitConfigHelper.writeConfig exactly. Would appreciate your review since you added the cli config detection layer.

fi
info "Writing git local config..."
git -C "$repo_root" config --local wt.enabled true
git -C "$repo_root" config --local wt.contextName "$context_name"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: what does the repo's awareness of which context it belongs to achieve?

Copy link
Collaborator Author

@guodong-sq guodong-sq Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently It's more for the UI of the plugin.

I also had the idea of having a repo provisioned by multiple context, so that even within the repo you can have multiple symlinks that are active, but that would require more metadata either in the repo's git config or .git/wt/ of each worktree

@guodong-sq guodong-sq force-pushed the parity/6-cli-git-config-writes branch from 7d476cd to 535e1dd Compare March 27, 2026 04:17
Make wt context add write wt.* keys to .git/config, matching what the
plugin's GitConfigHelper.writeConfig does. This eliminates the
asymmetry where CLI-created contexts lack the higher-priority git
config source.

Changes:
- Add _wt_write_git_config helper to lib/wt-context-setup that writes
  all 7 wt.* keys matching plugin's GitConfigHelper.writeConfig exactly
- Call it after .conf file write in wt_setup_context
- Handle empty metadataPatterns with --unset (matching plugin behavior)
- Gracefully skip when no .git exists
- Update stale comment in GitConfigHelper.kt that incorrectly stated
  only the plugin writes git config

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@guodong-sq guodong-sq force-pushed the parity/6-cli-git-config-writes branch from 535e1dd to 674aafe Compare March 27, 2026 04:27
@guodong-sq guodong-sq merged commit 90eb0a9 into main Mar 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants