Git credential fill rejects my input, scheduled on Windows

百般思念 提交于 2021-02-07 01:34:41

问题


I want to run a daily task on a Windows server: git-pull + heavy tests.

As I want it to be triggered by a schedule and run from a script, I need the Git credentials to be fed in automatically. I want to use Git credential fill with the syntax key=value

As this is my first time using Git credentials, I may got something basic wrong.

I tried working in both Git Bash (Git extensions --> Ctrl + G) and Cygwin.

There I entered the following lines:

$ git credential fill
protocol=ssh
host=devserver
username=<my user name>
password=<my password>
path=/srv/gitosis/repositories/Matlab.git
<empty line>

Then Git replies with:

warning: invalid credential line:
fatal: unable to read credential from stdin

I also tried to enter only a single line before the empty line and got the same result. I tried only username line, only protocol line, and only host line.

First: What did I do wrong?

Second: What is the correct path to feed?

If I run

git remote -vv

and get:

origin  gitosis@10.10.10.102:/srv/gitosis/repositories/Matlab.git (fetch)
origin  gitosis@10.10.10.102:/srv/gitosis/repositories/Matlab.git (push)

what is my path?

Third: What is the host name?

Given the output of Git remote, if I run ping devserver and get

64 bytes from 10.10.10.102: icmp_seq=0 ttl=64 time=74 ms

Does it mean that the host is devserver?


回答1:


First, a disclaimer: I don't know the plumbing of Git, and I'm just hacking things together to make them work and commenting it here in case it is helpful to you. I'm also using an out-of-date version of Git at this point (1.9.5.mysysgit; I have reasons).

My experience from trying to do something similar has been that git-credential was difficult to get working correctly. I did, however, get something similar to work by operating using the credential helper more directly.

I found an article about the credentials API that describes calling git credential-foo when git config credential.helper returns foo. This seems to have a slightly different interface, with the command get instead of fill (which also seems much more logical).

In any case, for me, my credential helper is wincred, and let's call the host mysite.com. I do most of my work using the same site, so the Windows credential manager shows a saved credential for https://myusername@mysite.com, rather than to any specific path. Calling it, I enter:

>git credential-wincred get
protocol=https
host=mysite.com

and then get out:

username=myusername
password=mypassword

I can also add a username to the input list, and it outputs the same thing. If I add any path to the inputs, or replace the host with the IP address, it doesn't work.

My suggestion would be to see if you can use the git credential-foo <get|store|erase> syntax rather than git credential <fill|approve|reject>, though they appear to be in essence the same thing, just with slightly different names.


To answer your more specific questions:

What did I do wrong?

Assuming I understand correctly that you're trying to set the Git credentials, I think you want to call git credential approve rather than git credential fill, as approve will actually send your entered values to the helper for storage, whereas fill is attempting to fill in holes in the data you provided (I think; the naming here and elsewhere is confusing in Git).

What is the correct path to provide?

I'm not sure, as my one overlapping usage didn't have a path, but I'd suggest srv/gitosis/repositories/Matlab.git, as the leading slash is implied by this being the path.

What is the host name?

I suspect what's going on here is simple string matching on the host in your remote name, rather than a lookup of the domain, so I'd suggest using host=10.10.10.102 for your situation.




回答2:


The easiest way is to use Git Bash to type in your commands, instead of using the Command Prompt. This will solve the stdin problem.




回答3:


I found that it was an issue with line endings in the Windows command shell. Holding the Alt key, then press 1 and 0 on the numeric keypad (in other words inserting a Line Feed character), followed by pressing Enter on the keyboard got it working for me.



来源:https://stackoverflow.com/questions/35336678/git-credential-fill-rejects-my-input-scheduled-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!