Skip to content

Follow file symlinks in the UI to their target #28835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 30, 2025

Conversation

delvh
Copy link
Member

@delvh delvh commented Jan 17, 2024

Description

Previously, when you clicked on a symlink, a document was opened that only displayed <target>.
While this follows git's behavior of implementing symlinks, it is not user-friendly for users using the web UI to access a file.
Now, symlinks are resolved when you click on a link next to them, either until a file has been found or until we know that the link is dead.
When the link cannot be accessed, we fall back to the current behavior of showing the document containing the target.

Before

Screenshots

before

After

after

delvh added 2 commits January 16, 2024 19:46
Only problem at the moment is that `git.TreeEntry` does not store the
full path of the entry, only the actual filename without directory.
@delvh delvh added type/enhancement An improvement of existing functionality topic/ui-interaction Change the process how users use Gitea instead of the visual appearance labels Jan 17, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 17, 2024
@delvh delvh added type/feature Completely new functionality. Can only be merged if feature freeze is not active. and removed type/enhancement An improvement of existing functionality labels Jan 17, 2024
@delvh
Copy link
Member Author

delvh commented Jan 17, 2024

Trivia: If we merge this, we are even ahead of GitHub in terms of behavior as GitHub still shows the <target> document instead of the linked location.

@delvh delvh changed the title Link to the symlinked file directly Follow symlinks in the UI to their target Jan 18, 2024
@delvh delvh changed the title Follow symlinks in the UI to their target Follow file symlinks in the UI to their target Jan 18, 2024
@KN4CK3R
Copy link
Member

KN4CK3R commented Jan 19, 2024

Could you add a test for TryFollowingLinks()? (valid link, link outside repo, ...)

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jan 19, 2024
@delvh
Copy link
Member Author

delvh commented Jan 19, 2024

And the test promptly caught a bug.
Welp.
I understand what the problem is, but I have no idea how to fix it adequately:
The problem is that I use fullPath = cleanedRelativePath in getTreeEntryByPath:

link points to ../nar/hello in foo/bar/link_to_hello

Expected foo/nar/hello, got nar/hello

However, I have no idea how to implement fullPath = tree.BasePath + normalizedRelativePath.
Does the tree already store this information?

@delvh
Copy link
Member Author

delvh commented Jan 20, 2024

Does the tree already store this information?

As expected, it doesn't 😒
What would be the most maintainable way to get the tree to store this information reliably?

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 2, 2024

After reading the code, I have some new ideas, maybe more simple to do: backend does nothing, but let frontend navigate.

For example:

  • There is a link in repo: /foo/bar/link => ../aaa/bbb
  • The UI just renders <a href="/org/repo/src/branch/main/foo/bar/../aaa/bbb">link</a>. Then when user clicks the link, they should be navigated to https://.../src/branch/main/foo/aaa/bbb

Otherwise, if we really would like to resolve the link in backend, I guess it needs some big refactoring to make things clear.

@delvh
Copy link
Member Author

delvh commented Mar 2, 2024

@wxiaoguang the problem with the frontend approach is that the frontend cannot recursively resolve links (latest-changelog -> /b-dir/current.txt -> /doc/internal/changes-2.30.2.md).
Apart from that, yes, it would be possible.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 2, 2024

@wxiaoguang the problem with the frontend approach is that the frontend cannot recursively resolve links (latest-changelog -> /b-dir/current.txt -> /doc/internal/changes-2.30.2.md). Apart from that, yes, it would be possible.

For me, I would like to see the direct link target on the UI, instead of recursively resolving the links ahead. For example: suppose there is a link /foo -> /bar -> /aaa -> /bbb. As an end user, I would like to see /foo points to /bar, that's also the real filesystem shows to end users (eg: ls -l). I don't expect it shows /foo points to /bbb directly, that's somewhat counter-intuitive IMO.


If an end user would like to follow, the frontend approach could also work: use a href like /bar?follow_symlink=1, then if backend reads follow_symlink, it redirects to the next target /aaa?follow_symbol=1 and again and agian.

@delvh
Copy link
Member Author

delvh commented Mar 2, 2024

But what is it you want to achieve when you click on a (symlinked) file?
In 99,9% of cases, you want to see/edit the content that is linked, not go on a journey to find the actual file.

@wxiaoguang
Copy link
Contributor

But what is it you want to achieve when you click on a (symlinked) file?
In 99,9% of cases, you want to see/edit the content that is linked, not go on a journey to find the actual file.

I updated the previous comment, a "/bar?follow_symlink=1" trick could work IMO.

@wxiaoguang
Copy link
Contributor

Are you working on this at the moment?

# Conflicts:
#	templates/repo/view_list.tmpl
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 28, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 28, 2025
@wxiaoguang
Copy link
Contributor

@delvh is there still anything to improve?

@delvh
Copy link
Member Author

delvh commented Jun 28, 2025

A quick skim over your changes looked good.
Will need to test it when I find the time, which should be tomorrow.
If the PR isn't merged until then, I'll update the description once I've re-tested it with up-to-date screenshots.
But yeah, nothing holding the PR back from my side.

@delvh
Copy link
Member Author

delvh commented Jun 30, 2025

So, I tested it out now and pushed a small fix.
It works as expected for now.
However, I can imagine a couple of improvements further down the line in future PRs:

  1. Display some sort of error when the link does not work
  2. Enhance the tooltip to show exactly where the link will lead
  3. Also add the same button when viewing the symlink directly or in a PR diff

@delvh delvh added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 30, 2025
@GiteaBot
Copy link
Collaborator

@delvh please fix the merge conflicts. 🍵

@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 30, 2025
@delvh delvh added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 30, 2025
@wxiaoguang wxiaoguang merged commit 8dbf13b into go-gitea:main Jun 30, 2025
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jun 30, 2025
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jul 1, 2025
* giteaofficial/main:
  Fix modal + form abuse (go-gitea#34921)
  [skip ci] Updated translations via Crowdin
  Follow file symlinks in the UI to their target (go-gitea#28835)
  Fix issue filter (go-gitea#34914)
  Fix: RPM package download routing & missing package version count (go-gitea#34909)
  Add support for 3D/CAD file formats preview (go-gitea#34794)
@delvh delvh deleted the link-to-symlink branch July 1, 2025 07:52
bdruth added a commit to bdruth/gitea that referenced this pull request Jul 4, 2025
…h/gitea into feature/enhanced-workflow-runs-api

* 'feature/enhanced-workflow-runs-api' of github.com:bdruth/gitea:
  [skip ci] Updated translations via Crowdin
  Follow file symlinks in the UI to their target (go-gitea#28835)
  Fix issue filter (go-gitea#34914)
  Fix: RPM package download routing & missing package version count (go-gitea#34909)
  Add support for 3D/CAD file formats preview (go-gitea#34794)
  Add a `login`/`login-name`/`username` disambiguation to affected endpoint parameters and response/request models (go-gitea#34901)
  Improve tags list page (go-gitea#34898)
  [skip ci] Updated translations via Crowdin
  docs: fix typo in pull request merge warning message text (go-gitea#34899)
  Refactor container package (go-gitea#34877)
  [skip ci] Updated translations via Crowdin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation topic/ui-interaction Change the process how users use Gitea instead of the visual appearance type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants