1
+ # To avoid running this pre-commit simply write your commit like:
2
+ # git commit -m "test commit" --no-verify
3
+ # with the --no-verify flag being the operative addition
4
+
5
+ printf "\e[33;1m%s\e[0m\n" 'Pre-Commit'
6
+
7
+ # Undo the stash of the files
8
+ pop_stash_files () {
9
+ if [ -n "$hasChanges" ]; then
10
+ printf "\e[33;1m%s\e[0m\n" '=== Applying git stash changes ==='
11
+ git stash pop
12
+ fi
13
+ }
14
+
15
+ # Stash unstaged files
16
+ hasChanges=$(git diff)
17
+ if [ -n "$hasChanges" ]; then
18
+ printf "\e[33;1m%s\e[0m\n" 'Stashing unstaged changes'
19
+ git stash push --keep-index
20
+ fi
21
+
22
+ # Flutter import sorter
23
+ printf "\e[33;1m%s\e[0m\n" '=== Running Dart import sorter ==='
24
+ dart run import_sorter:main
25
+ hasNewFilesSorted=$(git diff)
26
+ if [ -n "$hasNewFilesSorted" ]; then
27
+ git add .
28
+ printf "\e[33;1m%s\e[0m\n" 'Sorted imports added to git stage'
29
+ fi
30
+ printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter import sorter'
31
+ printf '%s\n' "${avar}"
32
+
33
+ # Dart fix
34
+ printf "\e[33;1m%s\e[0m\n" '=== Running Dart fix ==='
35
+ dart fix --apply
36
+ hasNewFilesFixed=$(git diff)
37
+ if [ -n "$hasNewFilesFixed" ]; then
38
+ git add .
39
+ printf "\e[33;1m%s\e[0m\n" 'Dart fix files added to git stage'
40
+ fi
41
+ printf "\e[33;1m%s\e[0m\n" 'Finished running Dart fix'
42
+ printf '%s\n' "${avar}"
43
+
44
+ # Dart formatter
45
+ printf "\e[33;1m%s\e[0m\n" '=== Running Dart formatter ==='
46
+ dart format .
47
+
48
+ hasNewFilesFormatted=$(git diff)
49
+ if [ -n "$hasNewFilesFormatted" ]; then
50
+ git add .
51
+ printf "\e[33;1m%s\e[0m\n" 'Formatted files added to git stage'
52
+ fi
53
+ printf "\e[33;1m%s\e[0m\n" 'Finished running Dart Formatter'
54
+ printf '%s\n' "${avar}"
55
+
56
+ # Flutter Analyzer
57
+ printf "\e[33;1m%s\e[0m\n" '=== Running Flutter analyzer ==='
58
+ flutter analyze
59
+
60
+ if [ $? -ne 0 ]; then
61
+ printf "\e[31;1m%s\e[0m\n" '=== Flutter analyzer error ==='
62
+ pop_stash_files
63
+ exit 1
64
+ fi
65
+
66
+ printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter analyzer'
67
+ printf '%s\n' "${avar}"
68
+
69
+
70
+ # Unit tests
71
+ # printf "\e[33;1m%s\e[0m\n" '=== Running Unit Tests ==='
72
+ # flutter test -r expanded
73
+
74
+ # if [ $? -ne 0 ]; then
75
+ # printf "\e[31;1m%s\e[0m\n" '=== Unit tests error ==='
76
+ # pop_stash_files
77
+ # exit 1
78
+ # fi
79
+
80
+ # printf "\e[33;1m%s\e[0m\n" 'Finished running Unit Tests'
81
+ # printf '%s\n' "${avar}"
82
+
83
+ pop_stash_files
84
+
85
+ printf "\e[33;1m%s\e[0m\n" 'Finished all tasks'
0 commit comments