-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-sync.sh
More file actions
executable file
·82 lines (65 loc) · 2.1 KB
/
git-sync.sh
File metadata and controls
executable file
·82 lines (65 loc) · 2.1 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
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
75
76
77
78
79
80
81
82
#!/bin/sh
set -e
SOURCE_REPO=$1
SOURCE_BRANCH=$2
DESTINATION_REPO=$3
DESTINATION_BRANCH=$4
EMAIL=$5
NAME=$6
FORCE=$7
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 '.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 config --global user.email "$EMAIL"
git config user.email
git config --global user.name "$NAME"
git config user.name
git config --global pull.rebase false
echo "----------------------------------------------------------------"
git clone "$SOURCE_REPO" --origin source && cd `basename "$SOURCE_REPO" .git`
sleep 10
echo "$SOURCE_REPO cloned"
git remote add destination $DESTINATION_REPO
sleep 2
echo "remote added $DESTINATION_REPO as destination"
echo "----------------------------------------------------------------"
echo "----------------------------------------------------------------"
git checkout $SOURCE_BRANCH
sleep 4
echo "checked out $SOURCE_BRANCH"
echo "----------------------------------------------------------------"
git pull destination $DESTINATION_BRANCH --allow-unrelated-histories -X ours
sleep 4
echo "pull complete $DESTINATION_REPO $DESTINATION_BRANCH"
#git fetch $DESTINATION_REPO $DESTINATION_BRANCH
#sleep 4
#echo "fetch complete $DESTINATION_REPO $DESTINATION_BRANCH"
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
if ! echo $FORCE | grep 'true'
then
git push destination $SOURCE_BRANCH:$DESTINATION_BRANCH
echo "Pushed $SOURCE_BRANCH:$DESTINATION without force"
else
git push destination $SOURCE_BRANCH:$DESTINATION_BRANCH -f
echo "Pushed $SOURCE_BRANCH:$DESTINATION force"
fi
echo ".........................................................."