-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -65,6 +65,15 @@ _forgit_emojify() { | |||||
| fi | ||||||
| } | ||||||
|
|
||||||
| _forgit_worktree_filter() { | ||||||
| if [[ "${FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES:-true}" == "true" ]]; then | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
| # Worktree branches are prefixed with '+' in 'git branch' output | ||||||
| grep -v '^[+]' | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
| else | ||||||
| cat | ||||||
| fi | ||||||
| } | ||||||
|
|
||||||
| # extract the first git sha occurring in the input and strip trailing newline | ||||||
| _forgit_extract_sha() { | ||||||
| grep -Eo '[a-f0-9]+' | head -1 | tr -d '[:space:]' | ||||||
|
|
@@ -879,7 +888,7 @@ _forgit_checkout_branch() { | |||||
| " | ||||||
| _forgit_checkout_branch_branch_git_opts=() | ||||||
| _forgit_parse_array _forgit_checkout_branch_branch_git_opts "$FORGIT_CHECKOUT_BRANCH_BRANCH_GIT_OPTS" | ||||||
| branch="$(git branch --color=always "${_forgit_checkout_branch_branch_git_opts[@]:---all}" | LC_ALL=C sort -k1.1,1.1 -rs | | ||||||
| branch="$(git branch --color=always "${_forgit_checkout_branch_branch_git_opts[@]:---all}" | _forgit_worktree_filter | LC_ALL=C sort -k1.1,1.1 -rs | | ||||||
| FZF_DEFAULT_OPTS="$opts" fzf | awk '{print $1}')" | ||||||
| [[ -z "$branch" ]] && return 1 | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| function set_up() { | ||
| source bin/git-forgit | ||
| } | ||
|
|
||
| function test_forgit_worktree_filter_excludes_plus_lines_by_default() { | ||
| local input="+ worktree-branch | ||
| * main-branch | ||
| other-branch" | ||
|
|
||
| # Default behavior (true) | ||
| local actual | ||
| actual=$(echo "$input" | _forgit_worktree_filter) | ||
| local expected="* main-branch | ||
| other-branch" | ||
|
|
||
| assert_same "$expected" "$actual" | ||
| } | ||
|
|
||
| function test_forgit_worktree_filter_excludes_plus_lines_when_explicitly_enabled() { | ||
| export FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES="true" | ||
| local input="+ worktree-branch | ||
| * main-branch" | ||
|
|
||
| local actual | ||
| actual=$(echo "$input" | _forgit_worktree_filter) | ||
| local expected="* main-branch" | ||
|
|
||
| assert_same "$expected" "$actual" | ||
| unset FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES | ||
| } | ||
|
|
||
| function test_forgit_worktree_filter_includes_plus_lines_when_disabled() { | ||
| export FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES="false" | ||
| local input="+ worktree-branch | ||
| * main-branch" | ||
|
|
||
| local actual | ||
| actual=$(echo "$input" | _forgit_worktree_filter) | ||
| local expected="+ worktree-branch | ||
| * main-branch" | ||
|
|
||
| assert_same "$expected" "$actual" | ||
| unset FORGIT_CHECKOUT_BRANCH_EXCLUDE_WORKTREES | ||
| } |
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.