[PATCH] Added example hook script to save/restore permissions/ownership.

Previous thread: Re: [RFC] Convert builin-mailinfo.c to use The Better String Library. by James Antill on Monday, September 10, 2007 - 1:49 pm. (1 message)

Next thread: [PATCH] Fix a test failure (t9500-*.sh) on cygwin by Ramsay Jones on Tuesday, September 11, 2007 - 2:16 pm. (2 messages)
To: <git@...>
Cc: Josh England <jjengla@...>
Date: Tuesday, September 11, 2007 - 12:59 pm

The post_merge hook enables one to hook in for `git pull` operations in order
to check and/or change attributes of a work tree from the hook. As an example,
it can be used in combination with a pre-commit hook to save/restore file
ownership and permissions data (or file ACLs) within the repository and
transparently update the working tree after a `git pull` operation.

Signed-off-by: Josh England <jjengla@sandia.gov>
---

Round two for the post_merge hook. Let me know if I missed anything.

Documentation/hooks.txt | 12 +++++++++
git-merge.sh | 13 ++++++++++
t/t5402-post-merge-hook.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 81 insertions(+), 0 deletions(-)
create mode 100755 t/t5402-post-merge-hook.sh

diff --git a/Documentation/hooks.txt b/Documentation/hooks.txt
index c39edc5..50535a7 100644
--- a/Documentation/hooks.txt
+++ b/Documentation/hooks.txt
@@ -87,6 +87,18 @@ parameter, and is invoked after a commit is made.
This hook is meant primarily for notification, and cannot affect
the outcome of `git-commit`.

+post-merge
+-----------
+
+This hook is invoked by `git-merge`, which happens when a `git pull`
+is done on a local repository. The hook takes a single parameter, a status
+flag specifying whether or not the merge being done was a squash merge.
+This hook cannot affect the outcome of `git-merge`.
+
+This hook can be used in conjunction with a corresponding pre-commit hook to
+save and restore any form of metadata associated with the working tree
+(eg: permissions/ownership, ACLS, etc).
+
[[pre-receive]]
pre-receive
-----------
diff --git a/git-merge.sh b/git-merge.sh
index 3a01db0..66e48b3 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -97,6 +97,19 @@ finish () {
fi
;;
esac
+
+ # Run a post-merge hook
+ if test -x "$GIT_DIR"/hooks/post-merge
+ then
+ case "$squash" in
+ t)
+ "$GIT_DIR"/hooks/post-merge 1
+ ;;
+ '')
+ ...

To: <git@...>
Cc: Josh England <jjengla@...>
Date: Tuesday, September 11, 2007 - 12:59 pm

Usage info is emebed in the script, but the gist of it is to run the script
from a pre-commit hook to save permissions/ownership data to a file and check
that file into the repository. Then, a post_merge hook reads the file and
updates working tree permissions/ownership. All updates are transparent to
the user (although there is a --verbose option). Merge conflicts are handled
in the "read" phase (in pre-commit), and the script aborts the commit and
tells you how to fix things in the case of a merge conflict in the metadata
file. This same idea could be extended to handle file ACLs or other file
metadata if desired.

Signed-off-by: Josh England <jjengla@sandia.gov>
---

This script sorta requires the post-merge hook to work really well.

Documentation/hooks.txt | 3 +-
contrib/hooks/setgitperms.perl | 213 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 215 insertions(+), 1 deletions(-)
create mode 100644 contrib/hooks/setgitperms.perl

diff --git a/Documentation/hooks.txt b/Documentation/hooks.txt
index 50535a7..58b9547 100644
--- a/Documentation/hooks.txt
+++ b/Documentation/hooks.txt
@@ -97,7 +97,8 @@ This hook cannot affect the outcome of `git-merge`.

This hook can be used in conjunction with a corresponding pre-commit hook to
save and restore any form of metadata associated with the working tree
-(eg: permissions/ownership, ACLS, etc).
+(eg: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
+for an example of how to do this.

[[pre-receive]]
pre-receive
diff --git a/contrib/hooks/setgitperms.perl b/contrib/hooks/setgitperms.perl
new file mode 100644
index 0000000..b3fb446
--- /dev/null
+++ b/contrib/hooks/setgitperms.perl
@@ -0,0 +1,213 @@
+#!/usr/bin/perl
+#
+# Copyright (c) 2006 Josh England
+#
+# This script can be used to save/restore full permissions and ownership data
+# within a git working tree.
+#
+# To save permissions/ownership data, place this script in your .git/hooks
+# directory and ena...

Previous thread: Re: [RFC] Convert builin-mailinfo.c to use The Better String Library. by James Antill on Monday, September 10, 2007 - 1:49 pm. (1 message)

Next thread: [PATCH] Fix a test failure (t9500-*.sh) on cygwin by Ramsay Jones on Tuesday, September 11, 2007 - 2:16 pm. (2 messages)