Renamed files in a pull request aren't always correctly displayed

Issue #560 new
Brennan Hoeting created an issue

This issue came up in a support ticket for Bitbucket Cloud. In Bitbucket, if a user has a diff that is simply too large for us to render on the pull request view, we instruct them to review the changes locally before merging. In our case, the customer was attempting using the Atlassian VScode extension to review the PR.

We found that in some cases VScode won’t correctly show that a file is renamed.

Bitbucket VScode

In this example, we have two renamed files that can be seen in the PR on Bitbucket, but VScode is only showing one of them.

I believe I’ve figured out why this is happening. In the mergePaths function, it attempts to apply the { from → to } bit in the middle of the old file path, but that logic isn’t actually being returned by the function since it incorrectly tries to modify the array in place.

> console.log(mergePaths('README.md', 'dir/README.md'));
README.md  dir,README.md

> console.log(
  mergePaths(
    'Assets/Resources/FontData.asset',
    'Assets/Editor/Resources/FontData.asset',
  ),
);
Assets/Resources/FontData.asset

If I change the mergePaths function to do something like this, we get the desired result:

function mergePaths(oldPath, newPath) {

  ...

  return [
    ...oldPathArray.slice(0, i),
    `{${oldPathArray.slice(i).join('/')}${newPathArray.slice(i).join('/')}}`,
  ].join('/');
}

> console.log(
    mergePaths(
      'Assets/Resources/FontData.asset',
      'Assets/Editor/Resources/FontData.asset',
    ),
  );
Assets/{Resources/FontData.asset → Editor/Resources/FontData.asset}

I tried raising a PR to fix this but wasn’t able to get the extension to build locally, so I figured I should just file this as a bug for now.

Comments (2)

  1. Log in to comment