From 439a262ec4f9f9a3dd73a69d17f3ef3765036dec Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sat, 25 May 2013 20:22:54 +0200 Subject: [PATCH] Add simple hook management Introduces a new user configuration variable `hook-alist', which specifies which hooks to link to which executables, for example: ,---- | (set! hook-alist '(("commit-msg" . "/path/to/my/commit/msg/hook"))) `---- With this setting the command `config hooks' will install `/path/to/my/commit/msg/hook' to the `commit-msg' hook of each repository not in the `config-exclusion-list' setting. --- gitto/config.scm | 12 ++++++++++++ gitto/main.scm | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gitto/config.scm b/gitto/config.scm index dcaecf0..6726e66 100644 --- a/gitto/config.scm +++ b/gitto/config.scm @@ -21,12 +21,24 @@ #:use-module (ice-9 format) #:use-module (ice-9 rdelim) #:export (global-config + hook-alist + install-hooks merge-config read-config write-config)) (define global-config '()) +(define hook-alist '()) + +(define (install-hooks repo-location) + (for-each + (lambda (hook) + (let ((new-name (string-append repo-location "/.git/hooks/" + (car hook)))) + (unless (file-exists? new-name) + (symlink (cdr hook) new-name)))) + hook-alist)) (define (merge-config repo-name x y) (let ((lst (if x (list-copy x) '()))) diff --git a/gitto/main.scm b/gitto/main.scm index c162a10..7cb98a9 100644 --- a/gitto/main.scm +++ b/gitto/main.scm @@ -65,6 +65,7 @@ gitto [command [arguments ...]] config global Show template configuration config update Merge template configuration with each repository's configuration + config hooks Install configured hooks for repositories version Display version help Display this help ")) @@ -180,7 +181,12 @@ gitto [command [arguments ...]] (newline)) repositories)) ((equal? (car args) "global") (show-global-config)) - ((equal? (car args) "update") (update-config)))) + ((equal? (car args) "update") (update-config)) + ((equal? (car args) "hooks") + (for-each (lambda (r) + (unless (member (repo-name r) config-exclusion-list) + (install-hooks (repo-location r)))) + repositories)))) (set! command-list (append command-list `(("config" . ,show-config)))) (define (update-repo-config repo)