-
Notifications
You must be signed in to change notification settings - Fork 6
/
gitlab-remote-v1.0
executable file
·53 lines (41 loc) · 1.29 KB
/
gitlab-remote-v1.0
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
#!/bin/bash
repo_name=$1
token=$2
dir_name=`basename $(pwd)`
if [ "$repo_name" = "" ]; then
echo "Repo name (hit enter to use '$dir_name')?"
read repo_name
fi
if [ "$repo_name" = "" ]; then
repo_name=$dir_name
fi
email=`git config user.email`
if [ "$email" = "" ]; then
echo "Could not find email, run 'git config --global user.mail <mail>'"
invalid_credentials=1
fi
if [ "$token" = "" ]; then
echo "Could not find token. Please enter your token"
invalid_credentials=1
fi
if [ "$invalid_credentials" == "1" ]; then
exit 1
fi
username=`git config user.email | cut -d '@' -f1`
echo -n "Creating GitLab repository '$repo_name' ..."
curl -H "Content-Type:application/json" https://gitlab.com/api/v3/projects?private_token=$token -d '{"name":"'$repo_name'"}' > /dev/null 2>&1
echo " done."
# 2>$1 means that we want redirect stderr to stdout
echo -n "Pushing local code to remote ..."
git init
echo "gitlab-init-remote.sh" > .gitignore
echo ".gitignore" >> .gitignore
git config --global core.excudefiles ~/.gitignore_global
git add .
git commit -m "first commit"
git remote add origin [email protected]:$username/$repo_name.git > /dev/null 2>&1
git push -u origin master > /dev/null 2>&1
echo " done."
echo ""
echo "The created repo is available at following link:"
echo "https://gitlab.com/$username/$repo_name"