CodeOwnerApprovalCheck: Fix exception when no old path is set for deletion

For deleted files we expect that that the old path is present and that
no new path is set. However for deleted files in merge commits that
resolved a conflict between a file modification in the destination
branch and a deletion in the source branch, the new path was present and
the old path was not set when the comparison was done against the
AutoMerge. This caused an IllegalStateException in
CodeOwnerApprovalCheck saying "old path must be present for
deletion/rename".

The reason for this was that PatchListEntry sets the old path as new
name and the old name is unset (see PatchListEntry constructor), which
is inconsistent with DiffEntry. PatchListEntry is only used when the
comparison is done against the AutoMerge which is why we didn't catch
this bug with the existing tests for file deletions. To fix this we now
get the old path from the new name field in PatchListEntry when we are
constructing a ChangedFile instance from a PatchListEntry for a file
deletion.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I99fd443317f360456bfe3199ac2819b7b19ff0d7
3 files changed
tree: f61edf6f17c7c4b257c3ff6200414f0c3f0bfc09
  1. java/
  2. javatests/
  3. proto/
  4. resources/
  5. test/
  6. ui/
  7. .eslintrc.json
  8. .gitignore
  9. .gitreview
  10. bower.json
  11. BUILD
  12. LICENSE
  13. package-lock.json
  14. package.json
  15. README.md
README.md

Gerrit Code Review code-owners plugin

This plugin provides support for defining code owners for files in a repository.

If the code-owners plugin is enabled, changes can only be submitted if all touched files are covered by approvals from code owners.

Also see resources/Documentation/about.md

IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide, see resources/Documentation/setup-guide.md