/
gr-initbare
81 lines (72 loc) · 2.02 KB
/
gr-initbare
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
#!/bin/sh
#git recursive directories scripts - http://safrm.net/projects/gr-scripts
#author: Miroslav Safr <miroslav.safr@gmail.com>
#
VERSION=NA
VERSION_DATE=NA
#support color escape characters on different terminals
alias echo="/bin/echo -e"
BASENAME=`basename $0`
usage() {
echo "$BASENAME ${VERSION}"
echo "Usage: $BASENAME <new_repo_name> [OPTIONS] "
echo "git helper to create new inited local git bare repo "
echo "args:"
echo " <new_repo_name> ..................... new git repo name (mandatory) e.g. my_project "
echo " -d, --description <project_descr> ... few words about project (optional)"
echo " -kc, --keep-clone ................... keep cloned directory"
echo " -h, --help ...................... prints this help"
echo " -V, --version ...................... prints version of scripts"
echo ""
}
exiting() {
echo "$@ Try $BASENAME --help. Exiting.."
exit 1
}
#check arguments
REPO_NAME=
DESCRIPTION=
while [ $# -gt 0 ]; do
case "$1" in
-V|--version) echo "`basename $0` ${VERSION} ${VERSION_DATE}" ; exit 0 ;;
-d|--description) shift ; DESCRIPTION="$1" ;;
-kc|--keep-clone) KEEP_CLONE=1 ;;
-h|--help) usage ; exit 0 ;;
*) REPO_NAME="$1" ;;
esac
shift
done
if [ -z "$REPO_NAME" ]; then
exiting "No new git repository name."
elif [ -d "$REPO_NAME" ]; then
exiting "Directory $REPO_NAME already exists."
fi
#echo "REPONAME: $REPO_NAME"
#check params
mkdir "$REPO_NAME.git"
cd "$REPO_NAME.git"
REPO_PATH=`pwd`
echo "$REPO_PATH"
git init --bare
if [ -n "$DESCRIPTION" ]; then
echo "$DESCRIPTION" > description
else
echo "$REPO_NAME " > description
fi
#make root checkout
cd ..
git clone $REPO_NAME.git $REPO_NAME-clone
cd $REPO_NAME-clone
#set up directory structure
cp -f ../$REPO_NAME.git/description .git/
git commit --allow-empty -m "init"
git tag 0.0.0 -m "init tag"
git push origin master -u
git push --tags
echo "new reposistory: $REPO_PATH"
if [ -n "$KEEP_CLONE" ]; then
echo "cloned to: `pwd`"
else
cd ..
rm -fr $REPO_NAME-clone
fi