This repository has been archived by the owner. It is now read-only.

Can't force git to use https:// instead of git:// #5257

Closed
ceeeKay opened this Issue May 12, 2014 · 16 comments

Comments

Projects
None yet
8 participants
@ceeeKay

ceeeKay commented May 12, 2014

Git has a simple way to do this in the config file.

[url "https://"]
    insteadOf = git://

However npm seems to throw out the environment in lib/cache.js

var gitEnv_
function gitEnv () {
  // git responds to env vars in some weird ways in post-receive hooks
  // so don't carry those along.
  if (gitEnv_) return gitEnv_
  gitEnv_ = {}
  for (var k in process.env) {
    if (!~['GIT_PROXY_COMMAND','GIT_SSH','GIT_SSL_NO_VERIFY'].indexOf(k) && k.match(/^GIT/)) continue
    gitEnv_[k] = process.env[k]
  }
  return gitEnv_
}

So I can't inject a GIT_CONFIG or anything.

I've hand-hacked it into the addRemoteGit function in lib/cache.js with

  u = u.replace(/^git:/, "https:")

but this variable should be pulled from a config somewhere

@ceeeKay

This comment has been minimized.

Show comment
Hide comment
@ceeeKay

ceeeKay Jul 3, 2014

Note the location for the work-around replacement appears to have changed to lib/cache/add-remote-git.js in recent versions, but hopefully my pull request (#5621) is accepted to use git-config to check for the url."https://".insteadOf git:// that those of us behind git:// protocol-blocking firewalls are accustomed to.

ceeeKay commented Jul 3, 2014

Note the location for the work-around replacement appears to have changed to lib/cache/add-remote-git.js in recent versions, but hopefully my pull request (#5621) is accepted to use git-config to check for the url."https://".insteadOf git:// that those of us behind git:// protocol-blocking firewalls are accustomed to.

@callumlocke

This comment has been minimized.

Show comment
Hide comment
@callumlocke

callumlocke Aug 4, 2014

I have this problem too, means I can't install some Atom packages. What is lib/cache.js?

callumlocke commented Aug 4, 2014

I have this problem too, means I can't install some Atom packages. What is lib/cache.js?

@Ajedi32

This comment has been minimized.

Show comment
Hide comment
@Ajedi32
Contributor

Ajedi32 commented Aug 4, 2014

@adamkdean

This comment has been minimized.

Show comment
Hide comment
@adamkdean

adamkdean Aug 27, 2014

I am also having problems with this. I've updated .gitconfig to work but Atom still doesn't work. Annoying really. Hopefully a fix will come out for this!

adamkdean commented Aug 27, 2014

I am also having problems with this. I've updated .gitconfig to work but Atom still doesn't work. Annoying really. Hopefully a fix will come out for this!

@Ajedi32

This comment has been minimized.

Show comment
Hide comment
@Ajedi32

Ajedi32 Aug 27, 2014

Contributor

Out of curiosity, why exactly is NPM throwing out the environment in the first place? I know the comment says:

git responds to env vars in some weird ways in post-receive hooks so don't carry those along.

But I'm not sure what that means, exactly. What are the "weird ways" being referred to here?

Also, I'm not sure why the code the OP referenced actually prevents us from using GIT_CONFIG. The way I read it, it seems like all that function is doing is returning a map of all GIT* environment variables except GIT_PROXY_COMMAND, GIT_SSH, and GIT_SSL_NO_VERIFY. GIT_CONFIG doesn't seem to be excluded.

Contributor

Ajedi32 commented Aug 27, 2014

Out of curiosity, why exactly is NPM throwing out the environment in the first place? I know the comment says:

git responds to env vars in some weird ways in post-receive hooks so don't carry those along.

But I'm not sure what that means, exactly. What are the "weird ways" being referred to here?

Also, I'm not sure why the code the OP referenced actually prevents us from using GIT_CONFIG. The way I read it, it seems like all that function is doing is returning a map of all GIT* environment variables except GIT_PROXY_COMMAND, GIT_SSH, and GIT_SSL_NO_VERIFY. GIT_CONFIG doesn't seem to be excluded.

@ceeeKay

This comment has been minimized.

Show comment
Hide comment
@ceeeKay

ceeeKay Aug 27, 2014

As far as I could tell without understanding javascript, at first glance

for (var k in process.env) {
    if (!~['GIT_PROXY_COMMAND','GIT_SSH','GIT_SSL_NO_VERIFY'].indexOf(k) && k.match(/^GIT/)) continue
    gitEnv_[k] = process.env[k]

meant "for each entry in process.env, if the entry is not GIT_PROXY_COMMAND/SSH/SSL_NO_VERIFY, move on to the next entry, otherwise add the environment variable to the gitEnv list" the placement of the continue and the use of negation here is very confusing, and the comment doesn't exactly help things.

I could be totally wrong and this isn't the line that's chucking things, but it looked like it needed to be revised/clarified regardless.

ceeeKay commented Aug 27, 2014

As far as I could tell without understanding javascript, at first glance

for (var k in process.env) {
    if (!~['GIT_PROXY_COMMAND','GIT_SSH','GIT_SSL_NO_VERIFY'].indexOf(k) && k.match(/^GIT/)) continue
    gitEnv_[k] = process.env[k]

meant "for each entry in process.env, if the entry is not GIT_PROXY_COMMAND/SSH/SSL_NO_VERIFY, move on to the next entry, otherwise add the environment variable to the gitEnv list" the placement of the continue and the use of negation here is very confusing, and the comment doesn't exactly help things.

I could be totally wrong and this isn't the line that's chucking things, but it looked like it needed to be revised/clarified regardless.

@Ajedi32

This comment has been minimized.

Show comment
Hide comment
@Ajedi32

Ajedi32 Aug 27, 2014

Contributor

@camillem Oops, I missed the continue at the end of the if statement. (Probably because I had to scroll to see it.) You are correct, the function is filtering out the exact opposite of what I thought it was. I guess the indentation should have clued me in on that...

Anyway, I wonder if we could fix this by adding GIT_CONFIG to that whitelist of git commands. (Would trigger the problems mentioned in the comment?) Is GIT_CONFIG necessary though? Couldn't you just put the insteadOf = git:// in the global gitconfig file?

Contributor

Ajedi32 commented Aug 27, 2014

@camillem Oops, I missed the continue at the end of the if statement. (Probably because I had to scroll to see it.) You are correct, the function is filtering out the exact opposite of what I thought it was. I guess the indentation should have clued me in on that...

Anyway, I wonder if we could fix this by adding GIT_CONFIG to that whitelist of git commands. (Would trigger the problems mentioned in the comment?) Is GIT_CONFIG necessary though? Couldn't you just put the insteadOf = git:// in the global gitconfig file?

@othiym23 othiym23 modified the milestone: first-class git Aug 27, 2014

@othiym23

This comment has been minimized.

Show comment
Hide comment
@othiym23

othiym23 Aug 27, 2014

Contributor

It is indeed a pain that npm gets in git's way like this, but I don't have the time right now to come up with a fix. If somebody wants to start the process of making a (tested) change to support https, I'll be happy to land it. If not, it's probably going to be a month or two before we can get to it.

Contributor

othiym23 commented Aug 27, 2014

It is indeed a pain that npm gets in git's way like this, but I don't have the time right now to come up with a fix. If somebody wants to start the process of making a (tested) change to support https, I'll be happy to land it. If not, it's probably going to be a month or two before we can get to it.

@LaurentGoderre

This comment has been minimized.

Show comment
Hide comment
@LaurentGoderre

LaurentGoderre Oct 24, 2014

Hey everyone, I figured this out!!! ...I think.

Npm doesn't seem to use git:// but rather git@ which is ssh. If you run the following command, it forces npm to instal using https

git config --global url."https://github.com/".insteadOf git@github.com:

I tested it out and it works great for me!

LaurentGoderre commented Oct 24, 2014

Hey everyone, I figured this out!!! ...I think.

Npm doesn't seem to use git:// but rather git@ which is ssh. If you run the following command, it forces npm to instal using https

git config --global url."https://github.com/".insteadOf git@github.com:

I tested it out and it works great for me!

@LaurentGoderre

This comment has been minimized.

Show comment
Hide comment
@LaurentGoderre

LaurentGoderre Oct 24, 2014

I fixed this issue for several of my colleagues by running the following two commands:

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://

One thing we noticed is that the .gitconfig used is not always the one expected so if you are on a machine that modified the home path to a shared drive, you need to ensure that your .gitconfig is the same on both your shared drive and in c:\users\[your user]\

LaurentGoderre commented Oct 24, 2014

I fixed this issue for several of my colleagues by running the following two commands:

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://

One thing we noticed is that the .gitconfig used is not always the one expected so if you are on a machine that modified the home path to a shared drive, you need to ensure that your .gitconfig is the same on both your shared drive and in c:\users\[your user]\

@othiym23

This comment has been minimized.

Show comment
Hide comment
@othiym23

othiym23 Oct 27, 2014

Contributor

This is nice, @LaurentGoderre! I think I'm going to add this to the troubleshooting guide right now. Eventually, I want the CLI to support this without having to hack around it, but this is a pretty sweet workaround, because it fixes more than just npm.

Contributor

othiym23 commented Oct 27, 2014

This is nice, @LaurentGoderre! I think I'm going to add this to the troubleshooting guide right now. Eventually, I want the CLI to support this without having to hack around it, but this is a pretty sweet workaround, because it fixes more than just npm.

@LaurentGoderre

This comment has been minimized.

Show comment
Hide comment
@LaurentGoderre

LaurentGoderre Oct 27, 2014

Yeah! It solved problems for half a dozen developers for us!

LaurentGoderre commented Oct 27, 2014

Yeah! It solved problems for half a dozen developers for us!

@AgeBK

This comment has been minimized.

Show comment
Hide comment
@AgeBK

AgeBK Jan 14, 2015

cheers @LaurentGoderre, worked a charm

AgeBK commented Jan 14, 2015

cheers @LaurentGoderre, worked a charm

@othiym23

This comment has been minimized.

Show comment
Hide comment
@othiym23

othiym23 Feb 27, 2015

Contributor

After reviewing the patch on #5621 and this issue, I've decided that @LaurentGoderre's approach is actually sufficient, without adding another difficult-to-test (and -debug) code path. Because we do have Laurent's instructions in the troubleshooting guide, I'm going to call this documented and resolved. If somebody wants to propose a patch that moves this configuration into the official npm documentation, I'm willing to work with them to land it, but keep in mind that the npm docs are meant for npm-specific things, and this is a more general Git configuration issue.

Contributor

othiym23 commented Feb 27, 2015

After reviewing the patch on #5621 and this issue, I've decided that @LaurentGoderre's approach is actually sufficient, without adding another difficult-to-test (and -debug) code path. Because we do have Laurent's instructions in the troubleshooting guide, I'm going to call this documented and resolved. If somebody wants to propose a patch that moves this configuration into the official npm documentation, I'm willing to work with them to land it, but keep in mind that the npm docs are meant for npm-specific things, and this is a more general Git configuration issue.

@othiym23 othiym23 closed this Feb 27, 2015

@LaurentGoderre

This comment has been minimized.

Show comment
Hide comment
@LaurentGoderre

LaurentGoderre Feb 27, 2015

👍 I don't think you guys should complicate your code base to accommodate super restrictive network environments if a workaround exists

LaurentGoderre commented Feb 27, 2015

👍 I don't think you guys should complicate your code base to accommodate super restrictive network environments if a workaround exists

@mkozjak

This comment has been minimized.

Show comment
Hide comment
@mkozjak

mkozjak Jul 7, 2015

For bitbucket you would use:
git config --global url."https://user:pass@bitbucket.org".insteadOf ssh://git@bitbucket.org

mkozjak commented Jul 7, 2015

For bitbucket you would use:
git config --global url."https://user:pass@bitbucket.org".insteadOf ssh://git@bitbucket.org

@npm npm locked and limited conversation to collaborators Jul 7, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.