{"thread":{"id":"61243","subject":"Fwd: \"reverse proxy\" remote-helper","startedAt":"2024-04-01T17:37:53Z","lastAt":"2024-04-01T17:37:53Z","messageCount":1,"participants":["Guga Figueiredo"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"491972","messageId":"CAEK6H9r7NbPpcTiOk7E8ZTr1W_rfarLmU_yT1etDiCs6BaERVw@mail.gmail.com","threadId":"61243","inReplyTo":"CAEK6H9o2QQGLQQZ0=C=1CjRGg6UiD_0fv7MwQujv1Sa_v41TAw@mail.gmail.com","subject":"Fwd: \"reverse proxy\" remote-helper","fromName":"Guga Figueiredo","fromEmail":"gugabfigueiredo@gmail.com","sentAt":"2024-04-01T17:37:40Z","receivedAt":"2024-04-01T17:37:53Z","isPatch":false,"sender":{"key":"gugabfigueiredo@gmail.com","avatar":null},"body":"Hello,\n\nI am playing around with git remote helpers trying to write a \"reverse\nproxy\" sort of custom helper to work with a personal server and custom\nprotocol.\nI am doing this because git, natively, already does 99% of the work\nthat I need, and I would like to avoid reinventing the wheel. I just\nwant to create a barely customized interface for a custom server.\nI know I can achieve this with hooks, but I would rather keep this\nconfiguration out of the repos.\n\nconceptually, the command call flow should be something like this:\n```\ngit <cmd> custom::<repo-url>\n└──>git-remote-custom <repo-url> <cmd>\n    └──>git <native-remote-helper> <repo-url> <cmd>\n```\n\nI have been able to implement a git remote helper in go that works on\nlocally stored remotes following this article by rovaugn and the git\ndocumentation on helpers.\n\nAnd have stripped it down to bare essentials to try to invoke the\nnative/builtin remote-helpers directly:\n```go\npackage main\n\nimport (\n    \"errors\"\n    \"fmt\"\n    \"log\"\n    \"net/url\"\n    \"os\"\n    \"os/exec\"\n    \"regexp\"\n)\n\nfunc Main() (er error) {\n\n    if len(os.Args) < 3 {\n       return fmt.Errorf(\"Usage: git-remote-custom remote-name remote-url\")\n    }\n\n    remoteName := os.Args[1]\n    remoteUrl := os.Args[2]\n\n    scheme, err := parseRemoteURL(remoteUrl)\n    if err != nil {\n       return fmt.Errorf(\"Invalid remote URL %s: %v\", remoteUrl, err)\n    }\n\n    // do custom stuff here ...\n\n    // proxy through to native git remote helper\n    cmd := exec.Command(\"git\", fmt.Sprintf(\"remote-%s\", scheme),\nremoteName, remoteUrl)\n    cmd.Stdin = os.Stdin\n    cmd.Stdout = os.Stdout\n    if err := cmd.Run(); err != nil {\n       return err\n    }\n\n    return nil\n}\n\nfunc main() {\n    if err := Main(); err != nil {\n       log.Fatal(err)\n    }\n}\n\nfunc parseRemoteURL(remoteUrl string) (string, error) {\n    if u, err := url.Parse(remoteUrl); err == nil && u.Scheme != \"\" {\n       return u.Scheme, nil\n    }\n\n    // Check for SCP-like SSH URLs first because they don't have a \"scheme://\"\n    scpRe := regexp.MustCompile(`^[a-zA-Z0-9._@/+~-]+@[a-zA-Z0-9._@/+~-]+:[a-zA-Z0-9._@/+~-]+(\\.git)?$`)\n    if scpRe.MatchString(remoteUrl) {\n       return \"ssh\", nil\n    }\n\n    return \"\", errors.New(\"invalid Git URL scheme\")\n}\n```\n\nand this worked for http(s):\n```\n$ GIT_TRACE=1 git clone custom::https://github.com/rovaughn/git-remote-grave.git\n11:17:52.117674 git.c:455               trace: built-in: git clone\ncustom::https://github.com/rovaughn/git-remote-grave.git\nCloning into 'git-remote-grave'...\n11:17:52.120021 run-command.c:668       trace: run_command: git\nremote-custom origin https://github.com/rovaughn/git-remote-grave.git\n11:17:52.121757 git.c:742               trace: exec: git-remote-custom\norigin https://github.com/rovaughn/git-remote-grave.git\n11:17:52.121792 run-command.c:668       trace: run_command:\ngit-remote-custom origin\nhttps://github.com/rovaughn/git-remote-grave.git\n11:17:52.666930 run-command.c:668       trace: run_command: git\nindex-pack --stdin -v --fix-thin '--keep=fetch-pack 21547 on pop-os'\n--check-self-contained-and-connected\nremote: Enumerating objects: 71, done.\n11:17:52.669349 git.c:455               trace: built-in: git\nindex-pack --stdin -v --fix-thin '--keep=fetch-pack 21547 on pop-os'\n--check-self-contained-and-connected\nremote: Total 71 (delta 0), reused 0 (delta 0), pack-reused 71\nReceiving objects: 100% (71/71), 48.92 KiB | 1.11 MiB/s, done.\nResolving deltas: 100% (28/28), done.\n11:17:52.716950 run-command.c:668       trace: run_command: git\nrev-list --objects --stdin --not --all --quiet --alternate-refs\n'--progress=Checking connectivity'\n11:17:52.718721 git.c:455               trace: built-in: git rev-list\n--objects --stdin --not --all --quiet --alternate-refs\n'--progress=Checking connectivity'\n```\n\nbut `ssh` doesn't have a corresponding remote-ssh helper.\n\nIs there a plug and play way to wrap/proxy the `ssh` protocols in a\nsimilar way with a remote-helper? Or are there better approaches to\nachieve this?\n\nAny feedback is appreciated,\nKind regards\n\nGuga\n"}]}