diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2018-10-21 16:01:23 +0200 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2018-10-21 16:01:23 +0200 |
| commit | 504ad7a46a0f308fd01dca4856a89a0c8078d779 (patch) | |
| tree | beef96cc6b5eca81e75aa42aaf54f6782a3e59fa /lisp | |
| parent | 9efcb1e8b0daa3327f179ffe934d063b8ce1e01a (diff) | |
Split magit-extras.el into multiple libraries
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/Makefile | 1 | ||||
| -rw-r--r-- | lisp/magit-extras.el | 61 | ||||
| -rw-r--r-- | lisp/magit-gitignore.el | 95 |
3 files changed, 96 insertions, 61 deletions
diff --git a/lisp/Makefile b/lisp/Makefile index 0a739db..9122f35 100644 --- a/lisp/Makefile +++ b/lisp/Makefile @@ -52,6 +52,7 @@ magit-obsolete.elc: magit.elc magit-submodule.elc: magit.elc magit-subtree.elc: magit.elc magit-ediff.elc: magit.elc +magit-gitignore.elc: magit.elc magit-extras.elc: magit.elc magit-merge.elc git-rebase.elc: magit.elc magit-imenu.elc: magit.elc git-rebase.elc diff --git a/lisp/magit-extras.el b/lisp/magit-extras.el index 693a52a..9198e91 100644 --- a/lisp/magit-extras.el +++ b/lisp/magit-extras.el @@ -238,67 +238,6 @@ with two prefix arguments remove ignored files only. (put 'magit-clean 'disabled t) -;;; Gitignore - -;;;###autoload (autoload 'magit-gitignore-popup "magit-extras" nil t) -(magit-define-popup magit-gitignore-popup - "Popup console for gitignore commands." - :man-page "gitignore" - :actions '((?l "ignore locally" magit-gitignore-locally) - (?g "ignore globally" magit-gitignore-globally)) - :max-action-columns 1) - -;;;###autoload -(defun magit-gitignore-globally (file-or-pattern) - "Instruct Git to globally ignore FILE-OR-PATTERN." - (interactive (list (magit-gitignore-read-pattern nil))) - (magit--gitignore file-or-pattern nil)) - -;;;###autoload -(defun magit-gitignore-locally (file-or-pattern) - "Instruct Git to locally ignore FILE-OR-PATTERN." - (interactive (list (magit-gitignore-read-pattern t))) - (magit--gitignore file-or-pattern t)) - -(defun magit--gitignore (file-or-pattern local) - (let ((gitignore - (if local - (magit-git-dir (convert-standard-filename "info/exclude")) - (expand-file-name ".gitignore" (magit-toplevel))))) - (make-directory (file-name-directory gitignore) t) - (with-temp-buffer - (when (file-exists-p gitignore) - (insert-file-contents gitignore)) - (goto-char (point-max)) - (unless (bolp) - (insert "\n")) - (insert (replace-regexp-in-string "\\(\\\\*\\)" "\\1\\1" file-or-pattern)) - (insert "\n") - (write-region nil nil gitignore)) - (if local - (magit-refresh) - (magit-run-git "add" ".gitignore")))) - -(defun magit-gitignore-read-pattern (local) - (let* ((default (magit-current-file)) - (choices - (delete-dups - (--mapcat - (cons (concat "/" it) - (when-let ((ext (file-name-extension it))) - (list (concat "/" (file-name-directory "foo") "*." ext) - (concat "*." ext)))) - (magit-untracked-files))))) - (when default - (setq default (concat "/" default)) - (unless (member default choices) - (setq default (concat "*." (file-name-extension default))) - (unless (member default choices) - (setq default nil)))) - (magit-completing-read (concat "File or pattern to ignore" - (and local " locally")) - choices nil nil nil nil default))) - ;;; ChangeLog ;;;###autoload diff --git a/lisp/magit-gitignore.el b/lisp/magit-gitignore.el new file mode 100644 index 0000000..c70d08a --- /dev/null +++ b/lisp/magit-gitignore.el @@ -0,0 +1,95 @@ +;;; magit-gitignore.el --- intentionally untracked files -*- lexical-binding: t -*- + +;; Copyright (C) 2008-2018 The Magit Project Contributors +;; +;; You should have received a copy of the AUTHORS.md file which +;; lists all contributors. If not, see http://magit.vc/authors. + +;; Author: Jonas Bernoulli <jonas@bernoul.li> +;; Maintainer: Jonas Bernoulli <jonas@bernoul.li> + +;; Magit 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, or (at your option) +;; any later version. +;; +;; Magit 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 Magit. If not, see http://www.gnu.org/licenses. + +;;; Commentary: + +;; This library implements gitignore commands. + +;;; Code: + +(require 'magit) + +;;; Commands + +;;;###autoload (autoload 'magit-gitignore-popup "magit-gitignore" nil t) +(magit-define-popup magit-gitignore-popup + "Popup console for gitignore commands." + :man-page "gitignore" + :actions '((?l "ignore locally" magit-gitignore-locally) + (?g "ignore globally" magit-gitignore-globally)) + :max-action-columns 1) + +;;;###autoload +(defun magit-gitignore-globally (file-or-pattern) + "Instruct Git to globally ignore FILE-OR-PATTERN." + (interactive (list (magit-gitignore-read-pattern nil))) + (magit--gitignore file-or-pattern nil)) + +;;;###autoload +(defun magit-gitignore-locally (file-or-pattern) + "Instruct Git to locally ignore FILE-OR-PATTERN." + (interactive (list (magit-gitignore-read-pattern t))) + (magit--gitignore file-or-pattern t)) + +(defun magit--gitignore (file-or-pattern local) + (let ((gitignore + (if local + (magit-git-dir (convert-standard-filename "info/exclude")) + (expand-file-name ".gitignore" (magit-toplevel))))) + (make-directory (file-name-directory gitignore) t) + (with-temp-buffer + (when (file-exists-p gitignore) + (insert-file-contents gitignore)) + (goto-char (point-max)) + (unless (bolp) + (insert "\n")) + (insert (replace-regexp-in-string "\\(\\\\*\\)" "\\1\\1" file-or-pattern)) + (insert "\n") + (write-region nil nil gitignore)) + (if local + (magit-refresh) + (magit-run-git "add" ".gitignore")))) + +(defun magit-gitignore-read-pattern (local) + (let* ((default (magit-current-file)) + (choices + (delete-dups + (--mapcat + (cons (concat "/" it) + (when-let ((ext (file-name-extension it))) + (list (concat "/" (file-name-directory "foo") "*." ext) + (concat "*." ext)))) + (magit-untracked-files))))) + (when default + (setq default (concat "/" default)) + (unless (member default choices) + (setq default (concat "*." (file-name-extension default))) + (unless (member default choices) + (setq default nil)))) + (magit-completing-read (concat "File or pattern to ignore" + (and local " locally")) + choices nil nil nil nil default))) + +;;; _ +(provide 'magit-gitignore) +;;; magit-gitignore.el ends here |
