aboutsummaryrefslogtreecommitdiff
path: root/lisp/magit-gitignore.el
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2019-01-19 00:10:24 +0100
committerJonas Bernoulli <jonas@bernoul.li>2019-02-03 01:26:00 +0100
commitab78039a03faa47076c66f90c02b5b242c949d87 (patch)
tree0c8ba206a6761f4d642ff7eed8d6412f273f16bd /lisp/magit-gitignore.el
parent26e45568e3cd90f6a062de22ae9673462d286af1 (diff)
magit-gitignore-{in-subdir,on-system}: New commands
Diffstat (limited to 'lisp/magit-gitignore.el')
-rw-r--r--lisp/magit-gitignore.el32
1 files changed, 31 insertions, 1 deletions
diff --git a/lisp/magit-gitignore.el b/lisp/magit-gitignore.el
index 46ad74d..47492e7 100644
--- a/lisp/magit-gitignore.el
+++ b/lisp/magit-gitignore.el
@@ -41,9 +41,15 @@
["Gitignore"
("t" "shared at toplevel (.gitignore)"
magit-gitignore-in-topdir)
+ ("s" "shared in subdirectory (path/to/.gitignore)"
+ magit-gitignore-in-subdir)
("p" "privately (.git/info/exclude)"
magit-gitignore-in-gitdir)
- ])
+ ("g" magit-gitignore-on-system
+ :if (lambda () (magit-get "core.excludesfile"))
+ :description (lambda ()
+ (format "privately for all repositories (%s)"
+ (magit-get "core.excludesfile"))))])
;;;###autoload
(defun magit-gitignore-in-topdir (rule)
@@ -56,6 +62,20 @@ repository. Also stage the file."
(magit-run-git "add" ".gitignore")))
;;;###autoload
+(defun magit-gitignore-in-subdir (rule directory)
+ "Add the Git ignore RULE to a \".gitignore\" file.
+Prompted the user for a directory and add the rule to the
+\".gitignore\" file in that directory. Since such files are
+tracked, they are shared with other clones of the repository.
+Also stage the file."
+ (interactive (list (magit-gitignore-read-pattern)
+ (read-directory-name "Limit rule to files in: ")))
+ (magit-with-toplevel
+ (let ((file (expand-file-name ".gitignore" directory)))
+ (magit--gitignore rule file)
+ (magit-run-git "add" ".gitignore"))))
+
+;;;###autoload
(defun magit-gitignore-in-gitdir (rule)
"Add the Git ignore RULE to \"$GIT_DIR/info/exclude\".
Rules in that file only affects this clone of the repository."
@@ -63,6 +83,16 @@ Rules in that file only affects this clone of the repository."
(magit--gitignore rule (magit-git-dir "info/exclude"))
(magit-refresh))
+;;;###autoload
+(defun magit-gitignore-on-system (rule)
+ "Add the Git ignore RULE to the file specified by `core.excludesFile'.
+Rules that are defined in that file affect all local repositories."
+ (interactive (list (magit-gitignore-read-pattern)))
+ (magit--gitignore rule
+ (or (magit-get "core.excludesFile")
+ (error "Variable `core.excludesFile' isn't set")))
+ (magit-refresh))
+
(defun magit--gitignore (rule file)
(when-let ((directory (file-name-directory file)))
(make-directory directory t))