Skip to content
This repository has been archived by the owner on Aug 11, 2022. 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
Closed

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

ceeeKay opened this issue May 12, 2014 · 16 comments

Comments

@ceeeKay
Copy link

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
Copy link
Author

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
Copy link

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

@Ajedi32
Copy link
Contributor

Ajedi32 commented Aug 4, 2014

@callumlocke I assume they're referring to https://github.com/npm/npm/blob/master/lib/cache.js

@adamkdean
Copy link

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
Copy link
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
Copy link
Author

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
Copy link
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
Copy link
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.

@LaurentGoderre
Copy link

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
Copy link

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
Copy link
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.

@LaurentGoderre
Copy link

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

@AgeBK
Copy link

AgeBK commented Jan 14, 2015

cheers @LaurentGoderre, worked a charm

@othiym23
Copy link
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.

@LaurentGoderre
Copy link

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

@mkozjak
Copy link

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.
Projects
None yet
Development

No branches or pull requests

8 participants