Klimi's new dotfiles with stow.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

200 lignes
6.6 KiB

il y a 4 ans
  1. ;;; magit-notes.el --- notes support -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2010-2019 The Magit Project Contributors
  3. ;;
  4. ;; You should have received a copy of the AUTHORS.md file which
  5. ;; lists all contributors. If not, see http://magit.vc/authors.
  6. ;; Author: Jonas Bernoulli <jonas@bernoul.li>
  7. ;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
  8. ;; Magit is free software; you can redistribute it and/or modify it
  9. ;; under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; Magit is distributed in the hope that it will be useful, but WITHOUT
  14. ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  16. ;; License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with Magit. If not, see http://www.gnu.org/licenses.
  20. ;;; Commentary:
  21. ;; This library implements support for `git-notes'.
  22. ;;; Code:
  23. (require 'magit)
  24. ;;; Commands
  25. ;;;###autoload (autoload 'magit-notes "magit" nil t)
  26. (define-transient-command magit-notes ()
  27. "Edit notes attached to commits."
  28. :man-page "git-notes"
  29. ["Configure local settings"
  30. ("c" magit-core.notesRef)
  31. ("d" magit-notes.displayRef)]
  32. ["Configure global settings"
  33. ("C" magit-global-core.notesRef)
  34. ("D" magit-global-notes.displayRef)]
  35. ["Arguments for prune"
  36. :if-not magit-notes-merging-p
  37. ("-n" "Dry run" ("-n" "--dry-run"))]
  38. ["Arguments for edit and remove"
  39. :if-not magit-notes-merging-p
  40. (magit-notes:--ref)]
  41. ["Arguments for merge"
  42. :if-not magit-notes-merging-p
  43. (magit-notes:--strategy)]
  44. ["Actions"
  45. :if-not magit-notes-merging-p
  46. ("T" "Edit" magit-notes-edit)
  47. ("r" "Remove" magit-notes-remove)
  48. ("m" "Merge" magit-notes-merge)
  49. ("p" "Prune" magit-notes-prune)]
  50. ["Actions"
  51. :if magit-notes-merging-p
  52. ("c" "Commit merge" magit-notes-merge-commit)
  53. ("a" "Abort merge" magit-notes-merge-abort)])
  54. (defun magit-notes-merging-p ()
  55. (let ((dir (magit-git-dir "NOTES_MERGE_WORKTREE")))
  56. (and (file-directory-p dir)
  57. (directory-files dir nil "^[^.]"))))
  58. (define-infix-command magit-core.notesRef ()
  59. :class 'magit--git-variable
  60. :variable "core.notesRef"
  61. :reader 'magit-notes-read-ref
  62. :prompt "Set local core.notesRef")
  63. (define-infix-command magit-notes.displayRef ()
  64. :class 'magit--git-variable
  65. :variable "notes.displayRef"
  66. :multi-value t
  67. :reader 'magit-notes-read-refs
  68. :prompt "Set local notes.displayRef")
  69. (define-infix-command magit-global-core.notesRef ()
  70. :class 'magit--git-variable
  71. :variable "core.notesRef"
  72. :reader 'magit-notes-read-ref
  73. :prompt "Set global core.notesRef")
  74. (define-infix-command magit-global-notes.displayRef ()
  75. :class 'magit--git-variable
  76. :variable "notes.displayRef"
  77. :multi-value t
  78. :reader 'magit-notes-read-refs
  79. :prompt "Set global notes.displayRef")
  80. (define-infix-argument magit-notes:--ref ()
  81. :description "Merge strategy"
  82. :class 'transient-option
  83. :key "-r"
  84. :argument "--ref="
  85. :reader 'magit-notes-read-ref)
  86. (define-infix-argument magit-notes:--strategy ()
  87. :description "Merge strategy"
  88. :class 'transient-option
  89. :shortarg "-s"
  90. :argument "--strategy="
  91. :choices '("manual" "ours" "theirs" "union" "cat_sort_uniq"))
  92. (defun magit-notes-edit (commit &optional ref)
  93. "Edit the note attached to COMMIT.
  94. REF is the notes ref used to store the notes.
  95. Interactively or when optional REF is nil use the value of Git
  96. variable `core.notesRef' or \"refs/notes/commits\" if that is
  97. undefined."
  98. (interactive (magit-notes-read-args "Edit notes"))
  99. (magit-run-git-with-editor "notes" (and ref (concat "--ref=" ref))
  100. "edit" commit))
  101. (defun magit-notes-remove (commit &optional ref)
  102. "Remove the note attached to COMMIT.
  103. REF is the notes ref from which the note is removed.
  104. Interactively or when optional REF is nil use the value of Git
  105. variable `core.notesRef' or \"refs/notes/commits\" if that is
  106. undefined."
  107. (interactive (magit-notes-read-args "Remove notes"))
  108. (magit-run-git-with-editor "notes" (and ref (concat "--ref=" ref))
  109. "remove" commit))
  110. (defun magit-notes-merge (ref)
  111. "Merge the notes ref REF into the current notes ref.
  112. The current notes ref is the value of Git variable
  113. `core.notesRef' or \"refs/notes/commits\" if that is undefined.
  114. When there are conflicts, then they have to be resolved in the
  115. temporary worktree \".git/NOTES_MERGE_WORKTREE\". When
  116. done use `magit-notes-merge-commit' to finish. To abort
  117. use `magit-notes-merge-abort'."
  118. (interactive (list (magit-read-string-ns "Merge reference")))
  119. (magit-run-git-with-editor "notes" "merge" ref))
  120. (defun magit-notes-merge-commit ()
  121. "Commit the current notes ref merge.
  122. Also see `magit-notes-merge'."
  123. (interactive)
  124. (magit-run-git-with-editor "notes" "merge" "--commit"))
  125. (defun magit-notes-merge-abort ()
  126. "Abort the current notes ref merge.
  127. Also see `magit-notes-merge'."
  128. (interactive)
  129. (magit-run-git-with-editor "notes" "merge" "--abort"))
  130. (defun magit-notes-prune (&optional dry-run)
  131. "Remove notes about unreachable commits."
  132. (interactive (list (and (member "--dry-run" (transient-args 'magit-notes)) t)))
  133. (when dry-run
  134. (magit-process-buffer))
  135. (magit-run-git-with-editor "notes" "prune" (and dry-run "--dry-run")))
  136. ;;; Readers
  137. (defun magit-notes-read-ref (prompt _initial-input history)
  138. (--when-let (magit-completing-read
  139. prompt (magit-list-notes-refnames) nil nil
  140. (--when-let (magit-get "core.notesRef")
  141. (if (string-prefix-p "refs/notes/" it)
  142. (substring it 11)
  143. it))
  144. history)
  145. (if (string-prefix-p "refs/" it)
  146. it
  147. (concat "refs/notes/" it))))
  148. (defun magit-notes-read-refs (prompt)
  149. (mapcar (lambda (ref)
  150. (if (string-prefix-p "refs/" ref)
  151. ref
  152. (concat "refs/notes/" ref)))
  153. (completing-read-multiple
  154. (concat prompt ": ")
  155. (magit-list-notes-refnames) nil nil
  156. (mapconcat (lambda (ref)
  157. (if (string-prefix-p "refs/notes/" ref)
  158. (substring ref 11)
  159. ref))
  160. (magit-get-all "notes.displayRef")
  161. ","))))
  162. (defun magit-notes-read-args (prompt)
  163. (list (magit-read-branch-or-commit prompt (magit-stash-at-point))
  164. (--when-let (--first (string-match "^--ref=\\(.+\\)" it)
  165. (transient-args 'magit-notes))
  166. (match-string 1 it))))
  167. ;;; _
  168. (provide 'magit-notes)
  169. ;;; magit-notes.el ends here