-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgerrit
executable file
·47 lines (39 loc) · 1.72 KB
/
gerrit
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
#!/bin/bash
# Thank Smasher816 for this, WTFPL!
# Overrides: branch=$1 server=$2 port=$3 user=$4
# Defaults: $1=jb $2=gerrit.aokp.co $3=29418 $4=$USER
#Google for some magic bash replacement default variable stuff
BRANCH=${1:-jb}
SERVER=${2:-fnv.snipanet.com}
[ -z $3 ] && PORT=29418 || PORT=$3 #Someone make numerical defaults work
ACCOUNT=${4:-sixstringsg} # $USER is the currently logged on user (shell var)
DIR_CURRENT=$PWD # $PWD is the current directory (shell var)
echo $BRANCH
echo $SERVER
echo $ACCOUNT
echo $DIR_CURRENT
# Loop through directory parents, find one with .git
# ex: frameworks/base/wifi will find framerworks/base
DIR_TOP=${DIR_CURRENT}
while [ ! -d "$DIR_TOP/.git" ]; do
DIR_TOP=$(dirname ${DIR_TOP})
done
# Loop through directory parents, find one with .repo (the main android folder)
# ex: ~/FNV/frameworks/base/wifi will find ~/FNV
DIR_BOTTOM=${DIR_CURRENT}
while [ ! -d "$DIR_BOTTOM/.repo" ]; do
DIR_BOTTOM=$(dirname ${DIR_BOTTOM})
done
echo DIR_BOTTOM: $DIR_BOTTOM
# Take DIR_TOP (FNV/frameworks/base) and take off bottom (FNV/) leaving the local branch folder (frameworks/base)
DEST=$(echo "${DIR_TOP}" | awk "BEGIN {FS=\"${DIR_BOTTOM}/\"} {print \$2}")
echo destination: $DEST
# Take the local folder and find it in the git manifest
PROJECT=$(grep ${DEST} ${DIR_BOTTOM}/.repo/manifest.xml)
# Take the remote part (name="XXXXX") with some regex magic
PROJECT=$(echo "${PROJECT}" | grep -Po 'name=".*?"' | cut -d '"' -f2 )
echo project: $PROJECT
# echo to command to be sure
echo "git push ssh://${ACCOUNT}@${SERVER}:${PORT}/${PROJECT} HEAD:refs/for/${BRANCH}"
# run it, eval fusses parameters into one shell command
eval "git push ssh://${ACCOUNT}@${SERVER}:${PORT}/FruitsAndVeggies/${PROJECT} HEAD:refs/for/${BRANCH}"