Magit: update forge advice

If think this was in response to some API changes in Magit, but I'm not
quite sure.
This commit is contained in:
TEC 2024-03-08 17:13:58 +08:00
parent 9830d78e28
commit ecdaa0b25f
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 39 additions and 33 deletions

View File

@ -3728,39 +3728,45 @@ the pre-filled remote url use ssh.
(defadvice! +magit-remote-add--streamline-forge-a (args)
:filter-args #'magit-remote-add
(interactive
(or (and +magit-default-forge-remote
(not (magit-list-remotes))
(eq (read-char-choice
(format "Setup %s remote? [y/n]: "
(replace-regexp-in-string
"\\`\\(?:[^@]+@\\|https://\\)\\([^:/]+\\)[:/].*\\'" "\\1"
+magit-default-forge-remote))
'(?y ?n))
?y)
(let* ((default-name
(subst-char-in-string ?\s ?-
(file-name-nondirectory
(directory-file-name (doom-project-root)))))
(name (read-string "Name: " default-name)))
(list "origin" (format +magit-default-forge-remote name)
(transient-args 'magit-remote))))
(let ((origin (magit-get "remote.origin.url"))
(remote (magit-read-string-ns "Remote name"))
(gh-user (magit-get "github.user")))
(when (and (equal remote gh-user)
(string-match "\\`https://github\\.com/\\([^/]+\\)/\\([^/]+\\)\\.git\\'"
origin)
(not (string= (match-string 1 origin) gh-user)))
(setq origin (replace-regexp-in-string
"\\`https://github\\.com/" "git@github.com:"
origin)))
(list remote
(magit-read-url
"Remote url"
(and origin
(string-match "\\([^:/]+\\)/[^/]+\\(\\.git\\)?\\'" origin)
(replace-match remote t t origin 1)))
(transient-args 'magit-remote)))))
(let ((default-name
(subst-char-in-string ?\s ?-
(file-name-nondirectory
(directory-file-name (doom-project-root))))))
(or (and +magit-default-forge-remote
(not (magit-list-remotes))
(eq (read-char-choice
(format "Setup %s remote? [y/n]: "
(replace-regexp-in-string
"\\`\\(?:[^@]+@\\|https://\\)\\([^:/]+\\)[:/].*\\'" "\\1"
+magit-default-forge-remote))
'(?y ?n))
?y)
(let ((name (read-string "Name: " default-name)))
(list "origin" (format +magit-default-forge-remote name)
(transient-args 'magit-remote))))
(let ((origin (magit-get "remote.origin.url"))
(remote (magit-read-string-ns "Remote name"))
(gh-user (magit-get "github.user")))
(and (equal remote gh-user)
(if origin
(and
(string-match "\\`https://github\\.com/\\([^/]+\\)/\\([^/]+\\)\\.git\\'"
origin)
(not (string= (match-string 1 origin) gh-user)))
t)
(setq origin
(if origin
(replace-regexp-in-string
"\\`https://github\\.com/" "git@github.com:"
origin)
(format "git@github.com:%s/%s" gh-user (read-string "GitHub repo Name: " default-name)))))
(list remote
(magit-read-url
"Remote url"
(and origin
(string-match "\\([^:/]+\\)/[^/]+\\(\\.git\\)?\\'" origin)
(replace-match remote t t origin 1)))
(transient-args 'magit-remote))))))
args)
#+end_src