From 46b758d6482a45599fd8a2850a391c1be14ab33a Mon Sep 17 00:00:00 2001 From: William Carroll Date: Wed, 22 Jun 2016 11:00:31 -0400 Subject: [PATCH] Adds another git function Adds function to search git branches for a ticket number `$ wgcheckout "$(wgfind 1045)"` --- .git_functions.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.git_functions.sh b/.git_functions.sh index 4bd7b5fc2..16162f019 100644 --- a/.git_functions.sh +++ b/.git_functions.sh @@ -10,6 +10,26 @@ function wgtix { } +# search for a git branch by ticket number +# useful when combined with `wgcheckout` +# e.g. +# $ wgcheckout "$(wgfind 1045)" +# checks-out feature/GDMX-1045 ... +# +# if the `TICKET_NO` cannot be found, it will return the current branch +function wgfind { + TICKET_NO="$1" + + BRANCHNAME=$(git branch | grep "$TICKET_NO" | perl -p -e 's/^\s*//') + + if [ -z $BRANCHNAME ]; then + BRANCHNAME="$(wgbranch)" + fi + + echo "$BRANCHNAME" +} + + # wrapper fn for "git checkout" that exports previous branch to env function wgcheckout { if [ -z $1 ]; then