;; -*- coding: utf-8; -*- ;; gitto -- Keep track of your git repositories ;; Copyright (C) 2012 Tom Willemse ;; This file is part of gitto. ;; gitto is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; gitto is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with gitto. If not, see . (define-module (gitto main) #:use-module (gitto config) #:use-module (gitto git) #:use-module (gitto path) #:use-module (gitto ui) #:use-module (ice-9 format) #:use-module (ice-9 popen) #:use-module (oop goops) #:use-module (srfi srfi-1) #:export (main)) (define-syntax define-command (syntax-rules () ((_ (name . args) exp exp* ...) (begin (set! command-list (cons (cons (symbol->string (quote name)) (case-lambda (args exp exp* ...) (lst (format #t "Wrong number of arguments.~%")))) command-list)))))) (define command-list '()) (define config-exclusion-list '()) (define (storage-dir xdg-env fallback) "Get the location where gitto stores information. XDG-ENV specifies which XDG environment variable should be looked at and FALLBACK specifies the directory to use if XDG-ENV has not been set in the current environment." (let ((xdg (getenv xdg-env))) (string-append (or xdg (getenv "HOME")) (if xdg "" fallback) "/gitto"))) (define (config-dir) (storage-dir "XDG_CONFIG_HOME" "/.config")) (define (config-file file) (string-append (config-dir) "/" file)) (define (data-dir) (storage-dir "XDG_DATA_HOME" "/.local/share")) (define (data-file file) (string-append (data-dir) "/" file)) (define-command (version) "Display version information." (display "gitto 0.1.0") (newline) (display "Copyright (C) 2012 Tom Willemse") (newline) (display "This program comes with ABSOLUTELY NO WARRANTY.") (newline) (display "You may redistribute copies of this program") (newline) (display "under the terms of the GNU General Public License.") (newline) (display "For more information about these matters, see the file named COPYING.") (newline)) (define-command (help) "Display some help." (display "\ gitto [command [arguments ...]] add Register a new repository directory remove Remove a repository directory check Check if a repository has been registered list List all repositories and their status list locations List all registered repositories' locations purge Remove all repositories that don't exist config Show each repository's configuration 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 ")) (define (known? repo) "Do we know REPO?" (or (member repo repositories same-repository?) (member (realpath (if (string? repo) repo (repo-location repo))) repositories same-repository?))) (define (save-repositories-list) "Save the list of repositories." (let ((dir (data-dir))) (unless (file-exists? dir) (mkdir dir))) ;; Sort first (set! repositories (sort repositories (lambda (s1 s2) (string (realpath repository))) (if (not (known? repository)) (begin (set! repositories (append `(,repository) repositories)) (save-repositories-list) (simple-format #t "Repository ~A registered.~%" (repo-name repository)) ;; Ask the user if they would like to merge their config ;; template with the newly registered repository if they have ;; a configuration set-up and the current input port is a tty. (when (and (isatty? (current-input-port)) (not (eq? global-config '())) (y-or-n? "Would you like to merge your settings?" #:default #t)) (update-repo-config repository))) (display "Repository already registered.")) (newline)) (define-command (remove repository) "Remove/unregister REPOSITORY from the repository list." (unless (member repository repositories same-repository?) (set! repository (realpath repository))) (if (known? repository) (begin (set! repositories (delete repository repositories same-repository?)) (save-repositories-list) (simple-format #t "Repository ~A removed." repository)) (display "Not a registered repository.")) (newline)) (define-command (list . args) "List information about every repository." (if (and (not (eq? args '())) (equal? (car args) "locations")) (list-repository-locations) (for-each print repositories))) (define (list-repository-locations) "List the registered locations of repositories." (for-each (lambda (repo) (display (repo-location repo)) (newline)) (sort repositories (lambda (s1 s2) (string repo)) result)) '()))