Allow directory specification for config update

Add an optional directory parameter to the `config update' and `config
hooks' commands, which, if specified, will limit any updates to the
given repository.
This commit is contained in:
Tom Willemse 2013-11-10 21:32:32 +01:00
parent f81fcc9a8a
commit 442b8f9122

View file

@ -220,12 +220,12 @@ which no longer point to a git repository."
"Show the template specified in `global-config'." "Show the template specified in `global-config'."
(write-config global-config)) (write-config global-config))
(define-command (config #:optional sub) (define-command (config #:optional sub repository)
"Manage your repositories' configurations." "Manage your repositories' configurations."
"Usage: gitto config "Usage: gitto config
gitto config global gitto config global
gitto config update gitto config update [repository]
gitto config hooks gitto config hooks [repository]
The first form prints the configurations for each registered The first form prints the configurations for each registered
repository. repository.
@ -236,10 +236,12 @@ format specifier which can be used to indicate the repository name.
The third form merges the template in and existing configurations, The third form merges the template in and existing configurations,
overwriting settings when necessary. The repositories in the overwriting settings when necessary. The repositories in the
`config-exclusion-list' will be skipped. *Note:* This is a destructive `config-exclusion-list' will be skipped. If REPOSITORY is specified it
operation, you should be mindful. only updates the configuration for that repository. *Note:* This is a
destructive operation, you should be mindful.
The fourth form installs the configured hooks into each repository." The fourth form installs the configured hooks into each repository or
the given repository."
(cond (cond
((not sub) ((not sub)
(for-each (lambda (repo) (for-each (lambda (repo)
@ -250,12 +252,17 @@ The fourth form installs the configured hooks into each repository."
(newline)) (newline))
repositories)) repositories))
((equal? sub "global") (show-global-config)) ((equal? sub "global") (show-global-config))
((equal? sub "update") (update-config)) ((equal? sub "update") (update-config repository))
((equal? sub "hooks") ((equal? sub "hooks")
(for-each (lambda (r) (let ((hookwrapper
(unless (member (repo-name r) config-exclusion-list) (lambda (r)
(install-hooks (repo-location r)))) (unless (member (repo-name r) config-exclusion-list)
repositories)))) (install-hooks (repo-location r))))))
(if repository
(if (known? repository)
(hookwrapper (make <repository> repository))
(format #t "Unknown repository: ~a~%" repository))
(for-each hookwrapper repositories))))))
(define (update-repo-config repo) (define (update-repo-config repo)
"Merge the configured configuration with REPO's configuration. "Merge the configured configuration with REPO's configuration.
@ -268,9 +275,13 @@ Don't do anything if REPO has been added to `config-exclusion-list'."
global-config) global-config)
(string-append (repo-location repo) "/.git/config")))) (string-append (repo-location repo) "/.git/config"))))
(define (update-config) (define* (update-config #:optional repo)
"Merge the configured configuration with all repositories." "Merge the configured configuration with all repositories."
(for-each update-repo-config repositories)) (if repo
(if (known? repo)
(update-repo-config (make <repository> repo))
(format #t "Unknown repository: ~a~%" repo))
(for-each update-repo-config repositories)))
(define (main args) (define (main args)
"Parse the command line options and run the appropriate functions." "Parse the command line options and run the appropriate functions."