Created
July 1, 2015 02:38
-
-
Save marsam/21dd3581a3bc656890f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun marsam/add-pull-request-refs (&optional remote local-ns) | |
"Set pull requests refs from a REMOTE with LOCAL-NS namespace into Git config." | |
(interactive (let* ((remote (magit-read-remote "Fetch remote")) | |
(local-ns (read-string "local namespace: " (format "%s/pr" remote)))) | |
(list remote local-ns))) | |
(and (not (magit-get-boolean "core" "disableprref")) | |
(let* ((remote (or remote "origin")) | |
(local-ns (if (or (null local-ns) (string= "" local-ns)) (format "%s/pr" remote) local-ns)) | |
(pr-refs (format "+refs/pull/*/head:refs/remotes/%s/*" local-ns)) | |
(remote-fetch-refs (magit-get-all "remote" remote "fetch"))) | |
(and remote-fetch-refs | |
(not (magit-get-boolean "remote" remote "disableprref")) | |
(not (member pr-refs remote-fetch-refs)) | |
(string-match "github.com" (magit-get "remote" remote "url")) | |
(magit-git-string "config" "--add" (format "remote.%s.fetch" remote) pr-refs))))) | |
(add-hook 'magit-mode-hook 'marsam/add-pull-request-refs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment