[Cmake-commits] CMake branch, hooks, updated. 48e72dd1cd9ebefae0006cba0fafd6a09928bc8c

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Aug 10 17:43:50 EDT 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, hooks has been updated
       via  48e72dd1cd9ebefae0006cba0fafd6a09928bc8c (commit)
      from  8653d286060b71b74b5a89ec7075617a76f81c3e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=48e72dd1cd9ebefae0006cba0fafd6a09928bc8c
commit 48e72dd1cd9ebefae0006cba0fafd6a09928bc8c
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Tue Aug 10 17:30:06 2010 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Tue Aug 10 17:30:06 2010 -0400

    pre-commit: Check submodules staged with other changes
    
    Since Git does not automatically update submodule checkouts when
    checking out a new version in the work tree, it is common to have
    locally modified submodule references.  Therefore it is easy to stage
    such modifications with other changes by accident, especially with
    commands like "git add -u" or "git commit -a".  The result is almost
    always wrong if the submodule change is not intended.
    
    Prevent such mistakes by requiring an extra step to commit submodule
    link updates with other changes.  When this case is detected, print a
    message describing the situation and provide cut-and-paste instructions
    to proceed.

diff --git a/pre-commit b/pre-commit
index 9289382..2399f53 100755
--- a/pre-commit
+++ b/pre-commit
@@ -125,8 +125,61 @@ check_size() {
 	fi
 }
 
-bad=$(git diff-index --cached $against -- |
-sed -n '/^:[^:]/ {s/^://;p;}' |
+short_commit() {
+	git rev-parse --short "$1" 2>/dev/null || echo "$1"
+}
+
+lookup_config_module_update() {
+	# Format is "aaaaaa..bbbbbb" for update aaaaaa => bbbbbb.
+	# Convert to regex "^aaaaaa[a-z0-9]* bbbbbb[a-z0-9]*$".
+	sha1ex='[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]*'
+	regex='^\('"$sha1ex"'\)\.\.\('"$sha1ex"'\)$'
+	git config "hooks.$1.update" |
+	sed -n "/$regex/ {s/$regex/"'^\1[a-z0-9]* \2[a-z0-9]*$/;p;}' |
+	grep '.' # Return false if result is empty.
+}
+
+check_module() {
+	# Allow module-only commits without extra work.
+	test -z "$diffs_normal" && return
+
+	# Check if module update is allowed with other changes.
+	allow=$(lookup_config_module_update "$file") || allow='none'
+	if echo "$src_obj $dst_obj" | grep "$allow" > /dev/null; then
+		return
+	fi
+	src_short=$(short_commit "$src_obj")
+	dst_short=$(short_commit "$dst_obj")
+	echo 'A submodule link is staged for commit (among other changes):
+
+  "'"$file"'"  '"$src_short => $dst_short"'
+
+This may occur by accident so we require an extra step to commit.
+If you intend to include this change in your commit, run
+
+  git config "hooks.'"$file"'.update" '"$src_short..$dst_short"'
+
+to explicitly allow the change and try the commit again.  Otherwise run
+
+  git reset HEAD -- "'"$file"'"
+
+to unstage the change.  Furthermore, if you did not intend to modify
+the submodule at all, also run
+
+  git submodule update -- "'"$file"'"
+
+to checkout the current version of the submodule in your work tree.
+Test your changes again to see if they still work with the module.
+Finally, try the commit again.
+'
+}
+
+diffs=$(git diff-index --cached $against -- |
+        sed -n '/^:[^:]/ {s/^://;p;}')
+diffs_normal=$(echo "$diffs" | grep -v '^...... 160000')
+diffs_module=$(echo "$diffs" | grep    '^...... 160000')
+bad=$(
+test -n "$diffs_normal" && echo "$diffs_normal" |
 while read src_mode dst_mode src_obj dst_obj status file; do
 	if test "$src_mode" != "$dst_mode" -a "$dst_mode" != "000000"; then
 		check_mode
@@ -134,5 +187,10 @@ while read src_mode dst_mode src_obj dst_obj status file; do
 	if test "$dst_mode" != "160000" -a "$dst_mode" != '000000'; then
 		check_size
 	fi
-done)
+done
+test -n "$diffs_module" && echo "$diffs_module" |
+while read src_mode dst_mode src_obj dst_obj status file; do
+	check_module
+done
+)
 test -z "$bad" || die "$bad"

-----------------------------------------------------------------------

Summary of changes:
 pre-commit |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 61 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list