obsidian-git icon indicating copy to clipboard operation
obsidian-git copied to clipboard

[Bug]: Conflict files do not change during merging when custom base path is empty

Open sweatran opened this issue 2 years ago • 0 comments

Describe the bug

Hi, I'm a new user of this plugin.

When I test this plugin on my mobile devices, I found the exact same problem described in issue #558.

Normally the file with conflicts should looks like this after merging:

<<<<<<< HEAD
File changes in local repository
=======
File changes in remote repository
>>>>>>> origin/main

But what I saw is like:

File changes in local repository

Nothing is changed in the file after merging. This behavior only appears on mobile devices (on my Android phone and iPad).

After serveral hours of viewing codes and debugging, I figured out that it was because I used the default emtpy Custom base path.

The reason is that, isomorphic-git will simply skip the process of changing all conflict files when a emtpy dir argument (which is set by Custom base path) is threw into the merge function, as shown in line 178~196 in mergeTree.js:

if (unmergedFiles.length !== 0) {
    if (dir && !abortOnConflict) {    // Here is the problem
      await _walk({    // Change all conflict files
        fs,
        cache,
        dir,
        gitdir,
        trees: [TREE({ ref: results.oid })],
        map: async function(filepath, [entry]) {
          const path = `${dir}/${filepath}`
          if ((await entry.type()) === 'blob') {
            const mode = await entry.mode()
            const content = new TextDecoder().decode(await entry.content())
            await fs.write(path, content, { mode })
          }
          return true
        },
      })
    }

So to avoid this, changing Custom base path to ./ is just enough.

Honestly I have no idea if it is a bug of isomorphic-git, or there's some purposes behind it, but it really causes quite annoying trouble without knowing such a detail.

I think the best way to solve this problem forever is never allowing Custom base path to be set as emtpy, at least filling with ./ or .\ for safety.

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

No response

Steps to reproduce

Steps have been fully descripted in issue #558.

Expected Behavior

No response

Addition context

No response

Operating system

Android

Installation Method

None

Plugin version

2.22.0

sweatran avatar Oct 10 '23 19:10 sweatran