Skip to content

Instantly share code, notes, and snippets.

@marsam
Created July 1, 2015 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marsam/21dd3581a3bc656890f4 to your computer and use it in GitHub Desktop.
Save marsam/21dd3581a3bc656890f4 to your computer and use it in GitHub Desktop.
(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