Simplify the remove command

This commit is contained in:
Tom Willemse 2014-03-02 00:01:07 +01:00
parent bc4555b0dd
commit 7a0c947c10

View file

@ -29,6 +29,12 @@
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:export (main)) #:export (main))
(define (canonicalize-filename path)
"Get a canonicalized name for PATH, unless it's already familiar."
(if (member path repositories same-repository?)
path
(realpath path)))
(define (config-dir) (storage-dir "XDG_CONFIG_HOME" "/.config")) (define (config-dir) (storage-dir "XDG_CONFIG_HOME" "/.config"))
(define (config-file file) (string-append (config-dir) "/" file)) (define (config-file file) (string-append (config-dir) "/" file))
@ -72,6 +78,12 @@
(repo-location repo))) (repo-location repo)))
repositories same-repository?))) repositories same-repository?)))
(define (remove-repository repository)
"Remove REPOSITORY from the list of known repositories."
(set! repositories
(delete repository repositories same-repository?))
(save-repositories-list))
(define (save-repositories-list) (define (save-repositories-list)
"Save the list of repositories." "Save the list of repositories."
(ensure-directory-exists. (data-dir)) (ensure-directory-exists. (data-dir))
@ -238,14 +250,11 @@ which no longer point to a git repository."
Removes REPO from the registered repository list. This command will Removes REPO from the registered repository list. This command will
fail if REPO does not indicate a git repository of if it hasn't been fail if REPO does not indicate a git repository of if it hasn't been
registered." registered."
(unless (member repository repositories same-repository?) (set! repository (canonicalize-filename repository))
(set! repository (realpath repository)))
(if (known? repository) (if (known? repository)
(begin (begin
(set! repositories (remove-repository repository)
(delete repository repositories same-repository?))
(save-repositories-list)
(simple-format #t "Repository ~A removed." repository)) (simple-format #t "Repository ~A removed." repository))
(display "Not a registered repository.")) (display "Not a registered repository."))
(newline)) (newline))