wasm-git icon indicating copy to clipboard operation
wasm-git copied to clipboard

Stops working because can't find user.name after a few commits and pushes

Open omert opened this issue 2 years ago • 7 comments

Here's something that seems to be a bug. I'm running the following webworker code on chrome. The index.html file is the same as in the examples directory, as is githttpserver.js. It all works, until the last push which fails.

var Module = {
  locateFile: function(s) {
    return 'https://unpkg.com/[email protected]/' + s;
  }
};

importScripts('https://unpkg.com/[email protected]/lg2.js');

Module.onRuntimeInitialized = () => {
  
  FS.mkdir('/working');
  FS.mount(MEMFS, { }, '/working');
  FS.chdir('/working');    
  
  FS.writeFile('/home/web_user/.gitconfig', '[user]\n' +
               'name = Test User\n' +
               'email = [email protected]');
  
  
  Module.callMain(['clone','http://localhost:5000/test.git', 'testrepo']);
  FS.chdir('/working/testrepo');    
  
  text = '';
  for (let i = 0; i < 6; i++) {
    console.log(i);
    text += 'x';
    FS.writeFile('./test.txt', text);
    Module.callMain(['add', '.']);
    Module.callMain(['commit','-m','commit ' + (i+1)]);
    Module.callMain(['push']);
  }
  
}

The error message is

Error creating signature [-3] - config value 'user.name' was not found

More specifically, here's what the console shows:

Screenshot from 2022-09-18 11-05-00

Clearly user.name is defined fine, since it works for the first 5 pushes.

Finally, note that this code uses unpkg.com/[email protected]. The same happens with unpkg.com/[email protected], but unpkg.com/[email protected] and below work fine.

omert avatar Sep 18 '22 18:09 omert

Thanks for reporting. I see that in another wasm-git worker I have here: https://github.com/petersalomonsen/javascriptmusic/commit/d16c94cfd85c852a279cee6d33881599ad2670b7#diff-b31f3e9b8374a4100e65e8acc63ba737cabcff3908f2f9b44771752380f4839aR87

I removed writing directly to the config file and instead called the git config command like this:

      callMain(['config', 'user.name', username]);
      callMain(['config', 'user.email', useremail]);

Will you try that in your worker, and I'll also see how to get this right with wasm-git. I'm not sure yet if it is because of the latest emscripten version or the wasm-git code, but I'll look into it.

petersalomonsen avatar Sep 19 '22 16:09 petersalomonsen

Thanks! That works.

omert avatar Sep 19 '22 17:09 omert

So I've managed to reproduce your bug here: https://github.com/petersalomonsen/wasm-git/pull/54/files#diff-865d0671bf01f79dadb619dae1e7a8e72d4aa828b5393f4f87a9c99b79be07cf

It seems to happen when there are several commits following each other, no need to push.

Will look into a fix for it then.

petersalomonsen avatar Sep 20 '22 18:09 petersalomonsen

Thanks a lot for taking a look at this!

omert avatar Sep 20 '22 20:09 omert

yeah.. just tried upgrading to libgit2-1.4.4, but didn't make any difference. not sure yet if the problem is with wasm-git or libgit2. you did not try this directly with libgit2 by any chance?

since you mention that wasm-git 0.0.6 and below work fine, there was an upgrade to using libgit2-1.3.0 in 0.0.7.. so the problem might have been introduced in libgit 1.3.0

petersalomonsen avatar Sep 22 '22 20:09 petersalomonsen

Sorry, I did not.

omert avatar Sep 22 '22 20:09 omert

all right. libgit2 1.5.0 seems to fix the problem. tested it locally, just a small issue with the -std=c90 flag that I have to find a way to get properly configured. For testing it I just replaced it manually right now, but it can handle the repeated commits test case.

work in progress here: https://github.com/petersalomonsen/wasm-git/pull/54

petersalomonsen avatar Sep 23 '22 20:09 petersalomonsen

Seems all good to me at least. Feel free to give it a try before I merge (and release it): https://github.com/petersalomonsen/wasm-git/pull/54

petersalomonsen avatar Sep 24 '22 14:09 petersalomonsen

Perfect! Works for me too. Thanks a lot!

omert avatar Sep 24 '22 16:09 omert