c# - What could cause a 401 error in a git pull (via libgit2sharp)? -
this pull wrapper works on local network:
internal mergestatus pull() { using (var repo = new repository(repositoryroot)) { var merger = new signature(username,emailaddress,datetimeoffset.utcnow); var options =new pulloptions { fetchoptions = new fetchoptions() { credentialsprovider = credentialshandler } }; mergeresult result = repo.network.pull(merger, options); return result.status; } }
the following shows credentialshandler using along commented-out attempt use usernamepasswordcredentials gave me same result.
public libgit2sharp.handlers.credentialshandler credentialshandler { { if (credentialshandler_ == null) { credentialshandler_ = (_url, _user, _cred) => new defaultcredentials(); //this not fix 401 error on jupiter box //credentialshandler_ = (_url, _user, _cred) => new usernamepasswordcredentials //{ // username = username, // password = pwd, //}; } return credentialshandler_; } set { credentialshandler_ = value; } }
the pull function works beautifully on local network when use machine on different network identical directory structure , clone of git repository, 401 error:
libgit2sharp.libgit2sharpexception: request failed status code: 401 @ libgit2sharp.core.ensure.handleerror(int32 result) @ libgit2sharp.core.ensure.zeroresult(int32 result) @ libgit2sharp.core.proxy.git_remote_fetch(remotesafehandle remote, signature signature, string logmessage) @ libgit2sharp.network.dofetch(remotesafehandle remotehandle, fetchoptions options, signature signature, string logmessage) @ libgit2sharp.network.fetch(remote remote, fetchoptions options, signature signature, string logmessage) @ libgit2sharp.network.pull(signature merger, pulloptions options) @ gitface.gitfilelistcontroller.pull() in c:\code\workspace\gitface\gitfilelistcontroller.cs:line 190
note when use git bash , enter 'git pull', need enter password on both local , network computers both pull changes remote repository (fwiw, actual repository in tfs on local network). process pulling , pushing via git bash identical 2 computers surprised when libgit2sharp code behaved differently 1 other.
note: did not work:
private int gitcredentialhandler(out intptr ptr, intptr curl, intptr usernamefromurl, gitcredentialtype credtypes, intptr payload) { string url = laxutf8marshaler.fromnative(curl); string domain = configurationmanager.appsettings["domain"]; if (url.startswith(@"http://")) { url = string.format(@"http://{0}\\\{1}", domain, url.substring(7)); } else if (url.startswith(@"https://")) { url = string.format(@"https://{0}\\\{1}", domain, url.substring(8)); } string username = string.format(@"{0}\{1}", domain, laxutf8marshaler.fromnative(usernamefromurl)); supportedcredentialtypes types = default(supportedcredentialtypes); if (credtypes.hasflag(gitcredentialtype.userpassplaintext)) { types |= supportedcredentialtypes.usernamepassword; } if (credtypes.hasflag(gitcredentialtype.default)) { types |= supportedcredentialtypes.default; } var cred = credentialsprovider(url, username, types); return cred.gitcredentialhandler(out ptr); }
Comments
Post a Comment