aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2015-12-08 15:22:27 +0100
committerJonas Bernoulli <jonas@bernoul.li>2016-05-07 16:11:22 +0200
commited0beff6beb5b80177068188228093bf5bf4b298 (patch)
treec61c76c57a7789562f16106ce91923d3d52ae58d /lisp
parent09ca09640e4d8e28b010d8d14712e7bc5b4fa641 (diff)
add support for git-subtree
Diffstat (limited to 'lisp')
-rw-r--r--lisp/Makefile1
-rw-r--r--lisp/magit-mode.el1
-rw-r--r--lisp/magit-subtree.el140
-rw-r--r--lisp/magit.el1
4 files changed, 143 insertions, 0 deletions
diff --git a/lisp/Makefile b/lisp/Makefile
index ef4bdbe..739a805 100644
--- a/lisp/Makefile
+++ b/lisp/Makefile
@@ -29,6 +29,7 @@ magit-bisect.elc: magit.elc
magit-stash.elc: magit.elc
magit-blame.elc: magit.elc
magit-submodule.elc: magit.elc
+magit-subtree.elc: magit.elc
magit-ediff.elc: magit.elc
magit-extras.elc: magit.elc
git-rebase.elc: magit.elc
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index ea701a3..dbe26df 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -330,6 +330,7 @@ starts complicating other things, then it will be removed."
(define-key map "m" 'magit-merge-popup)
(define-key map "M" 'magit-remote-popup)
(define-key map "o" 'magit-submodule-popup)
+ (define-key map "O" 'magit-subtree-popup)
(define-key map "P" 'magit-push-popup)
(define-key map "r" 'magit-rebase-popup)
(define-key map "R" 'magit-file-rename)
diff --git a/lisp/magit-subtree.el b/lisp/magit-subtree.el
new file mode 100644
index 0000000..fbfe4a8
--- /dev/null
+++ b/lisp/magit-subtree.el
@@ -0,0 +1,140 @@
+;;; magit-subtree.el --- subtree support for Magit -*- lexical-binding: t -*-
+
+;; Copyright (C) 2011-2015 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.
+
+;;; Code:
+
+(require 'magit)
+
+;;;###autoload (autoload 'magit-subtree-popup "magit-subtree" nil t)
+(magit-define-popup magit-subtree-popup
+ "Popup console for subtree commands."
+ 'magit-commands
+ :man-page "git-subtree"
+ :switches '("Switches for add, merge, push, and pull"
+ (?s "Squash" "--squash")
+ "Switches for split"
+ (?i "Ignore joins" "--ignore-joins")
+ (?j "Rejoin" "--rejoin"))
+ :options '("Options"
+ (?p "Prefix" "--prefix=" magit-subtree-read-prefix)
+ "Options for add, merge, and pull"
+ (?m "Message" "--message=")
+ "Options for split"
+ (?a "Annotate" "--annotate=")
+ (?b "Branch" "--branch=")
+ (?o "Onto" "--onto=" magit-read-branch-or-commit))
+ :actions '((?a "Add" magit-subtree-add)
+ (?m "Merge" magit-subtree-merge)
+ (?p "Push" magit-subtree-push)
+ (?c "Add commit" magit-subtree-add-commit)
+ (?f "Pull" magit-subtree-pull)
+ (?s "Split" magit-subtree-split))
+ :max-action-columns 3)
+
+(defun magit-subtree-prefix (prompt)
+ (--if-let (--first (string-prefix-p "--prefix=" it)
+ (magit-subtree-arguments))
+ (substring it 9)
+ (let* ((insert-default-directory nil)
+ (topdir (magit-toplevel))
+ (prefix (read-directory-name (concat prompt ": ") topdir)))
+ (if (file-name-absolute-p prefix)
+ ;; At least `ido-mode's variant is not compatible.
+ (if (string-prefix-p topdir prefix)
+ (file-relative-name prefix topdir)
+ (user-error "%s isn't inside the repository at %s" prefix topdir))
+ prefix))))
+
+(defun magit-subtree-args ()
+ (-filter (lambda (arg)
+ (if (eq this-command 'magit-subtree-split)
+ (or (equal arg "--ignore-joins")
+ (equal arg "--rejoin")
+ (string-prefix-p "--annotate=" arg)
+ (string-prefix-p "--branch=" arg)
+ (string-prefix-p "--onto=" arg))
+ (or (equal arg "--squash")
+ (and (string-prefix-p "--message=" arg)
+ (not (eq this-command 'magit-subtree-push))))))
+ (magit-subtree-arguments)))
+
+(defun magit-git-subtree (subcmd prefix &rest args)
+ (magit-run-git-async "subtree" subcmd (concat "--prefix=" prefix) args))
+
+;;;###autoload
+(defun magit-subtree-add (prefix repository commit args)
+ "Add COMMIT from REPOSITORY as a new subtree at PREFIX."
+ (interactive (list (magit-subtree-prefix "Add subtree")
+ (magit-read-string-ns "Repository")
+ (magit-read-string-ns "Commit")
+ (magit-subtree-args)))
+ (magit-git-subtree "add" prefix args repository commit))
+
+;;;###autoload
+(defun magit-subtree-add-commit (prefix commit args)
+ "Add COMMIT as a new subtree at PREFIX."
+ (interactive (list (magit-subtree-prefix "Add subtree")
+ (magit-read-string-ns "Commit")
+ (magit-subtree-args)))
+ (magit-git-subtree "add" prefix args commit))
+
+;;;###autoload
+(defun magit-subtree-merge (prefix commit args)
+ "Merge COMMIT into the PREFIX subtree."
+ (interactive (list (magit-subtree-prefix "Merge into subtree")
+ (magit-read-string-ns "Commit")
+ (magit-subtree-args)))
+ (magit-git-subtree "merge" prefix args commit))
+
+;;;###autoload
+(defun magit-subtree-pull (prefix repository commit args)
+ "Pull COMMIT from REPOSITORY into the PREFIX subtree."
+ (interactive (list (magit-subtree-prefix "Pull into subtree")
+ (magit-read-string-ns "From repository")
+ (magit-read-string-ns "Commit")
+ (magit-subtree-args)))
+ (magit-git-subtree "pull" prefix args repository commit))
+
+;;;###autoload
+(defun magit-subtree-push (prefix repository ref args)
+ "Extract the history of the subtree PREFIX and push it to REF on REPOSITORY."
+ (interactive (list (magit-subtree-prefix "Push subtree")
+ (magit-read-string-ns "To repository")
+ (magit-read-string-ns "To reference")
+ (magit-subtree-args)))
+ (magit-git-subtree "push" prefix args repository ref))
+
+;;;###autoload
+(defun magit-subtree-split (prefix commit args)
+ "Extract the history of the subtree PREFIX."
+ (interactive (list (magit-subtree-prefix "Split subtree")
+ (magit-read-string-ns "Commit")
+ (magit-subtree-args)))
+ (magit-git-subtree "split" prefix args commit))
+
+;;; magit-subtree.el ends soon
+(provide 'magit-subtree)
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; End:
+;;; magit-subtree.el ends here
diff --git a/lisp/magit.el b/lisp/magit.el
index 8aa15b6..f7ed781 100644
--- a/lisp/magit.el
+++ b/lisp/magit.el
@@ -2974,6 +2974,7 @@ doesn't find the executable, then consult the info node
(require 'magit-blame)
(unless (load "magit-autoloads" t t)
(require 'magit-submodule)
+ (require 'magit-subtree)
(require 'magit-ediff)
(require 'magit-extras)
(require 'git-rebase)))