gatsby-source-git
gatsby-source-git copied to clipboard
Clone fails when the remote is ssh and option is specified in https
It took me a while to figure this one out, so bear with the long description.
I am currently using gatsby-source-git
to source MD files from another Git repo. We'll call this Content
repo. Now I've already cloned the Content
repo on my local.
I've configured gatsby-source-git
as follows:
{
resolve: `gatsby-source-git`,
options: {
name: 'blog-content',
remote: 'https://github.com/PsyGik/content.git',
local: '/Development/Personal/blog-content/',
branch: 'master',
patterns: 'content/**',
},
},
When running gatsby develop
, it fails with an error:
ERROR
localPath is not defined
This kind of throws a wrench into the whole debugging process. Like, WTF is localPath
. Thankfully, it took little time to figure that out.
throw new Error(`Can't clone to target destination: ${localPath}`);
localPath
is being used outside of it's scope. Classic JS scope issue! 🤦🏽 Fixed this line, and now started getting the expected output, Can't clone to target destination: ...
Now, since I already have the repo cloned, it shouldn't fail with the clone again. I was stumped as to why the clone was failing. So I started debugging isAlreadyCloned
method. Lo and Behold, the remote were different. Same, but different.
Existing Remote: [email protected]:PsyGik/content.git
Remote: https://github.com/PsyGik/content.git
So obviously, the equality check failed, because I am a dumb genius who prefers ssh over https remotes. 🥇
I also found out the hard way, that the plugin overrides local changes and always prefers remote changes. I am not sure why it does that, but I'll be investigating more on this.
What should be done?
Mention something in the README that this plugin clones using whatever remote
option is specified. So it's upto the user to make sure that the remote urls are in sync. And that the plugin overrrides the content on every gatsby develop
Kick-ass plugin btw. Thank you! 🍻