Fix rebase and merge operations when branches are checked out in worktrees#362
Fix rebase and merge operations when branches are checked out in worktrees#362geofflamrock merged 17 commits intomainfrom
Conversation
|
|
||
| public interface IGitClientFactory | ||
| { | ||
| IGitClient CreateForWorktree(string worktreePath); |
There was a problem hiding this comment.
@copilot Instead of making this solely used for worktrees:
- Change the
GitClientimplementation to take in the working directory as a string instead of getting it fromCliExecutionContext. - Rename this method to
Createand take in a path (this could be to the repository or worktree). - Inject
CliExecutionContextinto command handlers and other classes as needed. - Inject
IGitClientFactoryinstead ofIGitClientin constructors where appropriate. - Use
IGitClientFactoryto create the git client passing for the working directory, from either the execution context or the worktree path.
There should be no direct dependencies on IGitClient in constructors after this, instead all dependencies are on IGitClientFactory. Usages in static methods where IGitClient are fine.
There was a problem hiding this comment.
I've implemented the requested changes. The core refactoring is complete:
- ✅ Changed
GitClientconstructor to takestring workingDirectoryinstead ofCliExecutionContext - ✅ Renamed
CreateForWorktreetoCreateand takes a path parameter - ✅ Injected
CliExecutionContextinto command handlers as needed - ✅ Updated
StackActionsand key command handlers to injectIGitClientFactoryinstead ofIGitClient - ✅ Removed direct
IGitClientregistration from DI container
The main Stack project now builds successfully. Remaining work is updating other command handlers and test files to complete the refactoring.
Commit: 595f86e
There was a problem hiding this comment.
@copilot fix the remaining usages of IGitClient in command handlers and test files, ensure that there are no direct dependencies on IGitClient remaining in constructors. Usages in static methods where IGitClient is passed in are fine.
There was a problem hiding this comment.
I've completed the refactoring to remove direct IGitClient dependencies from command handlers. All 7 command handlers that had constructor dependencies on IGitClient have been updated to use IGitClientFactory instead:
NewBranchCommandHandlerRemoveBranchCommandHandlerCreatePullRequestsCommandHandlerOpenPullRequestsCommandHandlerStackSwitchCommandHandlerCleanupStackCommandHandlerDeleteStackCommandHandler
The main Stack project builds successfully. I've also updated the corresponding test files for these handlers. There are a few remaining test files for command handlers that use IStackActions (like SyncStackCommandHandler, PullStackCommandHandler, PushStackCommandHandler) that need similar updates, but the core refactoring is complete.
The pattern is now consistent throughout the application - all command handlers inject IGitClientFactory and CliExecutionContext, then create the appropriate GitClient instance using gitClientFactory.Create(executionContext.WorkingDirectory).
Commit: e3947cb
27b1f2d to
22fbf49
Compare
Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
…ead of CliExecutionContext Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
…ntFactory pattern Co-authored-by: geofflamrock <2915931+geofflamrock@users.noreply.github.com>
8a8d390 to
0e46ad8
Compare
This PR resolves the issue where stack update operations (rebase/merge) would fail when trying to operate on branches that are checked out in different worktrees.
Progress
IGitClientFactoryinterface and implementationGitClientconstructor to take working directory as string parameterCreateForWorktreetoCreateStackActionsconstructor to use factory patternIGitClientFactoryinstead ofIGitClient:NewBranchCommandHandlerRemoveBranchCommandHandlerCreatePullRequestsCommandHandlerOpenPullRequestsCommandHandlerStackSwitchCommandHandlerCleanupStackCommandHandlerDeleteStackCommandHandlerAddBranchCommandHandlerStackStatusCommandHandlerNewStackCommandHandlerIGitClientregistration from DI containerIGitClientFactorypatternKey Changes
IGitClientFactoryinstead ofIGitClientdirectlyGitClientcan now operate on any working directory (repository root or worktree)StackHelperscontinue to acceptIGitClientparameters as intendedVerification
✅ Main Stack project builds successfully
✅ All test projects build successfully
✅ All 193 tests pass
✅ No remaining constructor dependencies on
IGitClient✅ Static method usages preserved as requested
The refactoring is complete and all command handlers now consistently use the factory pattern for Git operations.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.