magit / forge

Work with Git forges from the comfort of Magit
GNU General Public License v3.0
1.32k stars 117 forks source link

Support custom ssh port? #4

Closed damienrg closed 3 years ago

damienrg commented 5 years ago

In order to test forge, I am trying to use it with a personal gitlab server. To do that, I added:

(push '("gitlab.foo.com" "gitlab.foo.com/api/v4" "gitlab.foo.com" forge-gitlab-repository) forge-alist)

I created a bar project in gitlab and as ssh is listening on port 2222, the url to clone is ssh://git@gitlab.foo.com:2222/username/bar.git.

When I try to use forge I got the following error: Cannot determine forge repository. ssh://git@gitlab.foo.com:2222/username/bar.git. I could change the configuration to make it working by specifying gitlab.foo.com:2222 but then it does not work as forge use https://gitlab.foo.com:2222 for requests. Did I miss something, or is it not supported for now?

tarsius commented 5 years ago

Show me all the urls that work:

curl .../api/v4...
firefox ...
git clone ...
benalbrecht commented 5 years ago

something like

(push '("gitlab.foo.com:2222" "gitlab.foo.com/api/v4" "gitlab.foo.com" forge-gitlab-repository) forge-alist)

did the trick for me a while ago, but i haven't validated whether it still works on the current version

damienrg commented 5 years ago

In my initial report, I said that requests did not work, but in fact, I only tried forge-browse-dwim which is not a request...

I just tried forge-pull and it does work.

Requested information:

Urls that work:

I use the same configuration as the one given by @benalbrecht.

My actual problem:

When I do forge-browse-dwim with branch master, it tries to open https://gitlab.effidence.com:2222/username/bar/commit/sha1.

I might be wrong but for me it seems that:

The problem is more that forge should distinguish a ssh remote from a https remote.

tarsius commented 5 years ago

Couldn't you just use git clone https://gitlab.foo.com/username/bar.git and drop the port from the forge-alist entry?

damienrg commented 5 years ago

Yes, I can do that.

The question is then, is it a feature that you want to support? If yes, do you need help? If no, I will let you close the issue with the reason.

tarsius commented 5 years ago

I don't want to support it because it comes as an afterthought. I would have to bolt it on, resulting in a less than ideal interface. There already is enough necessary complexity that users have to deal with when configuring Forge for another forge and I don't want to make things even more complicated. (Of course if you actually need to use a non-standard port, then the absence of support for that makes things even more complicated, but I expect that only a very small minority of users will be affected by this.)

By the way an alternative to using https is to remap ssh urls; both git and ssh provide mechanisms for doing so.

Thaodan commented 3 years ago

Couldn't you just use git clone https://gitlab.foo.com/username/bar.git and drop the port from the forge-alist entry?

Can you revisit that? That breaks instances where the SSH Port for git-repositories is not the default.

Thaodan commented 3 years ago

It didn't found a workaround for that the remote always includes the port number eg. 2222/origin

tarsius commented 3 years ago

Can you revisit that?

I can but I don't understand yet what you are saying. Some additional thinking will be necessary and I would appreciate it if you did most of that. It would help me if you could posted the forge-alist entry that you would like to be using.

Thaodan commented 3 years ago

My forge at list is the following:

  (push '(
          "git.sailfishos.org" "git.sailfishos.org"
          "git.sailfishos.org/api/v4" forge-gitlab-repository)
        forge-alist)
)

When I use forge-add-repository on a repository from that Gitlab I get:

Debugger entered--Lisp error: (wrong-type-argument numberp nil)
  glab-repository-id("2222/mer-core" "scratchbox2" :username nil :auth forge 
:host "git.sailfishos.org")
  ghub-repository-id("2222/mer-core" "scratchbox2" :host "git.sailfishos.org" 
:auth forge :forge gitlab)
  #f(compiled-function (class host owner name &optional stub) "Return (OUR-ID 
