Skip to content

feat: Add ability to configure the git worktree path via the configuration file #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nbperry
Copy link

@nbperry nbperry commented Jun 11, 2025

This resolves #86

This enables users to set via worktree_pattern in their config file where they want their worktrees to be created. Please bear with me around any code things as this is the first time I have ever written Go. So if there are better ways to do things let me know. I also had claude code help me a bit with this since I am not super familiar with Go and they could have steered me wrong as well. Any suggestions would be greatly appreciated.

Example demos below.

Below is an example using a more central worktree location "worktree_pattern": "~/repos/worktree/{issue_number}-{title}"

Screen.Recording.2025-06-11.at.11.35.24.AM.mov

Below is an example using "worktree_pattern": "{repo_root}/worktree/{issue_number}-{title}" in config file

Screen.Recording.2025-06-11.at.11.30.39.AM.mov

I believe this sort of handles the idea of #90 as well I suspect. I could be misunderstanding the full Idea of that issue so let me know if not.

@nbperry
Copy link
Author

nbperry commented Jun 11, 2025

cc @bjcoombs some feature requests that you had that I also wanted.

@mufeez-amjad & @jayshrivastava I cannot mark reviewers but would one of you be willing to give this a review and let me know what it would take to get something like this merged?

@mufeez-amjad mufeez-amjad self-requested a review June 11, 2025 16:02
@nbperry
Copy link
Author

nbperry commented Jun 20, 2025

Hi @mufeez-amjad is there anything I can do to help push this along?

@mufeez-amjad
Copy link
Member

@nbperry do you mind rebasing your changes on the latest main and signing our CLA? Will give it a review after that – thanks!

Copy link

github-actions bot commented Jun 20, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@nbperry
Copy link
Author

nbperry commented Jun 20, 2025

I have read the CLA Document and I hereby sign the CLA

@nbperry
Copy link
Author

nbperry commented Jun 23, 2025

@mufeez-amjad signed the CLA so we should be good on that side of things.

@nbperry
Copy link
Author

nbperry commented Jul 8, 2025

Checking in again @mufeez-amjad, incase there is anything I can do to help push this along.

@@ -57,6 +63,12 @@ func (g *GitWorktree) SetupNewWorktree() error {
return fmt.Errorf("failed to create worktrees directory: %w", err)
}

// Ensure the parent directory of the worktree path exists
worktreeParent := filepath.Dir(g.worktreePath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please explain why this is needed?

Copy link
Author

Choose a reason for hiding this comment

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

Well git worktree add requires a directory to create worktree. Since the SetupNewWorktree and SetupFromExistingBranch are separately called in the Setup we need do do this in both of them.

So this checks for the directory and creates it if it does not exist to then be able to perform the git worktree add.

}

// parseWorktreePattern substitutes variables in the pattern with actual values
func parseWorktreePattern(pattern string, vars PatternVariables) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can usetext/template to do this replacing operation.

Copy link
Author

@nbperry nbperry Aug 7, 2025

Choose a reason for hiding this comment

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

Ah I will update to this approach,I am pretty new to go so still learning alot of things 😅

Copy link
Author

Choose a reason for hiding this comment

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

Updated via 5908ac6

// WorktreePattern is the pattern used to determine worktree location.
// Supports variables: {repo_root}, {repo_name}, {issue_number}, {title}, {timestamp}
// Example: "{repo_root}/worktree/{issue_number}-{title}"
WorktreePattern string `json:"worktree_pattern"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be good to make this apply to the branch name too. I think it's good for branch names to be 1:1 with worktree paths.

Maybe we can call it WorkStreamPattern?

Copy link
Author

Choose a reason for hiding this comment

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

Are you thinking the branch name would be another pattern we include?

@nbperry nbperry requested a review from jayshrivastava August 7, 2025 20:51
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.

Support configurable worktree location patterns
3 participants