-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathafter-first-checkout.sh
More file actions
executable file
·47 lines (41 loc) · 1.52 KB
/
after-first-checkout.sh
File metadata and controls
executable file
·47 lines (41 loc) · 1.52 KB
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
#!/usr/bin/env bash
#
# Prepare freshly cloned git repo for use with gerrit
## Configure me (if you like..)
SHORT=formaster
GITURL=$(git config --get remote.origin.url)
SSHURL=$(echo "$GITURL"|sed -r 's%^ssh://([^:]+):[^:]+$%\1%')
PORT=$(echo "$GITURL"|sed -r 's%^.+:([0-9]+)/.*$%\1%')
##
CONFIG=.git/config
HOOKDIR=.git/hooks
cd $(dirname $0)
if [ ! -w "$CONFIG" ]; then
echo -e "\E[31m:( $CONFIG does not exist or is not writable; is this a writable git repository?\E[37m"
exit 1
fi
# Setup shortcut for pushing changesets: e.g., git push formaster
if grep -q $SHORT $CONFIG; then
echo -e "\E[32m:) Shortcut \E[33m$SHORT \E[32malready set."
else
echo -e "\E[32mSetting up \E[33m$SHORT \E[32mshortcut in \E[33m$CONFIG"
echo -e "[remote \"$SHORT\"]\n\turl = $GITURL\n\tpush = HEAD:refs/for/master" >> $CONFIG
fi
# Install commit hook setting gerrit change id
if [ -f $HOOKDIR/commit-msg ]
then
echo -e "\E[32m:) Customized commit message already installed."
if grep -q "Change-Id:" $HOOKDIR/commit-msg
then
echo -e ":) Commit message seems to support Change-Ids."
else
echo -e "\E[31m:( Nothing about \E[33mChange-Id \E[31min \E[33m$HOOKDIR/commit-msg"
fi
else
echo -e "\E[32m:) Downloading commit message from $SSHURL.\E[37m"
if ! scp -p -P $PORT "$SSHURL:hooks/commit-msg" .git/hooks; then
echo -e "\E[31m:( Could not load \E[33mcommit-msg \E[31m"
echo -e "\E[37mTry manually: \E[33mscp -p -P $PORT $SSHURL:hooks/commit-msg $CONFIG"
fi
fi
echo -e "\E[37mdone."