. THEIR-ID) of the specified repository.\nIf optional STUB is non-nil, then the 
IDs are not guaranteed to\nbe unique.  Otherwise this method has to make an 
API request to\nretrieve THEIR-ID, the repository's ID on the forge.  In 
that\ncase OUR-ID derives from THEIR-ID and is unique across all\nforges and 
hosts." #<bytecode -0xee27a2fec139624>)(forge-gitlab-repository 
"git.sailfishos.org" "2222/mer-core" "scratchbox2" nil)
  apply(#f(compiled-function (class host owner name &optional stub) "Return 
(OUR-ID . THEIR-ID) of the specified repository.\nIf optional STUB is non-nil, 
then the IDs are not guaranteed to\nbe unique.  Otherwise this method has to 
make an API request to\nretrieve THEIR-ID, the repository's ID on the forge.  
In that\ncase OUR-ID derives from THEIR-ID and is unique across all\nforges 
and hosts." #<bytecode -0xee27a2fec139624>) forge-gitlab-repository 
("git.sailfishos.org" "2222/mer-core" "scratchbox2" nil))
  forge--repository-ids(forge-gitlab-repository "git.sailfishos.org" "2222/mer-
core" "scratchbox2" nil)
  #f(compiled-function (&rest rest) "((host owner name) &optional remote 
demand)\n\nReturn the repository identified by HOST, OWNER and NAME." 
#<bytecode 0xfbe77b0529f0fd3>)(("git.sailfishos.org" "2222/mer-core" 
"scratchbox2") nil create)
  apply(#f(compiled-function (&rest rest) "((host owner name) &optional remote 
demand)\n\nReturn the repository identified by HOST, OWNER and NAME." 
#<bytecode 0xfbe77b0529f0fd3>) ("git.sailfishos.org" "2222/mer-core" 
"scratchbox2") (nil create))
  forge-get-repository(("git.sailfishos.org" "2222/mer-core" "scratchbox2") nil 
create)
  #f(compiled-function (url &optional remote demand) "Return the repository at 
