Closed dkbarn closed 1 month ago
Increasing the verbosity in the developer console, and it looks -- at least to an untrained eye -- like possibly the value of the --pretty=format
argument is being incorrectly encoded, because I'm seeing strange characters in it:
No I think the format is correct. I have the same command in my logs, but for me everything is working.
I'm on linux and you're on Windows, but the simple-git dependency hasn't changed for quite some releases and I think if it would impact all Windows machines I've gotten more of these issues. So I don't know that this causes.
Is there any way that I can increase logging, or are there instructions for how I can run a debug build of the plugin, so I can get more intensive debugging information and hopefully zero in on the cause of the error?
I've managed to build a debug release of the plugin and have increased the logging verbosity in the simple-git dependency, but I'm still not certain on what exactly is causing the error.
The error occurs within the "git-refresh" event, specifically when calling simpleGit.getLastCommitTime()
method, which then uses simple-git to invoke a git log
command. I suspect that the problem is specific to Windows, in the way that simple-git is constructing the git log command. It appears that the --pretty=format
argument is being incorrectly truncated.
Why is this plugin dependent on a fork of simple-git? Why does https://github.com/Vinzent03/git-js exist? I can see that it was last updated a year and a half ago and has fallen behind https://github.com/steveukx/git-js by several versions.
Is it possible that this old forked copy of simple-git is no longer compatible with the newest versions of Git for Windows? Can we try removing the fork and depending directly on https://github.com/steveukx/git-js ?
I had to switch to my own work, to faster ship a fix I've made to simple-git, but that's already merged and released by simple-git as well. So you're right, I've switched now to the new simple-git versions on the master branch. So you can try the newest version out (remember to install the new version with pnpm install
)
I doubt git has introduced any breaking changes in this regard, though.
I think you're right, it's unlikely the bug is the result of a newer version of git or anything like that. The problem is that something somewhere is putting a stray "
on the front of the --pretty=format
argument to git log
. I'm able to reproduce the same error message outside of Obsidian, by interacting with git directly on the command line:
$ git -c core.quotepath=off log '"--pretty=format:òòòòòò %H ò %aI ò 128 ò %D ò %b ò %aN ò %aE òò' --max-count=1
fatal: invalid object name '"--pretty=format'.
The question is where is that stray "
coming from?
I have put together a minimal Node.js application that uses the exact same simple-git package in https://github.com/Vinzent03/git-js and then run the same git.log
function that is producing the error inside Obsidian. When I run this on the command line through Node, the error does not happen, it all works as expected. So the bug is introduced in the environment of Obsidian.
import simpleGit from "simple-git";
const vaultDir= "C:\\Users\\dkbarn\\Documents\\Obsidian Vault"
const git = simpleGit({
baseDir: vaultDir,
config: ["core.quotepath=off"],
})
git.cwd(vaultDir).then(res => {
console.log("git cwd result:", res);
});
git.log({ n: 1 }, (err) => {
if (err) {
console.error("Error occurred during git log:", err);
}
})
.then(res => {
console.log("git log result:", res);
});
Next I will try interactively debugging the plugin by setting a breakpoint from inside Obsidian and see if get anywhere with that. I can't wait see what is at the end of this tunnel, it's sure to be bizarre and facepalm-y considering no one else seems to be experiencing this but me...
Ok so the problem is the presence of unicode characters in the arguments passed to ChildProcess. In stepping through the execution of the code, I can see that the args array is set to:
"-c"
"core.quotepath=off"
"log"
"--pretty=format:òòòòòò %H ò %aI ò %s ò %D ò %b ò %aN ò %aE òò"
"--max-count=1"
all the way up until the spawning of the child process. So the arguments are not being incorrectly manipulated from within the JavaScript runtime, it is not until the child process is spawned that the --pretty=format:
argument gets truncated at the first unicode character.
This tells me that my Windows environment is incorrectly encoding the unicode characters in the child process.
I have confirmed that if I modify the source code of simple-git, by changing these lines:
export const START_BOUNDARY = 'òòòòòò ';
export const COMMIT_BOUNDARY = ' òò';
export const SPLITTER = ' ò ';
to be:
export const START_BOUNDARY = 'mystartbndry ';
export const COMMIT_BOUNDARY = ' mycommitbndry';
export const SPLITTER = ' mysplitter ';
which ensures that no unicode characters make it into the git command, then I avoid the error completely from within Obsidian, and everything works successfully.
I am able to reproduce the problem without the obsidian-git or simple-git involved at all, using the following code.
@Vinzent03 , please could you try running the following from within the developer console in Obsidian? Be sure to change the gitRepoPath.
const { spawn } = require('child_process');
const gitRepoPath = "C:/Users/dkbarn/Documents/Obsidian Vault"; // Change to your Git repo directory
const gitProcess = spawn('git', [
'-c', 'core.quotepath=off',
'log',
'--pretty=format:òòòòòò %H ò %aI ò 128 ò %D ò %b ò %aN ò %aE òò',
'--max-count=1'
], {
cwd: gitRepoPath
});
let stdoutData = '';
let stderrData = '';
gitProcess.stdout.on('data', (data) => {
stdoutData += data.toString();
});
gitProcess.stderr.on('data', (data) => {
stderrData += data.toString();
});
gitProcess.on('exit', (code) => {
console.log(`Git process exited with code ${code}`);
console.log('stdout:', stdoutData);
console.log('stderr:', stderrData);
});
gitProcess.on('error', (err) => {
console.error('Failed to start git process:', err);
});
When I run this, I get stderr: fatal: Invalid object name '"--pretty=format'
I guess works fine for me. I get the following stdout: 'òòòòòò 750941ab3ff9e2f7e592a98847e720ea19ddbca6 ò 2024-10-10T11:10:53+02:00 ò 128 ò HEAD -> Test ò ò Vinzent ò vinzent03@proton.me òò'
This works for me on Windows and Linux.
Interesting. Can you tell me, on Windows, if you open cmd.exe and run the command "chcp", what is the output?
UGH. I have finally fixed the issue. Turns out, even though I had installed Git for Windows v2.46, that is not the version that was actually being used by Obsidian or from cmd.exe, because there was an older version (v2.21) bundled with Cygwin64 that was overriding it in the system $PATH. So I removed that version and am now picking up v2.46 everywhere and the problem is resolved!
Describe the bug
I am unable to "Commit-and-sync" with a fresh install of Obsidian + Git plugin on Windows.
On my first attempt at performing the "Commit-and-sync" action, it fails to commit, and the following is the output to the developer console.
Relevant errors (if available) from notifications or console (
CTRL+SHIFT+I
)Steps to reproduce
Expected Behavior
No response
Addition context
Debug info copied from settings:
Operating system
Windows
Installation Method
None
Plugin version
2.27.0