-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbitbuket2bitbucket-migration.sh
137 lines (122 loc) · 4.13 KB
/
bitbuket2bitbucket-migration.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
set -euo pipefail
df -h
export GIT_SSL_NO_VERIFY=1
if [[ -d ./code-utils ]] ; then
cd ./code-utils
git fetch -ap
git reset --hard origin/master
cd ..
else
git clone https://github.com/Praqma/code-utils.git
fi
if [[ "${debug:-}" == true ]]; then
export GIT_TRACE=1
set -x
fi
project=$(echo ${projects_slug} | cut -d / -f1)
slug=$(echo ${projects_slug} | cut -d / -f 3 | cut -d : -f 1 )
lfs_statement=$(echo ${projects_slug} | cut -d : -f 2)
[[ ${lfs_statement:-} != "" ]] && [[ ${lfs_statement:-} != "${projects_slug}" ]] && eval ${lfs_statement}
if [[ -d ${slug}.git ]]; then
cd ${slug}.git
git fetch origin -ap
git fetch origin --tags
if [[ ${lfs_enabled:-true} == true ]]; then
git lfs fetch --all || {
exitcode_lfs_fetch=$?
if [[ ${lfs_accept_missing:-false} == true ]]; then
echo "INFO: we accept issues"
git lfs uninstall --local
else
exit $exitcode_lfs_fetch
fi
}
fi
else
mkdir ${slug}.git
cd ${slug}.git
git init --bare
git config --add remote.origin.url ${old_server_url}/${project}/${slug}.git
git config --add remote.origin.fetch +refs/heads/*:refs/heads/*
git config --add remote.origin.fetch +refs/tags/*:refs/tags/*
git config -l --local
git fetch origin -ap
git fetch origin --tags
if [[ ${lfs_enabled:-true} == true ]]; then
git lfs install --local
git lfs fetch --all || {
exitcode_lfs_fetch=$?
if [[ ${lfs_accept_missing:-false} == true ]]; then
echo "INFO: we accept issues"
git lfs uninstall --local
else
exit $exitcode_lfs_fetch
fi
}
fi
fi
if [[ -d lfs ]] ; then
du -sh lfs
fi
git show-ref
if [[ ${bitbucket_server_type:-} == "bitbucketProd" ]]; then
export bitbucket_server=$bitbucket_prod_server
fi
bitbucket_server_url=https://${bitbucket_username}:${bitbucket_password}@${bitbucket_server}
git push ${bitbucket_server_url}/scm/${project}/${slug}.git --mirror || {
cd ${WORKSPACE}
export netrc_file=~/.netrc
source ./code-utils/bitbucket/_bitbucket_repo_functions.sh
bash ./code-utils/bitbucket/bitbucket_create_repo-branch-restrictions.sh "${project}" "${slug}" ${netrc_file} "${bitbucket_server_url}" "$(whoami)" || {
echo "machine ${bitbucket_server}" >> ./.netrc
echo "login ${bitbucket_username}" >> ./.netrc
echo "password ${bitbucket_password}" >> ./.netrc
export netrc_file=$(pwd)/.netrc
source ./code-utils/bitbucket/_bitbucket_repo_functions.sh
bash ./code-utils/bitbucket/bitbucket_create_repo-branch-restrictions.sh "${project}" "${slug}" ${netrc_file} "${bitbucket_server_url}" "$(whoami)"
rm -rf ./.netrc
}
cd ${slug}.git
git push ${bitbucket_server_url}/scm/${project}/${slug}.git --mirror
}
bitbucket_server_url=https://${bitbucket_username}:${bitbucket_password}@${bitbucket_server}
if [[ ${lfs_enabled:-true} == true ]]; then
git lfs ls-files -a -s
git lfs push --all ${bitbucket_server_url}/scm/${project}/${slug}.git || {
exitcode_lfs_push=$?
if [[ ${lfs_accept_missing:-false} == true ]]; then
echo "INFO: we accept issues"
else
exit $exitcode_lfs_push
fi
}
fi
git ls-remote --heads origin > ${WORKSPACE}/origin_heads.txt
git ls-remote --tags origin > ${WORKSPACE}/origin_tags.txt
git ls-remote --heads ${bitbucket_server_url}/scm/${project}/${slug}.git > ${WORKSPACE}/aws_heads.txt
git ls-remote --tags ${bitbucket_server_url}/scm/${project}/${slug}.git > ${WORKSPACE}/aws_tags.txt
cd ${WORKSPACE}
diff -y origin_heads.txt aws_heads.txt && echo "All good - heads are identical" || {
echo "ERROR: heads differ"
exit_code=2
}
diff -y origin_tags.txt aws_tags.txt && echo "All good - tags are identical" || {
echo "ERROR: tags differ"
exit_code=2
}
rm -rf ${slug}-test.git
git clone ${bitbucket_server_url}/scm/${project}/${slug}.git --mirror ${slug}-test.git
if [[ ${lfs_enabled:-true} == later ]]; then
cd ${slug}-test.git
git lfs install --local
git lfs fetch --all || {
exitcode_lfs_refetch=$?
if [[ ${lfs_accept_missing:-false} == true ]]; then
echo "INFO: we accept issues"
else
exit $exitcode_lfs_refetch
fi
}
fi
exit ${exit_code:-}