diff options
| -rwxr-xr-x[l---------] | template/hooks/post-checkout | 13 | ||||
| -rwxr-xr-x[l---------] | template/hooks/post-merge | 4 | ||||
| -rw-r--r-- | util/perms-hook.c | 36 |
3 files changed, 29 insertions, 24 deletions
diff --git a/template/hooks/post-checkout b/template/hooks/post-checkout index acd988a5..2a619e25 120000..100755 --- a/template/hooks/post-checkout +++ b/template/hooks/post-checkout @@ -1 +1,12 @@ -../../libexec/oasis/perms-hook
\ No newline at end of file +#!/bin/sh + +old=$1 +new=$2 + +if [ "$old" = 0000000000000000000000000000000000000000 ] ; then + set "$new" +else + set "$old" "$new" +fi + +exec ./libexec/oasis/perms-hook "$@" diff --git a/template/hooks/post-merge b/template/hooks/post-merge index acd988a5..f69e5466 120000..100755 --- a/template/hooks/post-merge +++ b/template/hooks/post-merge @@ -1 +1,3 @@ -../../libexec/oasis/perms-hook
\ No newline at end of file +#!/bin/sh + +exec ./libexec/oasis/perms-hook ORIG_HEAD HEAD diff --git a/util/perms-hook.c b/util/perms-hook.c index cff6127e..87f79f61 100644 --- a/util/perms-hook.c +++ b/util/perms-hook.c @@ -1,8 +1,8 @@ /* See LICENSE file for copyright and license details. -This program is a git hook to fix the permissions of files based on a .perms -file in the repository +This program is meant to be run by a git hook to fix the permissions of files +based on a .perms file in the repository TODO: We should read the old .perms file, and remove any directories listed there that are not present in the new .perms file. @@ -35,7 +35,6 @@ struct perm { extern char **environ; -static char *argv0; static dev_t rootdev; static struct perm *perms; static int perms_len; @@ -272,28 +271,21 @@ int main(int argc, char *argv[]) { char *old, *new; struct stat st; - argv0 = basename(argv[0]); - if (strcmp(argv0, "post-merge") == 0) { - if (argc != 2) { - fprintf(stderr, "usage: %s flag\n", argv0); - exit(2); - } - old = "ORIG_HEAD"; + switch (argc) { + case 1: + old = NULL; new = "HEAD"; - } else if (strcmp(argv0, "post-checkout") == 0) { - if (argc != 4) { - fprintf(stderr, "usage: %s old new flag\n", argv0); - exit(2); - } + break; + case 2: + old = NULL; + new = argv[1]; + break; + case 3: old = argv[1]; - if (strcmp(old, "0000000000000000000000000000000000000000") == 0) - old = NULL; new = argv[2]; - } else if (argc == 1) { - old = NULL; - new = "HEAD"; - } else { - fprintf(stderr, "usage: %s\n", argv0); + break; + default: + fprintf(stderr, "usage: %s [[old] new]\n", basename(argv[0])); exit(2); } |
