-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathginit
56 lines (45 loc) · 1.3 KB
/
ginit
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
#!/bin/sh
if [ "$#" != 1 ] || [ "$1" == "--help" ]; then
echo " ginit -- create local repo in current directory and set origin remote."
echo " usage: ginit [address]"
echo " e.g. ginit https://github.com/terriblememory/stupidgit.git"
exit 1
fi
ADDRESS=$1
if (git rev-parse 2>/dev/null); then
echo "ERROR: Already a git repository. This script is too dumb to handle that!"
exit 1
fi
echo "Ensuring remote '$ADDRESS' is empty..."
if (git ls-remote --exit-code $ADDRESS); then
echo "ERROR: Remote '$ADDRESS' is NOT empty."
exit 1
fi
if !(git init); then
echo "ERROR: 'git init' failed."
exit 1
fi
if !(git add .); then
echo "ERROR: 'git add' failed."
exit 1
fi
if [ -z "$(git status --porcelain)" ]; then
echo "ERROR: Nothing to commit. Do some work then try again! Removing empty repo."
rm -rf .git
exit 1
fi
echo "Performing initial commit to the local repo."
if !(git commit -m "Initial commit."); then
echo "ERROR: 'git commit' failed."
exit 1
fi
if !(git remote add origin $ADDRESS); then
echo "ERROR: 'git remote' failed."
exit 1
fi
echo "Performing initial push to the remote origin."
if !(git push -u origin master); then
echo "ERROR: 'git push' failed."
exit 1
fi
echo "Done."