about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2016-06-22T15·00-0400
committerWilliam Carroll <wpcarro@gmail.com>2016-06-22T15·00-0400
commit46b758d6482a45599fd8a2850a391c1be14ab33a (patch)
treecf7ce8c9150c00b98d89f8195e685b46a3715cac
parentf5706af33743b567e1bcb5ec64fd0e391a2664b9 (diff)
Adds another git function
Adds function to search git branches for a ticket number

`$ wgcheckout "$(wgfind 1045)"`
-rw-r--r--.git_functions.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/.git_functions.sh b/.git_functions.sh
index 4bd7b5fc2dce..16162f0191a9 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