Fix incorrect redirect when branch doesn't include files

What does this MR do and why?

Contributes to #547652 (closed)

Problem

When branch doesn't include any files, the application triggers a redirect from Commit History page to the project tree. It prevents users from seeing the commit history.

Because @path value is an empty string, the validate_path code is incorrectly executed.

Solution

Change the path detection logic to handle empty string case.

References

Orphaned branch without blobs gets redirected t... (#547652 - closed)

Screenshots or screen recordings

Before After
Screenshot_2025-06-10_at_10.27.44 Screenshot_2025-06-10_at_10.26.49

How to set up and validate locally

  1. Visit http://gdk.test:3000/gitlab-org/gitlab-test/-/commits/empty-branch
  2. You should see a list of commits instead of a redirect with an error message

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #547652 (closed)

Merge request reports

Loading