Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
6.4 KiB

5 years ago
  1. ;;; magit-subtree.el --- subtree support for Magit -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2011-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. ;;; Code:
  21. (require 'magit)
  22. ;;; Commands
  23. ;;;###autoload (autoload 'magit-subtree "magit-subtree" nil t)
  24. (define-transient-command magit-subtree ()
  25. "Import or export subtrees."
  26. :man-page "git-subtree"
  27. ["Actions"
  28. ("i" "Import" magit-subtree-import)
  29. ("e" "Export" magit-subtree-export)])
  30. ;;;###autoload (autoload 'magit-subtree-import "magit-subtree" nil t)
  31. (define-transient-command magit-subtree-import ()
  32. "Import subtrees."
  33. :man-page "git-subtree"
  34. ["Arguments"
  35. (magit-subtree:--prefix)
  36. (magit-subtree:--message)
  37. ("-s" "Squash" "--squash")]
  38. ["Actions"
  39. [("a" "Add" magit-subtree-add)
  40. ("c" "Add commit" magit-subtree-add-commit)]
  41. [("m" "Merge" magit-subtree-merge)
  42. ("f" "Pull" magit-subtree-pull)]])
  43. ;;;###autoload (autoload 'magit-subtree-export "magit-subtree" nil t)
  44. (define-transient-command magit-subtree-export ()
  45. "Export subtrees."
  46. :man-page "git-subtree"
  47. ["Arguments"
  48. (magit-subtree:--prefix)
  49. (magit-subtree:--annotate)
  50. (magit-subtree:--branch)
  51. (magit-subtree:--onto)
  52. ("-i" "Ignore joins" "--ignore-joins")
  53. ("-j" "Rejoin" "--rejoin")]
  54. ["Actions"
  55. ("p" "Push" magit-subtree-push)
  56. ("s" "Split" magit-subtree-split)])
  57. (define-infix-argument magit-subtree:--prefix ()
  58. :description "Prefix"
  59. :class 'transient-option
  60. :shortarg "-P"
  61. :argument "--prefix="
  62. :reader 'magit-subtree-read-prefix)
  63. (defun magit-subtree-read-prefix (prompt &optional default _history)
  64. (let* ((insert-default-directory nil)
  65. (topdir (magit-toplevel))
  66. (prefix (read-directory-name (concat prompt ": ") topdir default)))
  67. (if (file-name-absolute-p prefix)
  68. ;; At least `ido-mode's variant is not compatible.
  69. (if (string-prefix-p topdir prefix)
  70. (file-relative-name prefix topdir)
  71. (user-error "%s isn't inside the repository at %s" prefix topdir))
  72. prefix)))
  73. (define-infix-argument magit-subtree:--message ()
  74. :description "Message"
  75. :class 'transient-option
  76. :shortarg "-m"
  77. :argument "--message=")
  78. (define-infix-argument magit-subtree:--annotate ()
  79. :description "Annotate"
  80. :class 'transient-option
  81. :key "-a"
  82. :argument "--annotate=")
  83. (define-infix-argument magit-subtree:--branch ()
  84. :description "Branch"
  85. :class 'transient-option
  86. :shortarg "-b"
  87. :argument "--branch=")
  88. (define-infix-argument magit-subtree:--onto ()
  89. :description "Onto"
  90. :class 'transient-option
  91. :key "-o"
  92. :argument "--onto="
  93. :reader 'magit-transient-read-revision)
  94. (defun magit-subtree-prefix (transient prompt)
  95. (--if-let (--first (string-prefix-p "--prefix=" it)
  96. (transient-args transient))
  97. (substring it 9)
  98. (magit-subtree-read-prefix prompt)))
  99. (defun magit-subtree-arguments (transient)
  100. (--remove (string-prefix-p "--prefix=" it)
  101. (transient-args transient)))
  102. (defun magit-git-subtree (subcmd prefix &rest args)
  103. (magit-run-git-async "subtree" subcmd (concat "--prefix=" prefix) args))
  104. ;;;###autoload
  105. (defun magit-subtree-add (prefix repository ref args)
  106. "Add REF from REPOSITORY as a new subtree at PREFIX."
  107. (interactive
  108. (cons (magit-subtree-prefix 'magit-subtree-import "Add subtree")
  109. (let ((remote (magit-read-remote-or-url "From repository")))
  110. (list remote
  111. (magit-read-refspec "Ref" remote)
  112. (magit-subtree-arguments 'magit-subtree-import)))))
  113. (magit-git-subtree "add" prefix args repository ref))
  114. ;;;###autoload
  115. (defun magit-subtree-add-commit (prefix commit args)
  116. "Add COMMIT as a new subtree at PREFIX."
  117. (interactive
  118. (list (magit-subtree-prefix 'magit-subtree-import "Add subtree")
  119. (magit-read-string-ns "Commit")
  120. (magit-subtree-arguments 'magit-subtree-import)))
  121. (magit-git-subtree "add" prefix args commit))
  122. ;;;###autoload
  123. (defun magit-subtree-merge (prefix commit args)
  124. "Merge COMMIT into the PREFIX subtree."
  125. (interactive
  126. (list (magit-subtree-prefix 'magit-subtree-import "Merge into subtree")
  127. (magit-read-string-ns "Commit")
  128. (magit-subtree-arguments 'magit-subtree-import)))
  129. (magit-git-subtree "merge" prefix args commit))
  130. ;;;###autoload
  131. (defun magit-subtree-pull (prefix repository ref args)
  132. "Pull REF from REPOSITORY into the PREFIX subtree."
  133. (interactive
  134. (cons (magit-subtree-prefix 'magit-subtree-import "Pull into subtree")
  135. (let ((remote (magit-read-remote-or-url "From repository")))
  136. (list remote
  137. (magit-read-refspec "Ref" remote)
  138. (magit-subtree-arguments 'magit-subtree-import)))))
  139. (magit-git-subtree "pull" prefix args repository ref))
  140. ;;;###autoload
  141. (defun magit-subtree-push (prefix repository ref args)
  142. "Extract the history of the subtree PREFIX and push it to REF on REPOSITORY."
  143. (interactive (list (magit-subtree-prefix 'magit-subtree-export "Push subtree")
  144. (magit-read-remote-or-url "To repository")
  145. (magit-read-string-ns "To reference")
  146. (magit-subtree-arguments 'magit-subtree-export)))
  147. (magit-git-subtree "push" prefix args repository ref))
  148. ;;;###autoload
  149. (defun magit-subtree-split (prefix commit args)
  150. "Extract the history of the subtree PREFIX."
  151. (interactive (list (magit-subtree-prefix 'magit-subtree-export "Split subtree")
  152. (magit-read-string-ns "Commit")
  153. (magit-subtree-arguments 'magit-subtree-export)))
  154. (magit-git-subtree "split" prefix args commit))
  155. ;;; _
  156. (provide 'magit-subtree)
  157. ;;; magit-subtree.el ends here