-
Notifications
You must be signed in to change notification settings - Fork 1
/
rebasefork
executable file
·69 lines (54 loc) · 1.63 KB
/
rebasefork
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
#!/bin/bash
## Brings your fork up to speed with upstream, and informs
## you of how far behind you were! You can supply the -f
## flag to OVERWRITE your forked repo to be the same as
## upstream -- useful if you mangle your fork and want to
## reset it.
############################################################
## YOUR VALUES ##
#################
## Your github username:
GITUSER=andf-crl
############################################################
## BEGIN SCRIPT ##
##################
TMPDIR=/tmp/rebasefork$$
FORCE=""
## Check for FORCE override: for resetting your fork to be
## identical to upstream. WARNING: destroys any fork-specific
## commits!
while getopts ":f" opt; do
case ${opt} in
f )
FORCE=1
;;
\? )
echo -e "\nERROR: Invalid option: $OPTARG" 1>&2
echo " rebasefork only supports the optional -f flag"
echo -e " for resetting to match upstream\n"
exit
;;
esac
done
mkdir -p $TMPDIR
cd $TMPDIR
git clone git@github.com:$GITUSER/docs.git
cd docs
git remote add upstream git@github.com:cockroachdb/docs.git
# Current commit count before:
BEFORE=`git rev-list --left-right --count origin | awk '{print $2}'`
git fetch upstream
# Proceed depending on user-supplied flag:
if [ ! $FORCE ]; then
git rebase upstream/master
git push origin master
else
git reset --hard upstream/master
git push origin master --force
fi
# New commit count after:
AFTER=`git rev-list --left-right --count origin | awk '{print $2}'`
# Just for fun, report number of commits moved:
NUM_COMMITS=`echo "$AFTER - $BEFORE" | bc`
echo "Moved ahead $NUM_COMMITS commits"
rm -rf $TMPDIR