-
Notifications
You must be signed in to change notification settings - Fork 14
/
git-now-grep
44 lines (39 loc) · 1.08 KB
/
git-now-grep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
usage() {
echo "usage: git now grep [--patch|-p] [--stat|-s] [--mine|-m] [<base-branch>]"
}
cmd_default() {
parse_args "$@"
if [ -n "$BASE_BRANCH" ]; then
WORKING_BRANCH=$(git_current_branch)
COMMON_ANCESTOR_COMMIT=`git merge-base ${BASE_BRANCH} ${WORKING_BRANCH}`
git log${ARGS} ${COMMON_ANCESTOR_COMMIT}.. --pretty=format:"%h - %an, %ar : %s" --grep="${PREFIX}"
else
git log${ARGS} --pretty=format:"%h - %an, %ar : %s" --grep="${PREFIX}"
fi
}
parse_args() {
# parse options
DEFINE_boolean 'patch' false 'generate diff in patch format' 'p'
DEFINE_boolean 'stat' false 'generate diffstat instead of patch' 's'
DEFINE_boolean 'mine' false 'limit git-now commits by my name' 'm'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# read arguments into global variables
BASE_BRANCH=$1
ARGS=
if flag patch; then
ARGS="${ARGS} -p"
fi
if flag stat; then
ARGS="${ARGS} --stat"
fi
if flag mine; then
AUTHOR=$(escape `git config --get user.name`)
ARGS="${ARGS} --author=$AUTHOR"
fi
}
cmd_help() {
usage
exit 0
}
# vim: set ff=unix ft=sh :