2016-06-15 16:23:27 +02:00
|
|
|
# output current branch to STDOUT
|
|
|
|
function wgbranch {
|
|
|
|
cat ./.git/HEAD | perl -p -e 's/^ref:\srefs\/heads\/(.+)$/\1/g'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-13 17:36:40 +02:00
|
|
|
# Outputs staged, unstaged, untracked files
|
|
|
|
# Similar to `git status` output but without the cruft
|
|
|
|
function wg-git-changed-files {
|
|
|
|
tracked_staged=$(git diff --name-only --staged)
|
|
|
|
tracked_unstaged=$(git diff --name-only)
|
|
|
|
untracked_unstaged=$(git ls-files --others --exclude-standard)
|
|
|
|
|
|
|
|
echo "${tracked_staged}\n${tracked_unstaged}\n${untracked_unstaged}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-07 18:20:26 +01:00
|
|
|
# git status "plumbing" version
|
|
|
|
# Useful for piping into grep -> xargs git add
|
|
|
|
function wgst {
|
|
|
|
git status -s | awk '{ print $2 }'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# git add by file regex pattern
|
|
|
|
function wgadd {
|
|
|
|
pattern="$2"
|
|
|
|
|
|
|
|
wgst | grep "${pattern}" | xargs git add
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-06 02:39:32 +01:00
|
|
|
# compare file with another branch
|
|
|
|
function wgcompare_file {
|
|
|
|
file_path="$1"
|
|
|
|
compare_branch_a="master"
|
|
|
|
compare_branch_b="$(wgbranch)"
|
|
|
|
|
|
|
|
git diff "${compare_branch_a}:${file_path}" "${compare_branch_b}:${file_path}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 16:23:27 +02:00
|
|
|
# output the stash ticket number to STDOUT
|
|
|
|
function wgtix {
|
|
|
|
wgbranch | perl -p -e 's/(?:feature|bugfix|refactor)\/(\w+-\d+).+$/\1/'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-22 17:00:31 +02:00
|
|
|
# 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"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 16:23:27 +02:00
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-15 17:14:37 +02:00
|
|
|
# opens the current ticket-branch in web browser
|
|
|
|
function wgjira {
|
|
|
|
base_url="https://jira.hugeinc.com/browse"
|
|
|
|
ticket=$(wgtix)
|
2016-08-02 21:41:21 +02:00
|
|
|
|
2016-08-15 17:14:37 +02:00
|
|
|
open "${base_url}/${ticket}"
|
2016-08-02 21:01:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-15 17:14:37 +02:00
|
|
|
# wgcheckout combined with a fuzzy search
|
|
|
|
function wgfcheckout {
|
2016-12-20 02:53:45 +01:00
|
|
|
branchname=$(trim $(git branch | fzf-tmux))
|
2016-05-04 20:13:19 +02:00
|
|
|
|
2016-08-15 17:14:37 +02:00
|
|
|
[ ! -z "$branchname" ] && wgcheckout "$branchname" || return
|
2016-05-04 20:13:19 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 16:23:27 +02:00
|
|
|
|
2017-06-13 17:36:40 +02:00
|
|
|
# View an author's work within a specified date range.
|
2016-08-15 17:14:37 +02:00
|
|
|
function wgviewcommits {
|
|
|
|
author=$([ -z "$1" ] && echo "William Carroll" || echo "$1")
|
|
|
|
todays_date=$(date +'%Y-%m-%d')
|
|
|
|
date=$([ -z "$2" ] && echo "${todays_date}" || echo "$2")
|
2016-05-04 20:13:19 +02:00
|
|
|
|
2016-08-15 17:14:37 +02:00
|
|
|
git log --all --author="${author}" --after="${date} 00:00" \
|
|
|
|
--before="${date} 23:59"
|
2016-05-04 20:13:19 +02:00
|
|
|
}
|