-
Notifications
You must be signed in to change notification settings - Fork 1
/
gpush.in
74 lines (62 loc) · 1.6 KB
/
gpush.in
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
#!/usr/bin/env bash
m4_include(gu_tools.inc.sh)
usage() {
printf '%s\n' \
'gpush @VERSION@' \
'' \
'gpush push branch to a remote branch.' \
'' \
'Usage: gpush [-h] [-f] [[-b] branch] [-r remote]' \
'' \
' -h Show this usage.' \
' -f Force pushing to remote.' \
' branch: Name of the branch to push.' \
' remote: Name of the remote to push into.'
}
set -e
# defaults
if [ -z "${REMOTE-}" ]; then
REMOTE=origin
fi
# process flags
pointer=1
while [[ $pointer -le $# ]]; do
if [[ ${!pointer} != "-"* ]]; then ((pointer++)) # not a parameter flag so advance pointer
else
param=${!pointer}
((pointer_plus = pointer + 1))
slice_len=1
case $param in
# paramter-flags with arguments
-r|--remote) REMOTE=${!pointer_plus}; ((slice_len++));;
-b|--branch) BRANCH=${!pointer_plus}; ((slice_len++));;
# binary flags
-h|--help) HELP=true;;
-f|--force) FORCE=true;;
esac
# splice out pointer frame from positional list
[[ $pointer -gt 1 ]] \
&& set -- ${@:1:((pointer - 1))} ${@:((pointer + $slice_len)):$#} \
|| set -- ${@:((pointer + $slice_len)):$#};
fi
done
if [ ! -z "${HELP-}" ]; then
usage
exit 0
fi
if [ -z "${BRANCH-}" ]; then
BRANCH=$1
fi
if [ -z "${BRANCH-}" ]; then
BRANCH=${BASED_BRANCH}
fi
if remote_avail ${REMOTE}; then
if [ ! -z "${FORCE-}" ]; then
git push -u -f ${REMOTE} ${BRANCH}
else
git push -u ${REMOTE} ${BRANCH}
fi
else
echo The ${REMOTE} is not available.
fi
# vim: set et ts=2 sw=2: