From 62cc8abde1945e0a343a2dbf6a12869f1acea0c1 Mon Sep 17 00:00:00 2001 From: Chris Apple <14171107+cjappl@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:42:07 -0700 Subject: [PATCH] Provide an input branch with gcp again (#252) Noticed there was a change recently that broke the ability to pass in an input branch to gcp. This change is the following: Fix faulty logic that just led to a git checkout -b being called when you pass in an argument to gcp If an argument was passed in, check if it is a valid branch, if so, set the input_branch var If input_branch is set, use it to do the cherry pick, as opposed to the first FZF selection. --- bin/git-forgit | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index dc72704..d397924 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -247,8 +247,11 @@ _forgit_cherry_pick() { _forgit_cherry_pick_from_branch() { _forgit_inside_work_tree || return 1 - [[ $# -ne 0 ]] && { git checkout -b "$@"; return $?; } - local cmd preview opts branch exitval + local cmd preview opts branch exitval input_branch args + args=("$@") + if [[ $# -ne 0 ]]; then + input_branch=${args[0]} + fi cmd="git branch --color=always --all | LC_ALL=C sort -k1.1,1.1 -rs" preview="git log {1} $_forgit_log_preview_options" opts=" @@ -261,13 +264,19 @@ _forgit_cherry_pick_from_branch() { # picked has been selected from within a branch while true do - branch="$(eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf | awk '{print $1}')" + if [[ -z $input_branch ]]; then + branch="$(eval "$cmd" | FZF_DEFAULT_OPTS="$opts" fzf | awk '{print $1}')" + else + branch=$input_branch + fi + + unset input_branch [[ -z "$branch" ]] && return 1 _forgit_cherry_pick "$branch" exitval=$? - [[ $exitval != 130 ]] && return $exitval + [[ $exitval != 130 ]] || [[ $# -ne 0 ]] && return $exitval done }