-
Notifications
You must be signed in to change notification settings - Fork 10
/
git-practice-platform
executable file
·87 lines (72 loc) · 2.23 KB
/
git-practice-platform
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
#!/bin/bash
set -e
usage() {
echo "USAGE: git-practice-platform [-f | --folder <folder>] [-r | --repository <repository>] [-u | --usercount <count>]"
exit 1
}
repo=
folder=
user_count=2
path=$(pwd)
realargs="$@"
while [ $# -gt 0 ]; do
case "$1" in
-r | --repository)
repo=$2
shift
;;
-f | --folder)
folder=$2
shift
;;
-u | --usercount)
user_count=$2
shift
;;
*)
usage
;;
esac
shift
done
set -- $realargs
if [ -z "$repo" ] || [ -z "$folder" ]; then
usage
return
fi
if [ -d "$path/$folder" ]; then
echo "Folder already exists in $path/$folder"
echo "Quited"
exit 0
fi
root=${path}/${folder}
mkdir -p ${root}
echo "Root folder >>"
echo " Created as ${root}"
mkdir -p ${root}/server/${repo}.git > /dev/null 2>&1
cd ${root}/server/${repo}.git
git init --bare > /dev/null 2>&1
echo "Bare repository >>"
echo " Created under server/${repo}.git"
for (( i=1; i<=${user_count}; i++ ))
do
echo "User${i} repository >>"
mkdir -p ${root}/clients > /dev/null 2>&1
mkdir -p ${root}/clients/user${i} > /dev/null 2>&1
echo " Created folder server/${repo}.git"
cd ${root}/clients/user${i}
git clone "file://${root}/server/${repo}.git" ${repo}.git > /dev/null 2>&1
echo " Cloned under clients/user${i}/${repo}.git"
cd ${root}/clients/user${i}/${repo}.git
git config user.name "User${i}"
git config user.email "user${i}@gittraining.com"
git config branch.autosetuprebase never
git config branch.autosetupmerge true
git config branch.master.rebase false
git config alias.la "log --graph --all --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
git config alias.lb "log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
git config alias.lf "log --format=fuller"
git config alias.l1 "log --stat --pretty=oneline"
echo " Applied initial git configurations"
done
echo "1 bare repository and ${user_count} clients are created. Ready for practicing."