-
Notifications
You must be signed in to change notification settings - Fork 7
/
git-cleartip
executable file
·58 lines (47 loc) · 1.29 KB
/
git-cleartip
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
#!/bin/bash
SCRIPT_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
usage() {
echo "
Usage: $(basename $0) [OPTIONS] [BRANCH]
Clear tip (or wip) in the remote for your branch namespace
OPTIONS
-a clear all tips and wips of your branch namespace
-h display this help message
-n dry-run
All the unknown options are passed directly to the git-push command.
" 1>&2;
exit 1;
}
. $SCRIPT_DIR/uri_parser.sh
. $SCRIPT_DIR/tip_config.sh
OPT_ALL=0
pushargs=""
args=
for arg in "$@"; do
case "$arg" in
-a) OPT_ALL=1
;;
-h) usage
;;
# unknown options go to arguments to git-push
# do nothing for '-n' it will be pased direclty to git-push as well
-*) pushargs="$pushargs $arg"
;;
*) args="$args $arg"
;;
esac
done
IFS=' ' read -a args <<< "$args"
branchargs=""
BRANCH="*"
if [ $OPT_ALL -eq 0 ]; then
TIP=${args[0]:-HEAD}
BRANCH=$(basename $(git rev-parse --abbrev-ref --symbolic $TIP))
if [ -z "$BRANCH" ]; then
die "No branch matches '$TIP'"
fi
fi
branchprefix=${branchprefix/tip/[tw]ip}
branchargs=$(git branch -r --list "$remote/$branchprefix/$BRANCH" | sed "s#$remote/#:#")
[ -z "$branchargs" ] && exit 0
git push $pushargs $remote $branchargs