vcpkg libgit2 with libssh2 does not seem to work

17 Views Asked by At

On VS2022, I am using a vcpkg manifest file linking libgit2 and libssh2 with an MFC project.

When I try to git push using libgit2, I get the error "unsupported URL protocol".

After Googling it seems the problem is that libgit2 does not use libssh2 but I do not know how to resolve this.

Any help is appreciated.

My manifest is:

{
  "name": "workbench",
  "version-string": "1.0.0.0",
  "dependencies": [
    {
      "name": "openssl",
      "version>=": "3.0.7#2"
    },
    {
      "name": "libssh2",
      "version>=": "1.10.0#4"
    },
    {
      "name": "boost-beast",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-asio",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-process",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-filesystem",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-locale",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-regex",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-algorithm",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-format",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-multiprecision",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-crc",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-uuid",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-iostreams",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-interprocess",
      "version>=": "1.78.0"
    },
    {
      "name": "boost-date-time",
      "version>=": "1.78.0"
    },
    {
      "name": "zlib",
      "version>=": "1.2.12#1"
    },
    {
      "name": "bzip2",
      "version>=": "1.0.8#2"
    },
    {
      "name": "mongo-cxx-driver",
      "version>=": "3.6.5"
    },
    {
      "name": "libmariadb",
      "version>=": "3.1.15"
    },
    {
      "name": "hunspell",
      "version>=": "1.7.1#2"
    },
    {
      "name": "exprtk",
      "version>=": "2022-01-01#2"
    },
    {
      "name": "libxlsxwriter",
      "version>=": "1.1.5"
    },
    {
      "name": "libgit2",
      "version>=": "1.4.2"
    }
  ],
  "builtin-baseline": "062f92c92e0e8017929ea7647819036d8daef638"
}

The code I use is:

giterr_clear();

bool result = false;

if (m_repo_path.empty())
    return result;  

git_repository* repo = nullptr;
if (git_repository_open(&repo, m_repo_path.c_str()))
    return result;
    
char* refspec = "refs/heads/master";    
const git_strarray refspecs = { &refspec, 1 };

git_remote* premote = NULL;
if (git_remote_lookup(&premote, repo, remote.c_str()) == 0)
{
    git_remote_callbacks callbacks;
    if (git_remote_init_callbacks(&callbacks, GIT_REMOTE_CALLBACKS_VERSION) == 0)
    {
        callbacks.payload = (void*) this;
        callbacks.credentials = cred_acquire_cb;
        callbacks.pack_progress = pack_progress_cb;
        callbacks.push_transfer_progress = push_transfer_progress_cb;
        callbacks.sideband_progress = sideband_progress_cb;
        callbacks.transfer_progress = transfer_progress_cb;
        
        git_push_options poptions;
        if (git_push_options_init(&poptions, GIT_PUSH_OPTIONS_VERSION) == 0)
        {
            poptions.callbacks = callbacks;
            result = (git_remote_push(premote, &refspecs, &poptions) == 0);

            if(result)
            {
                if (git_repository_state_cleanup(repo) == 0)
                {
                    char* pathspec_strings[] = { "HEAD", };
                    git_strarray pathspec_array = { pathspec_strings, 1, };
                    if (git_reset_default(repo, NULL, &pathspec_array) == 0)
                    {
                        git_remote_disconnect(premote);                         
                    }
                }
            }
            else
            {
                const ::git_error* e = giterr_last();
                m_lastError = e->message;
            }

        }
    }

    git_remote_free(premote);
}

git_repository_free(repo);
0

There are 0 best solutions below