File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,14 +5,27 @@ filter_formattable_files() {
55 grep -E ' \.(h|cpp|c|cc|hpp|tpp|proto|py|md|yml)$|/BUILD$'
66}
77
8+ # Output the modification time of a file (or 0 if nonexistent)
9+ get_mtime () {
10+ case " $( uname -s) " in
11+ Darwin* )
12+ stat -f %m " $1 " 2> /dev/null || echo 0
13+ ;;
14+ * )
15+ # No one will run this on BSD or other Unixes, so this should be fine
16+ stat -c %Y " $1 " 2> /dev/null || echo 0
17+ ;;
18+ esac
19+ }
20+
821# Find repo root, marker for the current branch, and marker mtime (0 if marker does not exist)
922toplevel=" $( git rev-parse --show-toplevel) "
1023marker=" $toplevel /scripts/.format_markers/$( git rev-parse --abbrev-ref HEAD) "
11- mtime=$( stat -c %Y " $marker " 2> /dev/null || echo 0 )
24+ mtime=$( get_mtime " $marker " )
1225
1326git diff --staged --name-only | filter_formattable_files | while read -r file; do
1427 # Compare marker mtime with file mtime
15- if [ $mtime -lt " $( stat -c %Y " $toplevel /$file " ) " ]; then
28+ if [ $mtime -lt $( get_mtime " $toplevel /$file " ) ]; then
1629 # The file was modified AFTER formatting. Remove the marker to tell the pre-push hook
1730 # that this commit introduces unformatted code.
1831 rm -f " $marker " 2> /dev/null
You can’t perform that action at this time.
0 commit comments