Isomorphic-git: `status` throws an error on a repository with no HEAD commit

Created on 28 Dec 2018  路  3Comments  路  Source: isomorphic-git/isomorphic-git

  • whether you are using Node or the Browser

I'm using it in a browser.

  • how you are using it (if you are using a bundler what bundler; if you are using a <script> tag what CDN URL)

The dependencies of my test are:

https://unpkg.com/[email protected]/dist/browserfs.min.js
https://unpkg.com/[email protected]/dist/bundle.umd.min.js

And here is the code:

let fsOptions = {
  fs: 'InMemory',
  options: {}
}

BrowserFS.configure(fsOptions, async function (err) {
  if (err) return console.log(err);
  const fs = BrowserFS.BFSRequire('fs');

  git.plugins.set('fs', fs);
  await git.init({ dir: '.' });

  fs.mkdir('/demo', async () => {
    fs.writeFile('/demo/test.txt', 'Testing git', 'utf8', async () => {
      console.log(await git.status({ dir: '/demo', filepath: 'test.txt' }));
    });
  });
});

I'm getting

Uncaught (in promise) s: Could not resolve reference "HEAD"

(at the line of the console.log)

Here is a demo where I'm trying to make it work https://demoit.app/e/xWj9gK7EJCV

bug released

Most helpful comment

:tada: This issue has been resolved in version 0.55.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

All 3 comments

The empty repository state is... weird. Git intentionally creates a dangling HEAD reference to a non-existing "master" branch. Once you add some files and make a commit it should be fine, but I suppose I should go through and add unit tests for everything in a "git init" state and find the commands (like status) that assume the HEAD commit exists and add extra logic to handle that case when there are no previous commits.

@wmhilton regarding blank repos. I suppose I could hack the git-server to potentially fork (by copying) a repo with a single commit, but it feels a bit hacky. Do you think this feature is on the horizon?

:tada: This issue has been resolved in version 0.55.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keshin picture keshin  路  5Comments

wmhilton picture wmhilton  路  7Comments

TomasHubelbauer picture TomasHubelbauer  路  6Comments

antoniofarina picture antoniofarina  路  3Comments

njlr picture njlr  路  5Comments