make: add clang-format prepare-commit-msg hook
To install this hook, run make install-git-commit-clangfmt This will install a pre-commit-msg hook that runs clang-format on all .c and .h files that are staged. It will add a clang-formatted-by: <git username> line to the commit message to indicate that clang-format was run on the files and that further processing of them is not needed. Change-Id: I1773f55b5b4677dad8f4bea017b6328fd93df20c Signed-off-by: Ronald G. Minnich <rminnich@gmail.com> Reviewed-on: https://review.coreboot.org/27779 Reviewed-by: Patrick Georgi <pgeorgi@google.com> Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
		@@ -597,6 +597,9 @@ update:
 | 
				
			|||||||
gitconfig:
 | 
					gitconfig:
 | 
				
			||||||
	util/gitconfig/gitconfig.sh "$(MAKE)"
 | 
						util/gitconfig/gitconfig.sh "$(MAKE)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					install-git-commit-clangfmt:
 | 
				
			||||||
 | 
						cp util/scripts/prepare-commit-msg.clang-format .git/hooks/prepare-commit-msg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include util/crossgcc/Makefile.inc
 | 
					include util/crossgcc/Makefile.inc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: tools
 | 
					.PHONY: tools
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								util/scripts/prepare-commit-msg.clang-format
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										13
									
								
								util/scripts/prepare-commit-msg.clang-format
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					files=`git diff --cached --name-only | grep '\.[ch]$'`
 | 
				
			||||||
 | 
					if [ -z "$files" ]; then
 | 
				
			||||||
 | 
						exit 0
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					# This has to be set here; otherwise a grep error seems to cause
 | 
				
			||||||
 | 
					# us to exit with non-zero status.
 | 
				
			||||||
 | 
					set -e
 | 
				
			||||||
 | 
					clang-format -i $files
 | 
				
			||||||
 | 
					git add $files
 | 
				
			||||||
 | 
					u=`git config user.name`
 | 
				
			||||||
 | 
					m="clang-formatted-by: $u"
 | 
				
			||||||
 | 
					echo $m >> $1
 | 
				
			||||||
		Reference in New Issue
	
	Block a user