about summary refs log tree commit diff
path: root/.git_functions.sh
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2016-06-15T14·23-0400
committerWilliam Carroll <wpcarro@gmail.com>2016-06-15T14·23-0400
commit636347304d94e2353b21b3e6de30bd72e493a3ff (patch)
tree031699703b19f66af4171f38e9b519445deb4319 /.git_functions.sh
parentea5c662b67075f32024d0420fd2c9048b44ccf42 (diff)
Extends git_functions.sh
* Adds function to export the previous git branch to the environment
* Adds function to get the current branch you're on
* Adds function to get the current ticket for the branch you're on
Diffstat (limited to '.git_functions.sh')
-rw-r--r--.git_functions.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/.git_functions.sh b/.git_functions.sh
index 5eaafbb498ad..4bd7b5fc2dce 100644
--- a/.git_functions.sh
+++ b/.git_functions.sh
@@ -1,3 +1,34 @@
+# output current branch to STDOUT
+function wgbranch {
+  cat ./.git/HEAD | perl -p -e 's/^ref:\srefs\/heads\/(.+)$/\1/g'
+}
+
+
+# output the stash ticket number to STDOUT
+function wgtix {
+  wgbranch | perl -p -e 's/(?:feature|bugfix|refactor)\/(\w+-\d+).+$/\1/'
+}
+
+
+# wrapper fn for "git checkout" that exports previous branch to env
+function wgcheckout {
+  if [ -z $1 ]; then
+    branchname="develop"
+  else
+    branchname="$1"
+  fi
+
+  echo " -- wgcheckout -- "
+  echo "Storing branch \"$(wgbranch)\" in WGPREV ..."
+  export WGPREV="$(wgbranch)"
+  echo "Checking out \"$branchname\" ..."
+  echo
+  echo " -- git checkout -- "
+  git checkout "$branchname"
+  echo
+}
+
+
 # combine fetch and rebase (git frebase)
 function wgfreebase {
     if [ -z $1 ]; then
@@ -9,6 +40,7 @@ function wgfreebase {
     git fetch origin "$branchname" && git rebase origin/"$branchname"
 }
 
+
 # push to current branch
 function wgpush {
     if [ -z $1 ]; then
@@ -19,3 +51,4 @@ function wgpush {
 
     git push origin $branchname
 }
+