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

Git config

Open germanysources opened this issue 4 years ago • 1 comments

wasm-git always commits with name Me and e-mail [email protected] when using inside web-worker. I tried creating /home/web_user/.gitconfig

 FS.writeFile('/home/web_user/.gitconfig', '[user]\n' +
                        `name = ${event.data.name}\n` +
                        `email = ${event.data.email}`);

and creating the config locally:

lg.callMain(['config', 'user.name', event.data.name]);
lg.callMain(['config', 'user.email', event.data.email]);

Both doesn't work. The complete script for the web-worker:

var Module = {
        locateFile: s => `https://unpkg.com/[email protected]/${s}`
}

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

Module.onRuntimeInitialized = () => {
        const lg = Module;
        FS.mkdir('/working');
        FS.mount(MEMFS, { }, '/working');

        const printError = err;
        let processStep;
        let terminate;
        err = obj => {
                printError(obj);
                terminate = true;
                postMessage({state: 'terminated', error: obj, processStep});
        };
        onmessage = (event) => {
                FS.writeFile('/home/web_user/.gitconfig', '[user]\n' +
                        `name = ${event.data.name}\n` +
                        `email = ${event.data.email}`);

                processStep = 'clone'
                lg.callMain([processStep, event.data.url, event.data.repo]);
                if (terminate)
                        return;
                FS.chdir(event.data.repo);

                processStep = 'checkout';
                lg.callMain([processStep, event.data.sourceBranch]);
                if (terminate)
                        return;
                processStep = 'checkout';
                lg.callMain([processStep, event.data.targetBranch]);
                if (terminate)
                        return;
                processStep = 'merge';
                lg.callMain([processStep, event.data.sourceBranch]);
                if (terminate)
                        return;
                processStep = 'push';
                lg.callMain([processStep]);
                if (terminate)
                        return;
                postMessage({state: 'merged'});
        };
        postMessage({state: 'ready'});
}

germanysources avatar Apr 15 '21 07:04 germanysources

I can't see that you have any commits in your worker, but if I copy your worker and create a commit, I get the configured user:

var Module = {
    locateFile: s => `https://unpkg.com/[email protected]/${s}`
}

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

Module.onRuntimeInitialized = () => {
    const lg = Module;
    FS.mkdir('/working');
    FS.mount(MEMFS, { }, '/working');

    const printError = err;
    let processStep;
    let terminate;
    err = obj => {
            printError(obj);
            terminate = true;
            postMessage({state: 'terminated', error: obj, processStep});
    };
    onmessage = (event) => {
            FS.writeFile('/home/web_user/.gitconfig', '[user]\n' +
                    `name = ${event.data.name}\n` +
                    `email = ${event.data.email}`);


            lg.callMain(['clone', event.data.url, event.data.repo]);
            FS.chdir(event.data.repo);

            lg.callMain(['commit', '-m', 'test']);

            processStep = 'log';
            lg.callMain(['log']);
            
    };
    postMessage({state: 'ready'});
}

When I run this worker.postMessage({name:'test',email:'[email protected]', url: 'https://wasm-git.petersalomonsen.com/test',repo: 'test', sourceBranch: 'master', 'targetBranch': 'test'});, the last commit looks like this:

commit 959ca246c3c537b3325ec74fd8c7ed0b282fc624
Author: test <[email protected]>
Date:   Thu Apr 15 19:58:10 2021 +0200

test

petersalomonsen avatar Apr 15 '21 18:04 petersalomonsen