URL." #<bytecode -0x1c424a9124495c34>)("ssh://git@git.sailfishos.org:2222/mer-
core/scratch..." nil create)
  apply(#f(compiled-function (url &optional remote demand) "Return the 
repository at URL." #<bytecode -0x1c424a9124495c34>) "ssh://
git@git.sailfishos.org:2222/mer-core/scratch..." (nil create))
  forge-get-repository("ssh://git@git.sailfishos.org:2222/mer-core/scratch..." 
nil create)
  forge-add-repository("ssh://git@git.sailfishos.org:2222/mer-core/scratch...")
  funcall-interactively(forge-add-repository "ssh://git@git.sailfishos.org:
2222/mer-core/scratch...")
  command-execute(forge-add-repository record)
  helm-M-x-execute-command(forge-add-repository)
  helm-execute-selection-action-1()
  helm-execute-selection-action()
  helm-internal((((name . "Emacs Commands history") (candidates . #f(compiled-
function () #<bytecode 0x1fad86b45a0ff0cd>)) (keymap keymap (keymap ...) keymap 
(21 . helm-M-x-universal-argument) keymap (127 . delete-backward-char) (27 
keymap ...) (C-return . helm-cr-empty-string) keymap (26 . helm-select-action) 
(tab . helm-execute-persistent-action) (f13 lambda nil ... ...) (f12 lambda 
nil ... ...) (f11 lambda nil ... ...) (f10 lambda nil ... ...) (f9 lambda nil 
... ...) (f8 lambda nil ... ...) (f7 lambda nil ... ...) (f6 lambda nil ... 
...) (f5 lambda nil ... ...) (f4 lambda nil ... ...) (f3 lambda nil ... ...) 
(f2 lambda nil ... ...) (menu-bar keymap ...) (help keymap ...) (23 . 
#f(compiled-function () ... #<bytecode 0x50017578943d1b2>)) (f1 lambda nil ... 
...) (8 keymap ... ... ... ... ...) (20 . helm-toggle-resplit-and-swap-
windows) (C-tab . undefined) (67108897 . helm-toggle-suspend-update) ...) 
(action . helm-type-command-actions) (persistent-action . helm-M-x-persistent-
action) (persistent-help . "Describe this command") (help-message . helm-M-x-
help-message) (requires-pattern . 0) (filtered-candidate-transformer helm-M-x-
transformer-no-sort helm-fuzzy-highlight-matches) (volatile . t) (match . 
identity) (redisplay . identity) (nomark . t) (coerce . helm-symbolify) 
(header-line . "C-j: Describe this command (keep...") (must-match . t) (group 
. helm-command) (match-dynamic . t)) ((name . "Emacs Commands") (candidates . 
#f(compiled-function () #<bytecode -0xc8026a0e910a8ef>)) (keymap keymap 
(keymap ...) keymap (21 . helm-M-x-universal-argument) keymap (127 . delete-
backward-char) (27 keymap ...) (C-return . helm-cr-empty-string) keymap (26 . 
helm-select-action) (tab . helm-execute-persistent-action) (f13 lambda nil ... 
...) (f12 lambda nil ... ...) (f11 lambda nil ... ...) (f10 lambda nil ... 
...) (f9 lambda nil ... ...) (f8 lambda nil ... ...) (f7 lambda nil ... ...) 
(f6 lambda nil ... ...) (f5 lambda nil ... ...) (f4 lambda nil ... ...) (f3 
lambda nil ... ...) (f2 lambda nil ... ...) (menu-bar keymap ...) (help keymap 
...) (23 . #f(compiled-function () ... #<bytecode 0x50017578943d1b2>)) (f1 
lambda nil ... ...) (8 keymap ... ... ... ... ...) (20 . helm-toggle-resplit-
and-swap-windows) (C-tab . undefined) (67108897 . helm-toggle-suspend-update) 
...) (action . helm-type-command-actions) (persistent-action . helm-M-x-
persistent-action) (persistent-help . "Describe this command") (help-message . 
helm-M-x-help-message) (requires-pattern . 0) (filtered-candidate-transformer 
helm-M-x-transformer-no-sort helm-fuzzy-highlight-matches) (volatile . t) 
(match . identity) (redisplay . identity) (nomark . t) (coerce . helm-
symbolify) (header-line . "C-j: Describe this command (keep...") (must-match . 
t) (group . helm-command) (match-dynamic . t))) nil "M-x " nil nil "*helm M-
x*" nil nil helm-M-x-input-history)
  helm((((name . "Emacs Commands history") (candidates . #f(compiled-function 
() #<bytecode 0x1fad86b45a0ff0cd>)) (keymap keymap (keymap ...) keymap (21 . 
helm-M-x-universal-argument) keymap (127 . delete-backward-char) (27 keymap 
...) (C-return . helm-cr-empty-string) keymap (26 . helm-select-action) (tab . 
helm-execute-persistent-action) (f13 lambda nil ... ...) (f12 lambda nil ... 
...) (f11 lambda nil ... ...) (f10 lambda nil ... ...) (f9 lambda nil ... ...) 
(f8 lambda nil ... ...) (f7 lambda nil ... ...) (f6 lambda nil ... ...) (f5 
lambda nil ... ...) (f4 lambda nil ... ...) (f3 lambda nil ... ...) (f2 lambda 
nil ... ...) (menu-bar keymap ...) (help keymap ...) (23 . #f(compiled-
function () ... #<bytecode 0x50017578943d1b2>)) (f1 lambda nil ... ...) (8 
keymap ... ... ... ... ...) (20 . helm-toggle-resplit-and-swap-windows) (C-tab 
. undefined) (67108897 . helm-toggle-suspend-update) ...) (action . helm-type-
command-actions) (persistent-action . helm-M-x-persistent-action) (persistent-
help . "Describe this command") (help-message . helm-M-x-help-message) 
(requires-pattern . 0) (filtered-candidate-transformer helm-M-x-transformer-no-
sort helm-fuzzy-highlight-matches) (volatile . t) (match . identity) 
(redisplay . identity) (nomark . t) (coerce . helm-symbolify) (header-line . 
"C-j: Describe this command (keep...") (must-match . t) (group . helm-command) 
(match-dynamic . t)) ((name . "Emacs Commands") (candidates . #f(compiled-
function () #<bytecode -0xc8026a0e910a8ef>)) (keymap keymap (keymap ...) 
keymap (21 . helm-M-x-universal-argument) keymap (127 . delete-backward-char) 
(27 keymap ...) (C-return . helm-cr-empty-string) keymap (26 . helm-select-
action) (tab . helm-execute-persistent-action) (f13 lambda nil ... ...) (f12 
lambda nil ... ...) (f11 lambda nil ... ...) (f10 lambda nil ... ...) (f9 
lambda nil ... ...) (f8 lambda nil ... ...) (f7 lambda nil ... ...) (f6 lambda 
nil ... ...) (f5 lambda nil ... ...) (f4 lambda nil ... ...) (f3 lambda nil 
... ...) (f2 lambda nil ... ...) (menu-bar keymap ...) (help keymap ...) (23 . 
#f(compiled-function () ... #<bytecode 0x50017578943d1b2>)) (f1 lambda nil ... 
...) (8 keymap ... ... ... ... ...) (20 . helm-toggle-resplit-and-swap-
windows) (C-tab . undefined) (67108897 . helm-toggle-suspend-update) ...) 
(action . helm-type-command-actions) (persistent-action . helm-M-x-persistent-
action) (persistent-help . "Describe this command") (help-message . helm-M-x-
help-message) (requires-pattern . 0) (filtered-candidate-transformer helm-M-x-
transformer-no-sort helm-fuzzy-highlight-matches) (volatile . t) (match . 
identity) (redisplay . identity) (nomark . t) (coerce . helm-symbolify) 
(header-line . "C-j: Describe this command (keep...") (must-match . t) (group 
. helm-command) (match-dynamic . t))) nil "M-x " nil nil "*helm M-x*" nil nil 
helm-M-x-input-history)
  helm(:sources (((name . "Emacs Commands history") (candidates . #f(compiled-
function () #<bytecode 0x1fad86b45a0ff0cd>)) (keymap keymap (keymap ...) keymap 
(21 . helm-M-x-universal-argument) keymap (127 . delete-backward-char) (27 
keymap ...) (C-return . helm-cr-empty-string) keymap (26 . helm-select-action) 
(tab . helm-execute-persistent-action) (f13 lambda nil ... ...) (f12 lambda 
nil ... ...) (f11 lambda nil ... ...) (f10 lambda nil ... ...) (f9 lambda nil 
... ...) (f8 lambda nil ... ...) (f7 lambda nil ... ...) (f6 lambda nil ... 
...) (f5 lambda nil ... ...) (f4 lambda nil ... ...) (f3 lambda nil ... ...) 
(f2 lambda nil ... ...) (menu-bar keymap ...) (help keymap ...) (23 . 
#f(compiled-function () ... #<bytecode 0x50017578943d1b2>)) (f1 lambda nil ... 
...) (8 keymap ... ... ... ... ...) (20 . helm-toggle-resplit-and-swap-
windows) (C-tab . undefined) (67108897 . helm-toggle-suspend-update) ...) 
(action . helm-type-command-actions) (persistent-action . helm-M-x-persistent-
action) (persistent-help . "Describe this command") (help-message . helm-M-x-
help-message) (requires-pattern . 0) (filtered-candidate-transformer helm-M-x-
transformer-no-sort helm-fuzzy-highlight-matches) (volatile . t) (match . 
identity) (redisplay . identity) (nomark . t) (coerce . helm-symbolify) 
(header-line . "C-j: Describe this command (keep...") (must-match . t) (group 
. helm-command) (match-dynamic . t)) ((name . "Emacs Commands") (candidates . 
#f(compiled-function () #<bytecode -0xc8026a0e910a8ef>)) (keymap keymap 
(keymap ...) keymap (21 . helm-M-x-universal-argument) keymap (127 . delete-
backward-char) (27 keymap ...) (C-return . helm-cr-empty-string) keymap (26 . 
helm-select-action) (tab . helm-execute-persistent-action) (f13 lambda nil ... 
...) (f12 lambda nil ... ...) (f11 lambda nil ... ...) (f10 lambda nil ... 
...) (f9 lambda nil ... ...) (f8 lambda nil ... ...) (f7 lambda nil ... ...) 
(f6 lambda nil ... ...) (f5 lambda nil ... ...) (f4 lambda nil ... ...) (f3 
lambda nil ... ...) (f2 lambda nil ... ...) (menu-bar keymap ...) (help keymap 
...) (23 . #f(compiled-function () ... #<bytecode 0x50017578943d1b2>)) (f1 
lambda nil ... ...) (8 keymap ... ... ... ... ...) (20 . helm-toggle-resplit-
and-swap-windows) (C-tab . undefined) (67108897 . helm-toggle-suspend-update) 
...) (action . helm-type-command-actions) (persistent-action . helm-M-x-
persistent-action) (persistent-help . "Describe this command") (help-message . 
helm-M-x-help-message) (requires-pattern . 0) (filtered-candidate-transformer 
helm-M-x-transformer-no-sort helm-fuzzy-highlight-matches) (volatile . t) 
(match . identity) (redisplay . identity) (nomark . t) (coerce . helm-
symbolify) (header-line . "C-j: Describe this command (keep...") (must-match . 
t) (group . helm-command) (match-dynamic . t))) :prompt "M-x " :buffer "*helm 
M-x*" :history helm-M-x-input-history)
  helm-M-x-read-extended-command([eww-buffer-select TeX-mode-specific-command-
menu ansi-color-apply-overlay-face epg-context-signers gnus-cloud-download-
data tex-chktex-program web-mode-engine-open-delimiter-regexps ⇓\ \\Downarrow 
TeX-command-Biber edebug-trace js-jsx--text-properties magit-reflog-commit 
bbdb-current-record markdown-match-bold magit-wip-buffer-backed-up LaTeX-
comment-env-list helm-type-timers-actions woman-last-file-name adwaita nnmail-
fix-eudora-headers brackets-after-symbol mixal gnus-summary-recenter makefile-
browser-format-macro-line cl-print--preprocess which-key-side-window-max-
height :curr-line edebug-clear-frequency-count ps-footer-offset bibtex-
SuppCollection conf-space-mode-map TeX-auto-local ---- shr-parse-image-data 
Load\ snippets\.\.\. ↮\ \\nleftrightarrow Edebug\ All\ Defs nnheader-
translate-file-chars makefile-insert-gmake-function \' nnoo-import-1 path-dirs 
for\ environment comp-func-l-p--cmacro muletibetan-2 magit-diff-wash-hunk 
cperl-load-font-lock-keywords-1 desktop-buffer-name woman-use-topic-at-point-
default doc-view-pdf/ps->png ...])
  helm-M-x(nil)
  funcall-interactively(helm-M-x nil)
  command-execute(helm-M-x)

So it uses the port number in the api call and bugs then.

tarsius commented 3 years ago

This might actually be trivial to support. Please try this patch:

diff --git a/lisp/forge-core.el b/lisp/forge-core.el
index 5f151851..5d435ccd 100644
--- a/lisp/forge-core.el
+++ b/lisp/forge-core.el
@@ -229,6 +229,7 @@ (defun forge--url-regexp ()
           "\\(?:ssh\\|ssh\\+git\\|git\\+ssh\\)://\\(?:[^/@]+@\\)?\\|"
           "https?://\\(?:[^/@]+@\\)?\\)"
           (regexp-opt (mapcar #'car forge-alist) t)
+          "\\(?::[0-9]+\\)?"
           "\\(?:/\\|:/?\\)"
           "\\(.+?\\)"
           "\\(?:\\.git\\|/\\)?\\'"))
Thaodan commented 3 years ago

That works thanks.

On a site note: it is strange that the host for the gitconfig is the address with the api url instead of just the host.