diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2015-12-08 15:22:27 +0100 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2016-05-07 16:11:22 +0200 |
| commit | ed0beff6beb5b80177068188228093bf5bf4b298 (patch) | |
| tree | c61c76c57a7789562f16106ce91923d3d52ae58d /lisp/magit-subtree.el | |
| parent | 09ca09640e4d8e28b010d8d14712e7bc5b4fa641 (diff) | |
add support for git-subtree
Diffstat (limited to 'lisp/magit-subtree.el')
| -rw-r--r-- | lisp/magit-subtree.el | 140 |
1 files changed, 140 insertions, 0 deletions
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 |
