hakoerber / git-repo-manager

A git tool to manage worktrees and integrate with GitHub and GitLab
https://hakoerber.github.io/git-repo-manager/
GNU General Public License v3.0
62 stars 9 forks source link

cannot sync found projects. #65

Open woutervh opened 7 months ago

woutervh commented 7 months ago

what am i doing wrong:

first I created a config-file with:

> grm repos find remote --provider gitlab --token-command "echo ${GITLAB_TOKEN}" --root repo --format yaml --group my-projects  > gitlab-projects.yaml

This finds all my-projects correctly:

trees:
- root: repo
  repos:

  - name: foo
    worktree_setup: false
    remotes:
    - name: origin
      url: git@gitlab.com:my-projects/foo.git
      type: ssh
     ....

manually cloning this repo works ok

> git clone git@gitlab.com:my-projects/foo.git

but syncing via grm fails

>  grm repos sync config --config gitlab-projects.yaml
remote: ========================================================================
remote:
remote: ERROR: The project you were looking for could not be found or you don't have permission to view it.

remote:
remote: ========================================================================
remote:
; class=Ssh (23); code=Eof (-20)
hakoerber commented 7 months ago

How did you set up SSH auth? grm only supports ssh-agent-based auth.

woutervh commented 7 months ago

A direct git clone via ssh on the same ssh-glone url works. I use an ssh-agent running, and use named ssh-sessions like this:

Host gitlab.com
    AddKeysToAgent yes
    HostName gitlab.com
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes
    Port 22
    PreferredAuthentications publickey

Somehow grm manages to fetch the complete list of remote private projects, but cannot check them out.

rbcb-bedag commented 4 months ago

@woutervh I have a similar problem.

My ~/.ssh/config file looks like this :

Host myfancy.domain.com
  HostName 159.XXX.XXX.XX
  IdentityFile ~/.ssh/myfancy_key
....

grm wasn't able to resolve the domain to the ip and also didn't picked up the ssh key.

Following script worked for me as a workaround (maybe change the path to your config.yml at the last line):

function sync_repos {
    # Check if the SSH wrapper script exists
    if [ ! -f ~/.ssh/wrapper.sh ]; then
        # If it doesn't exist, create it
        echo '#!/bin/bash' > ~/.ssh/wrapper.sh
        echo 'ssh -F ~/.ssh/config "$@"' >> ~/.ssh/wrapper.sh

        # Make the script executable
        chmod +x ~/.ssh/wrapper.sh
    fi

    # Set the GIT_SSH_COMMAND environment variable
    export GIT_SSH_COMMAND="~/.ssh/wrapper.sh"

    # Run the grm command with the new config file
    grm repos sync config --config ~/repos/config.yml
}

What it does:

It sets the GIT_SSH_COMMAND env variable, which libgit2 picks up, when executing the git commands. And the evn variable tells it, to use the script at ~/.ssh/wrapper.sh (which get's first created, if it is not present). The wrapper.sh tells git, to load the config file (eg. ssh -F ~/.ssh/config "$@").

With that, it now works again. Hope it helps.

hakoerber commented 2 months ago

I think the issue is that grm does not read any git configurations at all. This should be quite straightfoward to implement using git-rs' Config::open_default.

Maybe you can take a shot at the implemenation? The best place to read the config would be in clone_repo() I guess.

woutervh commented 1 month ago

This is very frustating, no verbose mode, nothing works. I can get a list of remote repos, but I cannot do anything with it,
Something is missing in the docs. No idea what.