diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el index 033cb27e33..e5c5e16a17 100644 --- a/lisp/vc/vc-dir.el +++ b/lisp/vc/vc-dir.el @@ -879,7 +879,9 @@ vc-dir-ignore (vc-ignore (vc-dir-fileinfo->name filearg)) t)) vc-ewoc) - (vc-ignore (vc-dir-current-file)))) + (vc-ignore + (file-relative-name (vc-dir-current-file)) + default-directory))) (defun vc-dir-current-file () (let ((node (ewoc-locate vc-ewoc))) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index ec252b74d4..72bd4d3910 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1406,16 +1406,21 @@ vc-ignore prefix argument is given, in which case prompt for a file FILE to remove from the list of ignored files." (interactive - (list - (if (not current-prefix-arg) - (read-file-name "File to ignore: ") - (completing-read - "File to remove: " - (vc-call-backend - (or (vc-responsible-backend default-directory) - (error "Unknown backend")) - 'ignore-completion-table default-directory))) - nil current-prefix-arg)) + (let* ((backend (vc-responsible-backend default-directory)) + (rel-dir + (condition-case nil + (file-name-directory + (vc-call-backend backend 'find-ignore-file + default-directory)) + (vc-not-supported + default-directory))) + (file (read-file-name "File to ignore: "))) + (when (and (file-name-absolute-p file) + (file-in-directory-p file rel-dir)) + (setq file (file-relative-name file rel-dir))) + (list file + rel-dir + current-prefix-arg))) (let* ((directory (or directory default-directory)) (backend (or (vc-responsible-backend default-directory) (error "Unknown backend")))) @@ -1423,23 +1428,18 @@ vc-ignore (defun vc-default-ignore (backend file &optional directory remove) "Ignore FILE under the VCS of DIRECTORY (default is `default-directory'). -FILE is a wildcard specification, either relative to -DIRECTORY or absolute. +FILE is a wildcard specification relative to DIRECTORY. When called from Lisp code, if DIRECTORY is non-nil, the repository to use will be deduced by DIRECTORY; if REMOVE is non-nil, remove FILE from ignored files. Argument BACKEND is the backend you are using." (let ((ignore - (vc-call-backend backend 'find-ignore-file (or directory default-directory))) - file-path root-dir pattern) - (setq file-path (expand-file-name file directory)) - (setq root-dir (file-name-directory ignore)) - (when (not (string= (substring file-path 0 (length root-dir)) root-dir)) - (error "Ignore spec %s is not below project root %s" file-path root-dir)) - (setq pattern (substring file-path (length root-dir))) + (vc-call-backend backend + 'find-ignore-file + (or directory default-directory)))) (if remove - (vc--remove-regexp (concat "^" (regexp-quote pattern ) "\\(\n\\|$\\)") ignore) - (vc--add-line pattern ignore)))) + (vc--remove-regexp (concat "^" (regexp-quote file) "\\(\n\\|$\\)") ignore) + (vc--add-line file ignore)))) (defun vc-default-ignore-completion-table (backend file) "Return the list of ignored files under BACKEND."