-
Notifications
You must be signed in to change notification settings - Fork 3
/
repo-to-bitbucket.sh
executable file
·81 lines (70 loc) · 2.27 KB
/
repo-to-bitbucket.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
#!/bin/bash
# set -o nounset
# set -o errexit
set -o pipefail
# enable for debug
# set -o xtrace
CURRENT_DIR=`pwd`
source $HOME/.r2b-credentials.sh
if [ -z "$BITBUCKET_USER" ];then
echo -e "\n\n** Please ensure your BITBUCKET_USER is setup in $HOME/.r2b-credentials.sh **"
exit 999
fi
if [ -z "$BITBUCKET_TEAM" ];then
echo -e "\n\n** Please ensure your BITBUCKET_TEAM is setup in $HOME/.r2b-credentials.sh **"
exit 999
fi
if [ -z "$BITBUCKET_PASSWORD" ];then
echo -e "\n\n** Please ensure your BITBUCKET_PASSWORD is setup in $HOME/.r2b-credentials.sh **"
exit 999
fi
function doGitMigrate(){
for REPO in `ls "$CURRENT_DIR"`;do
if [ -d "$CURRENT_DIR/$REPO" ];then
echo -e "\n\n** Updating $REPO at `date` **"
if [ -d "$CURRENT_DIR/$REPO/.git" ]; then
cd "$CURRENT_DIR/$REPO"
git status
echo -e "Fetching"
git fetch origin
echo -e "Stashing changes for simplicity"
git stash
echo -e "Pulling down all "
for REMOTE_BRANCH in `git branch -r`; do
if [[ $REMOTE_BRANCH == *"HEAD"* ]];then
echo 'NOT DOING STUFF TO HEAD; it complicates stuff'
else
git checkout --track ${REMOTE_BRANCH}
# incase branch is local already; pull any changes
git pull
fi
done
# just incase ;)
git checkout master
git branch -D HEAD
git remote remove bitbucket
git remote add bitbucket ssh://[email protected]/${BITBUCKET_TEAM}/${REPO}
# # create repositories on bitbucket for the repos
createBitBucketRepos ${REPO}
# push stuff
git push bitbucket --all
git push bitbucket --tags
else
echo -e "\n\nSkipping because it doesn't look like it has a .git folder."
fi
fi
done
echo -e "\n\nDone at `date`"
return
}
function createBitBucketRepos() {
#naming for niceness to people
REPO=${1}
echo "Creating BitBucket Repo:: ${REPO}"
curl -X POST "https://${BITBUCKET_USER}:${BITBUCKET_PASSWORD}@api.bitbucket.org/2.0/repositories/${BITBUCKET_TEAM}/${REPO}" \
-H "Content-Type: application/json" \
-d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }'
}
# call the doGitMigrate to kick this script off
# "$@"
doGitMigrate