<p dir="auto">I am pretty sure this is going to affect <em>any</em> install from a git remote with a ref that's not found in the origin.  But I encountered it trying to install a PR, and haven't investigated further.</p>
<p dir="auto">Instead of "remote reference not found in git repository", or some other helpful thing, it does this.</p>
<h3 dir="auto">Current Behavior:</h3>
<p dir="auto">Pacote fails with a git folder issue.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ npm i npm/pacote#pull/55
npm ERR! code 128
npm ERR! command failed
npm ERR! command git clone --mirror -q ssh://git@github.com/npm/pacote.git /Users/isaacs/.npm/_cacache/tmp/git-clone-00c3d7a2/.git
npm ERR! fatal: destination path '/Users/isaacs/.npm/_cacache/tmp/git-clone-00c3d7a2/.git' already exists and is not an empty directory.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/isaacs/.npm/_logs/2021-05-03T00_17_29_111Z-debug.log"><pre class="notranslate"><code class="notranslate">$ npm i npm/pacote#pull/55
npm ERR! code 128
npm ERR! command failed
npm ERR! command git clone --mirror -q ssh://git@github.com/npm/pacote.git /Users/isaacs/.npm/_cacache/tmp/git-clone-00c3d7a2/.git
npm ERR! fatal: destination path '/Users/isaacs/.npm/_cacache/tmp/git-clone-00c3d7a2/.git' already exists and is not an empty directory.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/isaacs/.npm/_logs/2021-05-03T00_17_29_111Z-debug.log
</code></pre></div>
<h3 dir="auto">Expected Behavior:</h3>
<p dir="auto">Report that <code class="notranslate">pull/55</code> isn't a thing that exists in the npm/pacote repository.</p>
<h3 dir="auto">Environment:</h3>
<p dir="auto">macOS, npm 7.11.2</p>
<p dir="auto">My bet is that this is a bug in either <code class="notranslate">pacote</code> or <code class="notranslate">@npmcli/git</code>, but I haven't dug any further into it as yet.</p>
<p dir="auto">### Current Behavior:</p>

<h3 dir="auto">Expected Behavior:</h3>
<p dir="auto"><code class="notranslate">npm install</code> with erroneous git version on a github  dependency whines about cache "already exists"</p>
<h3 dir="auto">Steps To Reproduce:</h3>
<ol dir="auto">
<li>with a fresh npm package.json, add a dep for a non-existent branch, e.g.<code class="notranslate">"dependencies": { "shex-test": "github:shexSpec/shexTest#master" }</code></li>
<li><code class="notranslate">npm install --cache /tmp/brand-new-cache</code></li>
</ol>
<h3 dir="auto">Environment:</h3>
<ul dir="auto">
<li>OS: Ubuntu 20.04</li>
</ul>
<h3 dir="auto">Error Message:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="eric@touchy:/tmp/npmz/npm-user$ npm install --cache /tmp/brand-new-cache
npm ERR! code 128
npm ERR! command failed
npm ERR! command git clone --mirror -q ssh://git@github.com/shexSpec/shexTest.git /tmp/brand-new-cache/_cacache/tmp/git-clone-e421e02b/.git
npm ERR! fatal: destination path '/tmp/brand-new-cache/_cacache/tmp/git-clone-e421e02b/.git' already exists and is not an empty directory.

npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/brand-new-cache/_logs/2021-04-25T16_32_24_722Z-debug.log"><pre class="notranslate"><code class="notranslate">eric@touchy:/tmp/npmz/npm-user$ npm install --cache /tmp/brand-new-cache
npm ERR! code 128
npm ERR! command failed
npm ERR! command git clone --mirror -q ssh://git@github.com/shexSpec/shexTest.git /tmp/brand-new-cache/_cacache/tmp/git-clone-e421e02b/.git
npm ERR! fatal: destination path '/tmp/brand-new-cache/_cacache/tmp/git-clone-e421e02b/.git' already exists and is not an empty directory.

npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/brand-new-cache/_logs/2021-04-25T16_32_24_722Z-debug.log
</code></pre></div>
<p dir="auto">The real prob had nothing to do with the cache, but simply that the <code class="notranslate">master</code> branch was renamed to <code class="notranslate">main</code> (which makes this a timely UI experience to improve).</p>
<p dir="auto">Related issue:<br>
If you change to an existent branch (e.g. <code class="notranslate">main</code>), <code class="notranslate">npm i</code>, change back, and <code class="notranslate">npm i</code> again, you see no error. The <code class="notranslate">package-lock.json</code> entry was changed to <code class="notranslate">"shex-test": "github:shexSpec/shexTest#master"</code> but the node_modules entry appeared to stay on <code class="notranslate">main</code>. While playing with this, i had to reset to square 1 with <code class="notranslate">rm -rf node_modules/ package-lock.json /tmp/brand-new-cache/</code> to get around this overly agreeable behavior.</p>