Commit a3d788ec authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-worktree-checkout-pull-request: New command

parent cbfc9ea0
......@@ -40,6 +40,8 @@
:man-page "git-worktree"
:actions '((?b "Create new worktree" magit-worktree-checkout)
(?c "Create new branch and worktree" magit-worktree-branch)
(?p "Create new worktree from pull-request"
magit-worktree-checkout-pull-request)
(?k "Delete worktree" magit-worktree-delete)
(?g "Show status for worktree" magit-worktree-status))
:max-action-columns 1)
......@@ -54,6 +56,35 @@
(magit-run-git "worktree" "add" (expand-file-name path) branch)
(magit-diff-visit-directory path))
(defun magit-worktree-checkout-pull-request (path pr)
"Create, configure and checkout a new worktree from a pull-request.
This is like `magit-checkout-pull-request', except that it
also creates a new worktree. Please see the manual for more
information."
(interactive
(let ((pr (magit-read-pull-request "Checkout pull request")))
(let-alist pr
(let ((path (let ((branch (magit--pullreq-branch pr t)))
(read-directory-name
(format "Checkout #%s as `%s' in new worktree: "
.number branch)
(file-name-directory
(directory-file-name default-directory))
nil nil
(if (string-match-p "\\`pr-[0-9]+\\'" branch)
(number-to-string .number)
(format "%s-%s" .number .head.ref))))))
(when (equal path "")
(user-error "The empty string isn't a valid path"))
(list path pr)))))
(when (and (file-exists-p path)
(not (and (file-directory-p path)
(= (length (directory-files "/tmp/testing/")) 2))))
(user-error "%s already exists and isn't empty" path))
(magit-worktree-checkout path
(let ((inhibit-magit-refresh t))
(magit-branch-pull-request pr))))
;;;###autoload
(defun magit-worktree-branch (path branch start-point &optional force)
"Create a new BRANCH and check it out in a new worktree at PATH."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment