/
git
81 lines (76 loc) · 2.71 KB
/
git
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!bash
git() {
if [[ "$1" == "pullall" ]]; then
_gitall pull
elif [[ "$1" == "pushall" ]]; then
_gitall push
elif [[ "$1" == "statusall" ]]; then
_gitall status
elif [[ "$1" == "showdefaultbranch" ]]; then
$(which git) remote show origin | awk '/HEAD branch/ {print $NF}'
elif [[ "$1" == "defaultbranch" ]]; then
$(which git) checkout $(git showdefaultbranch)
elif [[ "$1" == "root-hash" ]]; then
$(which git) hash-object -t tree /dev/null
elif [[ "$1" == "diff-unfancy" ]]; then
shift
$(which git) -c pager.diff="less --tabs=4 -RFX" diff "$@"
elif [[ "$1 $2 $3" == "clone git clone" ]]; then
# because some gitty websites want to copy 'git clone blahblah' into
# the paste buffer and others just the repository address. Bastards
shift; shift
$(which git) "$@"
elif [[ "$1" == "log" ]]; then
shift
$(which git) log --graph --date-order "$@"
elif [[ "$1" == "cherry-pick" ]]; then
shift
if [ "$1" == "--continue" ] || [ "$1" == "--skip" ] || [ "$1" == "--abort" ] || [ "$1" == "--quit" ]; then
$(which git) cherry-pick "$@"
else
$(which git) cherry-pick -x "$@"
fi
elif [[ "$1" == "commit" ]]; then
shift
for i in "$@"; do
# -a encourages committing of unrelated changes
# -m encourages short pithy commit messages
if [ "$i" == "-a" ] || [ "$i" == "--all" ] || [ "$i" == "-m" ] || [ "$i" == "--message" ]; then
echo NO\! SHAN\'T\! $i is BAD\!
return 1
fi
done
if [[ "$1" != "--amend" ]]; then
local DEFAULT_BRANCH=$(git showdefaultbranch)
local CURRENT_BRANCH=$($(which git) rev-parse --abbrev-ref HEAD)
if [[ "$CURRENT_BRANCH" = "$DEFAULT_BRANCH" ]]; then
if [ "$COMMIT_TO_DEFAULT_BRANCH" ] ; then
echo "OK, letting you commit to $CURRENT_BRANCH"
else
echo "You should not be committing to $CURRENT_BRANCH directly, raise a PR"
echo "If you have a really good reason to do so, set env var COMMIT_TO_DEFAULT_BRANCH"
return 1;
fi
fi
fi
if [[ "$1" != "--amend" ]]; then
$(which git) commit -v "$@"
else
# git commit -v makes thoughtful commit messages easier
$(which git) commit "$@"
fi
else
$(which git) "$@"
fi
}
_gitall() {
for i in *; do
if [[ -d $i ]]; then
echo $i
(
cd $i
git $1 2>&1| sed 's/^/ /'
)
fi
done
}