0

I've migrated my git repositories from Gitlab to Gogs and I've taken the opportunity to change some organization/group names and reorganize repositories.

I'd like to maintain the current Git+SSH URLs working however for projects using composer or other packagers.

I've looked for a way to do it inside Gogs but nothing seems to exist to this purpose so I had another idea (which could also be useful in other contexts): rewriting the SSH path on the server, like Apache does with mod_rewrite. Is there a way to do just that with SSH? Note that adding a command in the .authorized_keys is a bit tricky since Gogs already uses it to mediate access to the repositories through a command.

10
  • So you want to say that URL to your repo changed and you want to fix it for your repos but not submodules? If so you probably want something like this: git config --global url.ssh://[email protected]/.insteadOf [email protected]: Commented Mar 22, 2021 at 9:59
  • @JiriB Not exactly, I have a repo, say "git.example.com/org1/repo1" whose URL is now "git.example.com/other_org_name/other_repo_name" and I'd like the old URL to keep working. Commented Mar 22, 2021 at 10:18
  • And I'd like it to work for any developer on the project without them having to do any config on their side, if possible. Commented Mar 22, 2021 at 10:20
  • Thus it must be server side. I don't know Gogs but I would check how git user on Gogs server works, ie. what command does it run when one does git over SSH. IIUC git over SSH is just calling git in the end with some args. If you see github.com/gogs/gogs/blob/main/internal/ssh/ssh.go then you can see that in trace log level you could see what was called from SSH client (a git user). Basically if Gogs doesn't have any feature for this, you could write a wrapper which would get "old" path from SSH_ORIGINAL_COMMAND and rewrite it and then call git as Gogs does by default. Commented Mar 22, 2021 at 10:36
  • Or maybe server-side git hooks could be used, I have no experience with that. Commented Mar 22, 2021 at 10:38

1 Answer 1

0

So after much tweaking around, I concluded that there's nothing built into SSH to perform what mod_rewrite does for Apache2, most probably for excellent reasons.

So, I instead resorted to replacing the gogs command, called from SSH (in the .authorized_keys file by a script that rewrites the environment variable SSH_ORIGINAL_COMMAND and then calls the real gogs executable.

The SSH_ORIGINAL_COMMAND is the variable into which SSH writes the command sent to the server before calling the command written in .authorized_keys (when there is one). In the case of gogs, this variable is used to check that the repository exists, verify that it belongs to the SSH user logged in, etc. and finally perform the git operation on it. By changing the repository path in this variable, it's possible to alias repositories on-the-fly.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.