-
Notifications
You must be signed in to change notification settings - Fork 154
exclude worktree branches #474
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
base: main
Are you sure you want to change the base?
Conversation
Switching to a branch occupied by another worktree results in an error. Until proper support for work trees is released, I think this is a good stop gap.
carlfriedrich
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iloveitaly Thanks a lot for the PR. Very clean implementation and big thumbs up for adding the unit test! Approved from my side. Will wait whether the other maintainers want to say something, otherwise I will merge this next week.
| | Option | Description | Default | | ||
| |--------------------------------------------|-----------------------------------------------|-----------------------------------------------| | ||
| | `FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES` | exclude worktree branches in `gcb` | `true` | | ||
| | `FORGIT_LOG_FORMAT` | git log format | `%C(auto)%h%d %s %C(black)%C(bold)%cr%Creset` | | ||
| | `FORGIT_PREVIEW_CONTEXT` | lines of diff context in preview mode | 3 | | ||
| | `FORGIT_FULLSCREEN_CONTEXT` | lines of diff context in full-screen mode | 10 | | ||
| | `FORGIT_DIR_VIEW` | command used to preview directories | `tree` if available, otherwise `find` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the rest of the table should be widened as well to keep the formatting consistent.
| } | ||
|
|
||
| _forgit_worktree_filter() { | ||
| if [[ "${FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES:-true}" == "true" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, one more thing: we're evaluating this kind of env variables at a central place in the code (search for FORGIT_LOG_GRAPH_ENABLE for example). I think we should do it like that with this variable, too.
sandr01d
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks clean, just two minor questions/comments from my side.
| _forgit_worktree_filter() { | ||
| if [[ "${FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES:-true}" == "true" ]]; then | ||
| # Worktree branches are prefixed with '+' in 'git branch' output | ||
| grep -v '^[+]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding, the bracket expression isn't necessary or is there any reason we can't simply use:
| grep -v '^[+]' | |
| grep -v '^+' |
| } | ||
|
|
||
| _forgit_worktree_filter() { | ||
| if [[ "${FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES:-true}" == "true" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there actually a case where somebody would not want to exclude worktrees? If they don't work with checkout we might want to always exclude them...
|
As @carlfriedrich says, kudos for adding the unit test! I love seen bashunit being use and getting adoption! It feels so good helping the community. Cheers! |
Check list
Description
If a branch is used by a git worktree it cannot be switched to and is
prefixed with a
+. This excludes these branches fromgcbto avoiderroring out when they are selected.
Related to #399
Type of change
Test environment