Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git config #28

Open
germanysources opened this issue Apr 15, 2021 · 1 comment
Open

Git config #28

germanysources opened this issue Apr 15, 2021 · 1 comment

Comments

@germanysources
Copy link

germanysources commented Apr 15, 2021

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'});
}
@petersalomonsen
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants