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

[Bug]: Git init doesn't work properly when a custom git-dir value is set through the 'Custom Git directory path' setting #714

Open
fabalorian opened this issue Apr 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@fabalorian
Copy link

Describe the bug

When a value is set in the Custom Git directory path (Instead of '.git') setting before running the git-init command, any command run after git-init would fail and return an error.

Relevant errors (if available) from notifications or console (CTRL+SHIFT+I)

fatal: this operation must be run in a work tree

Steps to reproduce

  1. In the plugin settings, set a value to Custom Git directory path (Instead of '.git'). For example git
  2. Restart Obsidian
  3. Run the Initialize a new repo command. In my example, it will create a directory called git
  4. Try to run another command (e.g. the command Commit all changes)

Expected Behavior

Git commands should work and not trigger an error.
Running the command git --git-dir=git worktree list from the CLI after running git-ini should return the path to the repo followed by 0000000 [master]

Addition context

Running the command git --git-dir=git worktree list from the CLI after the init indicates that the repo is bare. It shouldn't be the case.
I think this is due to the fact that --git-dir=<git-dir> is used as a parameter to the git-init command.
According to my tests with Git CLI, git init --separate-git-dir=<git-dir> should be used instead. These two parameters cannot be used together.
As a result, the init command will also create a .git text file containing the path to git-dir. This file can be removed as git-dir is already specified in the plugin settings.

Refer to the git-init doc for more details.

Workarounds

If no custom git-dir value has been set in the plugin settings (CLI not required):

  1. Run the Initialize a new repo command
  2. Rename the .git directory to <git-dir>
  3. Set the git-dir plugin setting to <git-dir>
  4. Restart Obsidian

If a custom git-dir value has already been set in the settings (requires using the CLI):

  1. Use git CLI to manually run the command git init --separate-git-dir=<git-dir>
  2. Delete the .git text file that's been automatically created (optional)

Operating system

Windows

Installation Method

None

Plugin version

2.24.1

@fabalorian fabalorian added the bug Something isn't working label Apr 5, 2024
@fabalorian
Copy link
Author

To fix this bug I think you need to edit the simpleGit.ts file on line 647.

Based on the simple-git doc about the git-init command, you'd need to create a condition that tests if gitDir is set.
If it is, then use the following command instead await this.git.init({ '--separate-git-dir': gitDir }, (err) => this.onError(err)); and then delete the .git test file created in the base folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant