Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't specify http.extraheader #424

Closed
ermshiperete opened this issue Jan 24, 2020 · 8 comments
Closed

Can't specify http.extraheader #424

ermshiperete opened this issue Jan 24, 2020 · 8 comments

Comments

@ermshiperete
Copy link

I'm trying to implement the equivalent of

git -c http.extraheader="Authorization: Basic $TOKEN" push $REMOTE $BRANCH

However, the following doesn't work:

git.raw([
  '-c',
  `http.extraheader="Authorization: Basic ${token}"`,
  'push',
  remote,
  branch,
]);

I get a The requested URL returned error: 400 from github whereas calling the above command on the command line works. Is this a bug or am I doing something wrong?

@NightFox7
Copy link

I have the same problem. Did you manage to find a solution ?

@steveukx
Copy link
Owner

In my testing, the commands in your example are passed to the ChildProcess used by simple-git. Are you able to switch to adding configuration with addConfig instead?

const gitP = require('simple-git/promise');
const git = gitP('./').addConfig('http.extraheader', `Authorization: Basic ${token}`);

const result = await git.push(remote, branch);

@NightFox7
Copy link

For me, the problem is with the clone command so I can't use the addConfig given the fact that I don't have local git configuration yet.

@steveukx
Copy link
Owner

You could try logging all output by adding the GIT_TRACE environment variable

const GIT_TRACE = true;
const gitP = require('simple-git/promise');
const git = gitP('./').env({ ...process.env, GIT_TRACE });

const result = await git.raw(['-c', `http.extraheader="Authorization: Basic ${token}"`, remote, branch]);

The standard git binary uses curl for any http request, adding GIT_TRACE will add curl's verbose output to stdout which should help find where the header is being lost.

@NightFox7
Copy link

So I ran the clone command with simple-git and in command line. And here is the difference in the trace logs:
With Simple Git

exec-cmd.c:238          trace: resolved executable dir: ***/git-core
fatal: unable to access '${my_url}: The requested URL returned error: 400

With Command Line

exec-cmd.c:238          trace: resolved executable dir: ***/git-core
12:17:56.155715 run-command.c:663       trace: run_command: git fetch-pack --stateless-rpc --stdin --lock-pack --thin --check-self-contained-and-connected --cloning ${my_url}

@steveukx
Copy link
Owner

The format of the http.extraHeader setting requires that there are no quotes in the value, this passes the header through to the remote repo:

const header = `http.extraHeader=X-Foo: Bar`;
const result = await git.raw(['-c', header 'clone', repo]);

Whereas this fails:

const header = `http.extraHeader="X-Foo: Bar"`;
const result = await git.raw(['-c', header 'clone', repo]);

Please can you check that your header argument is formatted without the quotes...

@NightFox7
Copy link

You are correct. Thank you ! It works now.

@steveukx
Copy link
Owner

steveukx commented Feb 24, 2020

No problem, I'll add to the readme shortly.

@ermshiperete this info should resolve your query too - please ensure you are passing a correctly formatted string as the -c value (ie: http.extraheader=Authorization: Basic ${token} without the ")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants