-
Notifications
You must be signed in to change notification settings - Fork 1
/
change-merged
executable file
·74 lines (61 loc) · 1.98 KB
/
change-merged
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
#!/bin/bash
# This script implements a gerrit hook to handle changes being merged into projects
# which need to sync over to a github project.
#
# When the commit is merged to a branch which is listed as one we sync, we will sync up with
# the github branch using git fetch && git rebase -p then push it to github.
set -e # exit on any error return val
# --change Ia6b818ea822ed6d7336c5b1c45e8d724ecb070b7 --change-url http://localhost:9090/8
# --change-owner Kelly Campbell ([email protected]) --project test_gerrit_sync --branch master
# --submitter Kelly Campbell ([email protected]) --commit cf3c79c7b541fec20630d7ff9273b76aa51ed196
while [[ $# > 1 ]] ; do
case "$1" in
--change)
change=$2 ; shift ;;
--change-url)
change_url=$2 ; shift ;;
--change-owner)
change_owner=$2 ; shift ;;
--project)
project=$2 ; shift ;;
--branch)
branch=$2 ; shift ;;
--submitter)
submitter=$2 ; shift ;;
--commit)
commit=$2 ; shift ;;
esac
shift
done
set +e
grep "$project" /home/gerrit/gerrit/etc/non_gitlab_repos.txt
exclude_proj=$?
set -e
if [[ $exclude_proj == 0 ]] ; then
exit
fi
# PROJECT="gerrit-project-name"
# BRANCH="master"
WORKDIR=/tmp/${USER}_${project}_${branch}_${BASHPID}
# if [ "$project" = "$PROJECT" -a "$branch" = "$BRANCH" ] ; then
mkdir -p "$WORKDIR"
git --git-dir=. --work-tree=$WORKDIR checkout -f $branch
git fetch origin ${branch}
# Rebase incase any commits got into the origin outside of gerrit
# execute in a subshell to keep -e from causing an exit
# TODO(kellyc): this is where commits tend to get stuck with status
# being submitted in gerrit, and nothing in origin
(
git --git-dir=. --work-tree=$WORKDIR rebase -p FETCH_HEAD
rebaseStatus=$?
if (( $rebaseStatus != 0 )) ; then
git --git-dir=. --work-tree=$WORKDIR rebase --abort
exit $rebaseStatus
fi
)
git --git-dir=. --work-tree=$WORKDIR push origin ${branch}
git fetch origin ${branch}
git update-ref HEAD FETCH_HEAD
rm -rf $WORKDIR
# fi
#