Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to resolve using OpenSSH client configuration file #116

Merged
merged 1 commit into from
Mar 3, 2024

Conversation

psibi
Copy link
Contributor

@psibi psibi commented Dec 8, 2023

So I have this setup where I use a different github account and a different private key configured like this in my ~/.ssh/config

Host github+myorg
  IdentitiesOnly yes
  HostName github.com
  IdentityFile ~/.ssh/myorg_id_rsa

This PR provides the ability to support such configuration. I have disabled it by default since this is not a common setup most peoples have.

@sshaw
Copy link
Owner

sshaw commented Dec 9, 2023

Hi, thanks for the PR!

To make sure I understand, your git remote uses github+myorg but you want that to link to github.com, is that correct?

@@ -431,10 +436,16 @@ return (FILENAME . REVISION) otherwise nil."
(when (string-match ":" host)
(let ((parts (split-string host ":" t))
(case-fold-search t))
(string-match (concat (car parts) ":\\(" (cadr parts) "\\)/") url)
(string-match (concat (regexp-quote (car parts)) ":\\(" (cadr parts) "\\)/") url)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

git-link.el Outdated Show resolved Hide resolved
@psibi
Copy link
Contributor Author

psibi commented Dec 10, 2023

To make sure I understand, your git remote uses github+myorg but you want that to link to github.com, is that correct?

Yes. The remote for my repository looks like this:

git@github+myorg:MyOrganization/repo-name.git

@psibi psibi requested a review from sshaw December 18, 2023 09:59
git-link.el Outdated
"Resolve HOSTNAME using ssh client."
(let ((output (shell-command-to-string (format "ssh -G %s" hostname)))
(host nil))
(dolist (line (string-split output "\n"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string-split, where does this come from? I do not have it in my Emacs. Using 27.2

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also on Window will this be \n or \r\n?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes from subr.el which comes with Emacs 29.1. I will see what I can do to support older versions.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

(defun find-it (host)
  (with-temp-buffer
    (call-process "/usr/bin/ssh" nil (list (current-buffer) nil) nil "-G" host)
    (beginning-of-buffer)
    (when (search-forward-regexp "^hostname \\(.*\\)")
      (match-string 1))))

Should take care of the Windows line terminator problem. If it was even a problem.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well (defun git-link--ssh-resolve-hostname ...) 😉

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also just be "ssh", right?

Copy link
Contributor Author

@psibi psibi Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sshaw Sorry, this took more time to come back than what I expected. I have replaced string-split with split-string which is available from Emacs 20.1. In fact string-split is a defalias to it.

Also, I have been using this functionality for couple of months at work now and didn't face any issues.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, great thanks for the update!

Do we know \n will work on Windows? It's okay if not.

Can you squash into a single commit?

Also added one question about cond

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know \n will work on Windows? It's okay if not.

It won't work. I can make it portable if you want, but I wouldn't be able to test it on a Windows machine since I don't have one.

Can you squash into a single commit?

Done, thanks!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know \n will work on Windows? It's okay if not.

It won't work. I can make it portable if you want, but I wouldn't be able to test it on a Windows machine since I don't have one.

And I just uninstalled my Virtual Box Windows (7!) image. Should just be a matter of changing "\n" to "\r?\n" but we can do that latter.

Thanks for the work!

@psibi psibi requested a review from sshaw March 1, 2024 10:05
git-link.el Outdated Show resolved Hide resolved
So I have this setup where I use a different github account and a
different private key configured like this in my ~/.ssh/config

Host github+myorg
  IdentitiesOnly yes
  HostName github.com
  IdentityFile ~/.ssh/myorg_id_rsa

This PR provides the ability to support such configuration. I have
disabled it by default since this is not a common setup most peoples
have.
@psibi psibi requested a review from sshaw March 3, 2024 07:59
@sshaw sshaw merged commit 81b4eb8 into sshaw:master Mar 3, 2024
11 checks passed
@sshaw
Copy link
Owner

sshaw commented Mar 3, 2024

Release in v0.9.1

@psibi
Copy link
Contributor Author

psibi commented Mar 3, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants