git version 1.7.1 ( I have no power over this, on this server )
I have a private repo with several submodules, some of which are also private.
The submodules which are not private are coming in without issue. However the first private repo encountered returns this
ssh: Could not resolve hostname bitbucket.org:username: Name or service not known
, and the process stops here.
As per the docs, I have set up a deployment key for the staging server and have created an ~/.ssh/config
alias to point bitbucket.org to that key. This is working as the private parent repo is pulling in just fine.
The staging server has a few locked files in the environment which I have to work around, so I am initialising as follows:
git init
git remote add origin ssh://git@bitbucket.org/user/parent-repo.git
git fetch
git checkout -t origin/master
So far so good but the submodules are empty:
# Update submodules
git submodule update --init --recursive
# git submodule update --remote # Not available in 1.7.1
git submodule foreach git pull origin master
## git fetch --recurse-submodules=yes # introduced 1.7.3
Here is where things go wrong and ssh can't connect and the process halts on the first private repo. This isn't totally surprising as to access private repos, we need to associate another key, which cannot be the same as the one associated with the account. (scroll down to 'Private repos" heading for some interesting comments in this article by Luke Woodward)
So after making individual (I could have created just one) keys and creating ssh aliases for each of them (on the staging server), I'm stuck as to how to reference those key properly.
Just to be sure the aliases are working we can test them with:
ssh -Tv git@<alias>
Which when successful returns a lot of output ending with:
.... authenticated via a deploy key. You can use git or hg to connect to Bitbucket. Shell access is disabled. This deploy key has read access to the following repositories: XXXXX
Here is what I've tried so far. After each change, Im running:
git submodule update --init --recursive
git submodule foreach git pull origin master
EDIT: as suggested in comments re updating the links, at this point a git submodule sync
will sync all submodules which have already completed a pull. None of the private repos will be listed in this operation. So sadly this operation does not seem to address issues with missing private repos.
- change paths to ssh key aliases
.gitmodules
Result:
ssh: Could not resolve hostname bitbucket.org:username
It looks like an alias is resolving, but something is blocking the key?
- change paths to ssh key aliases in
.git/config
.
Result:
ssh: Could not resolve hostname <alias>:username
Obviously the alias isn't resolving at all.
As option 1 seemed to be at least making the ssh request, I manipulated the ssh alias that I thought was routing the request to the proper key. There must be some caching in effect, because changing the host on the alias to something impossible like bitbucketXXX.org
. The result was the same error: ssh: Could not resolve hostname bitbucket.org:username
. I would have thought the error would have read ssh: Could not resolve hostname *bitbucketXXX.org:username*
--HUMMMM
Update: After a bit of thought
My approach so far has been to create an ssh key alias linking bitbucket.org to the parent key that I established for this server in my personal bitbucket settings.
When that didn't work for subs, I set up keys for each of them, and then on the server, aliases for each of them too, but keeping the parent repo key the same as before. Thus far i've been hunting for ways to reference these aliased-keys in .gitmodules
and in .git/config
. But this simply isn't working, the parent key is being recognised, but aliases for submodules keys are not.
My last approach has been to make one common key (different from my account key, they wont let you do that) and assign it to the parent repo, and each submodule. On the server, the alias for bitbucket.org points to this common key.
now when I test it with ssh -Tv git@bitbucket.org
after a lot of output, we get:
authenticated via a deploy key.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
This deploy key has read access to the following repositories:
*A list of all the repos associated with that key*
While this looks promising, the result is the same ssh: Could not resolve hostname . . .
I've even tried absorbing the user name into the alias like so
Host bitbucket.org:<user_name>
HostName bitbucket.org
IdentityFile ~/.ssh/shared_bb_key
but this results in conq: invalid repository syntax.
At this point I can't see the forest, never mind trees. Any thoughts?