-
Notifications
You must be signed in to change notification settings - Fork 10
/
git-generate-changes
executable file
·98 lines (85 loc) · 1.79 KB
/
git-generate-changes
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
88
89
90
91
92
93
94
95
96
#!/bin/bash
set -e
fileNameNumberUpperLimit=100
commentNumberUpperLimit=1000
function getFileName() {
randomNumber=$(( ( RANDOM % $fileNameNumberUpperLimit ) + 1 ))
file="$1$randomNumber.$2"
echo $file
}
function create() {
if [ -f $1 ];
then
echo "Modified file $randomNumber" >> $1
echo -n " ... modified"
else
echo "Created file $randomNumber" >> $1
echo -n " ... created"
fi
}
function isInGitRepo() {
git rev-parse --is-inside-work-tree 2>/dev/null
statusCode=$?
if [ $statusCode -eq 0 ]; then
echo 1
else
echo 0
fi
}
function commitToGitRepo() {
if [ -n "$1" ]; then
git add -A
randomNumber=$(( ( RANDOM % $commentNumberUpperLimit ) + 1 ))
git commit -m "Random changes #${randomNumber}" >/dev/null 2>&1
echo -n ", committed"
fi
}
usage() { echo "USAGE: git-generate-changes -g -p <PREFIX> -c <NUMBER OF COMMITS> -e <EXTENSION>"; exit 1; }
prefix="temp"
count=1
extension="txt"
togit=
realargs="$@"
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
usage
;;
-p | --prefix)
prefix=$2
shift
;;
-c | --count)
count=$2
shift
;;
-e | --extension)
extension=$2
shift
;;
-g | --commit)
togit=1
;;
*)
usage
break
;;
esac
shift
done
set -- $realargs
gitStatus=$(isInGitRepo)
if [ -n "$togit" ] && [ "$gitStatus" == true ]; then
echo "FATAL: The current directory is not in a git repository"
exit 0
fi
counter=1;
while [[ $counter -le "$count" ]];
do
file=$(getFileName $prefix $extension)
echo -n "$file"
create $file
commitToGitRepo $togit
echo ""
let "counter += 1";
done