kometenstaub / obsidian-version-history-diff

Get a diff view of your Obsidian Sync, File Recovery and Git version history
MIT License
111 stars 5 forks source link

custom base path #9

Closed cjunekim closed 2 years ago

cjunekim commented 2 years ago

Hi

This plugin doesn't seem to work with custom base path feature of Obsidian Git plugin. When it is set to a child folder and it is ran by Show Git Diff View command, it results in an error.

image

In my case, the child folder name is Subfolder and the custom base path option is set as such.

image

kometenstaub commented 2 years ago

@Vinzent03 I think that‘s something you would need to implement in the Git plugin API.

Vinzent03 commented 2 years ago

@cjunekim Is Subfolder directly below your vault? E.g desktop/myVault/Subfolder?

cjunekim commented 2 years ago

@cjunekim Is Subfolder directly below your vault? E.g desktop/myVault/Subfolder?

Yes.

Vinzent03 commented 2 years ago

Hmm tricky. @kometenstaub Am I right that you use only show, log, diff?

cjunekim commented 2 years ago

Ping. How is this going?

kometenstaub commented 2 years ago

Hmm tricky. @kometenstaub Am I right that you use only show, log, diff?

Only log and show. I don't use diff because the base implementation works on file contents that get diffed with jsdiff and not commit hashes.

kometenstaub commented 2 years ago

@Vinzent03 I think I don't use anything else, unless I've overlooked something.

https://github.com/kometenstaub/obsidian-version-history-diff/blob/main/src/git_diff_view.ts

Vinzent03 commented 2 years ago

@cjunekim Can you try updating Obsidian-Git. The issue should be fixed.

cjunekim commented 2 years ago

@Vinzent03 I still get an error as following:

plugin:obsidian-git:7354 Uncaught (in promise) Error: fatal: ambiguous argument 'A 사용법.md': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

    at Object.action (plugin:obsidian-git:10679:25)
    at PluginStore.exec (plugin:obsidian-git:10704:25)
    at eval (plugin:obsidian-git:8499:43)
    at new Promise (<anonymous>)
    at GitExecutorChain.handleTaskData (plugin:obsidian-git:8497:16)
    at GitExecutorChain.eval (plugin:obsidian-git:8481:44)
    at Generator.next (<anonymous>)
    at fulfilled (plugin:obsidian-git:7333:24)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Something notable to me is the file name 'A 사용법.md' is not the full filename. The first character is cut out. It was originally 'AA 사용법.md'(without the single quote).

Vinzent03 commented 2 years ago

@cjunekim Your git root folder is still Subfolder without any slashes at the start or end? And your file path relative to your vault is Subfolder/AA 사용법.md?

cjunekim commented 2 years ago

@cjunekim Your git root folder is still Subfolder without any slashes at the start or end? And your file path relative to your vault is Subfolder/AA 사용법.md?

Oh. I got it. The "Custom base path (Git repository path)" was set to "/Subfolder". I removed the slash at the front, and it seems to work now. Maybe there is some mishandling of slash in the filename. Thanks!

Vinzent03 commented 2 years ago

Maybe I should check/correct wrong formatting. @kometenstaub I think this can be closed now.

kometenstaub commented 2 years ago

@kometenstaub I think this can be closed now.

Thanks!

cjunekim commented 2 years ago

Oh my goodness! Recently, I had to clean install obsidian and git on a new computer and clone the repository.

This time I didn't use the custom base path. Thus, I used the git repository root as the vault directory. However, the same error happens.

fatal: ambiguous argument 'A 사용법.md': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this:

The first character of the filename is removed, which was "A"(without quotes).

On the other hand, the same computer and setting that I used before is still working. It uses the custom base path.

Maybe, it has something to do with the use of substring in https://github.com/denolehov/obsidian-git/commit/0d86e6872fa16c809f7bf71f05e344acaf31008d but I haven't looked into it seriously. What do you think @Vinzent03 ?

In obsidian version history diff plugin, it seems to call the GitManager's show function but without the optional default argument for relativeToRepo, which always defaults to false. Hence, the path3 always takes the substring route, which will skip the first character by +1 in the substring call, whether or not the plugin.settings.basePath is null.

It is strange to me that no one seems to have reported about the error yet. Obsidian version history diff would not work if the user doesn't use custom base path at all as of now.

I think it's all coming from using a simple and cheap trick of substring +1 instead of proper path handling. Even something like split by the delimiter(slash or backslash) would've been better.