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.init fails silently on, "Don't overwrite an existing config" #1762

Open
rhildred opened this issue May 16, 2023 · 3 comments
Open

git.init fails silently on, "Don't overwrite an existing config" #1762

rhildred opened this issue May 16, 2023 · 3 comments

Comments

@rhildred
Copy link

using node, no bundler the following test fails

    it("does a git init with api",async () =>{
        const sDir = "test";
        const sGitDir = ".git";
        if (!fs.existsSync(sDir)) {
            fs.mkdirSync(sDir);
          }
                
        await git.init({dir:sDir, gitdir:sGitDir, fs:fs});
        const oConfig = ini.parse(fs.readFileSync(`${sDir}/${sGitDir}/config`, 'utf-8'));
        expect(oConfig.base.ignorecase).toBe(true);
    });

it returns:

FAIL spec/GitLoader.test.js > git-cli for a pwa > does a git init with api
Error: ENOENT: no such file or directory, open 'test/.git/config'

The code ends up here with gitdir not including the dir parameter (".git"):

  // Don't overwrite an existing config
  if (await fs.exists(gitdir + '/config')) return

It would be somewhat better if an error was thrown

if (await fs.exists(gitdir + '/config')){
 throw new Error("Don't overwrite existing config");
}

Better still if the .git folder was created in the specified dir.

@jcubic
Copy link
Contributor

jcubic commented May 16, 2023

Is this the test from the library or is it something that was created by you? I'm not sure but I think that gitDir is used only for bare repos, but I may be wrong. I actually never used gitDir option (maybe only at the beginning long ago when was learning how to use the library).

EDIT: I'm also not sure if you can use gitDir with dir option together.

@rhildred
Copy link
Author

Thanks for your prompt attention to this matter. The test is one that I made to reproduce the problem. You are correct, it is the dir option that I am trying to depend on. I want to git.init in a subfolder and push the code to another branch. A bit like gh_pages deploy command. I am using stackblitz and need isomorphic.git to run in their browser environment.

@jcubic
Copy link
Contributor

jcubic commented Sep 9, 2023

Sorry for the late response I'm browsing open issues. Because I was closing issues related to Salesforce that didn't catch exceptions from Isomorphic git that say to create an issue here.

If you need to make this work you will need to read the code to figure out why it doesn't work.

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