-
Notifications
You must be signed in to change notification settings - Fork 0
/
plantuml.pre-commit.sh
41 lines (27 loc) · 1.13 KB
/
plantuml.pre-commit.sh
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
#!/bin/bash
exitIfPlantJarNotFound () {
if [[ ! -f "$1" ]]; then
echo "plantuml.jar file cannot be found in your project directory"
exit 1;
fi
}
echo "Running pre-commit to check for staged files to convert to plantuml diagrams"
# plantuml.jar file should be placed at the project directory
plantJarFile="$(dirname $(git rev-parse --git-dir))/plantuml.jar"
exitIfPlantJarNotFound $plantJarFile
plantUmlFilesToGenerate="";
diagramFilesToAddToGitCommit="";
while read status plantUmlFile; do
plantUmlFileWithoutExtension=${plantUmlFile%%.*}
# clean up image file
if [[ $status == 'D' ]]; then
rm "${plantUmlFileWithoutExtension}.png"
fi
if [[ $status == 'A' ]] || [[ $status == 'M' ]]; then
plantUmlFilesToGenerate="${plantUmlFilesToGenerate} ${plantUmlFile}"
diagramFilesToAddToGitCommit="${diagramFilesToAddToGitCommit} ${plantUmlFileWithoutExtension%%.*}.png"
fi
done <<< "$(git diff-index --cached HEAD --name-status | grep '\.puml$')"
echo "Generating plantuml diagrams for $plantUmlFilesToGenerate"
java -jar $plantJarFile -progress $plantUmlFilesToGenerate
git add $diagramFilesToAddToGitCommit