Skip to content

Commit 6b628b1

Browse files
committed
add GIT_RECENT_QUERY env for testing
1 parent fbb93ae commit 6b628b1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

git-recent

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ fi
6262
# - https://github.com/junegunn/fzf/wiki/Examples-(fish)#git
6363
# - https://github.com/junegunn/fzf-git.sh (intense.)
6464

65+
# If there's a GIT_RECENT_QUERY environment variable, use it for non-interactive filtering. (Primarily added for testing.)
66+
filterarg=${GIT_RECENT_QUERY:+"--filter=$GIT_RECENT_QUERY"}
67+
6568
_browse_branches() {
6669
git for-each-ref --color=always --sort=-authordate "$heads" --format="$branches_format" \
67-
| fzf --ansi -- \
68-
--layout=reverse --multi --height=90% --min-height=20 \
70+
| fzf \
71+
$filterarg --ansi -- --layout=reverse --multi --height=90% --min-height=20 \
6972
--border-label-pos=2 --border-label '🌲 Branches' --border \
7073
--no-hscroll --no-multi \
7174
--preview-window='right,70%,border-left,border-rounded' --preview="$uniqcommits_cmd" --preview-label="Commits unique to branch" \
@@ -75,9 +78,12 @@ _browse_branches() {
7578
--bind "ctrl-y:execute-silent($copy_cmd)" \
7679
--bind "ctrl-o:preview:$diffbranch_cmd"
7780
}
78-
7981
chosen_branch="$(_browse_branches)"
80-
if [[ -n "$chosen_branch" ]]; then
82+
line_count=$(printf "%s" "$chosen_branch" | wc -l)
83+
84+
if [[ -n "$chosen_branch" ]] && (( line_count == 0 )); then
8185
echo git checkout "$chosen_branch"
8286
git checkout "$chosen_branch"
87+
else
88+
echo "$chosen_branch"
8389
fi

0 commit comments

Comments
 (0)