forked from repo-sync/github-sync
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-sync.sh
51 lines (41 loc) · 1.22 KB
/
git-sync.sh
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
#!/bin/sh
set -e
SOURCE_REPO=$1
SOURCE_BRANCH=$2
DESTINATION_REPO=$3
DESTINATION_BRANCH=$4
if ! echo $SOURCE_REPO | grep '.git'
then
if [[ -n "$SSH_PRIVATE_KEY" ]]
then
SOURCE_REPO="git@github.com:${SOURCE_REPO}.git"
GIT_SSH_COMMAND="ssh -v"
else
SOURCE_REPO="https://github.com/${SOURCE_REPO}.git"
fi
fi
if ! echo $DESTINATION_REPO | grep -E '.git|@'
then
if [[ -n "$SSH_PRIVATE_KEY" ]]
then
DESTINATION_REPO="git@github.com:${DESTINATION_REPO}.git"
GIT_SSH_COMMAND="ssh -v"
else
DESTINATION_REPO="https://github.com/${DESTINATION_REPO}.git"
fi
fi
echo "SOURCE=$SOURCE_REPO:$SOURCE_BRANCH"
echo "DESTINATION=$DESTINATION_REPO:$DESTINATION_BRANCH"
git clone "$SOURCE_REPO" /root/source --origin source && cd /root/source
git remote add destination "$DESTINATION_REPO"
# Pull all branches references down locally so subsequent commands can see them
git fetch source '+refs/heads/*:refs/heads/*' --update-head-ok
chmod 777 gen-files.sh
./gen-files.sh
git add .
git config --global user.name "auto_user"
git config --global user.email "auto@silabs.com"
git commit -a -m "gen links"
# Print out all branches
git --no-pager branch -a -vv
git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" -f