Skip to content

Conversation

@iloveitaly
Copy link
Contributor

@iloveitaly iloveitaly commented Nov 26, 2025

Check list

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have added unit tests for my code
  • I have made corresponding changes to the documentation

Description

If a branch is used by a git worktree it cannot be switched to and is
prefixed with a +. This excludes these branches from gcb to avoid
erroring out when they are selected.

Related to #399

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Test
  • Documentation change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

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.
Copy link
Collaborator

@carlfriedrich carlfriedrich left a 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.

Comment on lines +387 to 393
| 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` |
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 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
Copy link
Collaborator

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.

Copy link
Collaborator

@sandr01d sandr01d left a 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 '^[+]'
Copy link
Collaborator

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:

Suggested change
grep -v '^[+]'
grep -v '^+'

}

_forgit_worktree_filter() {
if [[ "${FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES:-true}" == "true" ]]; then
Copy link
Collaborator

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...

@Chemaclass
Copy link

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!

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.

4 participants