git2go icon indicating copy to clipboard operation
git2go copied to clipboard

Can't figure out how to use NewCredUserpassPlaintext() properly

Open elmed opened this issue 9 years ago • 1 comments

Hello,

I am trying to clone a password protected http git repo using NewCredUserpassPlaintext() function by passing the credentials to git.CloneOptions struct as shown in code bellow, but it does not work for me and I get a: No Content-Type header in response.

Cloning the same http repo using git command-line works fine. Would you please point out to me what I am doing wrong ?

package main

import  "gopkg.in/libgit2/git2go.v23"


func credentialsCallback(url string, username string, allowedTypes git.CredType) (git.ErrorCode, *git.Cred) {
  ret, cred := git.NewCredUserpassPlaintext("username", "password")
  return git.ErrorCode(ret), &cred
}

func main() {

  cloneOptions := &git.CloneOptions{}

  cloneOptions.FetchOptions = &git.FetchOptions{
    RemoteCallbacks: git.RemoteCallbacks{
      CredentialsCallback:      credentialsCallback,
    },
  }
  repo, err := git.Clone("http://IP-address:port/private-repository.git", "private-repo", cloneOptions)
  if err != nil {
    Panic(err)
  }
}

elmed avatar Feb 18 '16 13:02 elmed

That error message isn't related to the password, the server isn't sending the right kind of response. Chances are that you're hitting a repo that expects to be downloaded via dumb HTTP, WHICH git2go/libgit2 doesn't support.

carlosmn avatar Feb 18 '16 14:02 carlosmn