feat: Allow opening a single-file diff from file history view (#6599)

This PR adds a small icon link to the file history list to open the diff for *only* this file in the respective commit. This is very useful if the commit in question touches a very large amount of files and finding the actual file in the diff is tedious.

- fixes #6596

Co-authored-by: Gusted <postmaster@gusted.xyz>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6599
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Yann Büchau <nobodyinperson@posteo.de>
Co-committed-by: Yann Büchau <nobodyinperson@posteo.de>
This commit is contained in:
Yann Büchau 2025-02-05 17:43:27 +00:00 committed by Gusted
parent d1d78c1b14
commit 0d3a759fdc
3 changed files with 13 additions and 1 deletions

View file

@ -131,7 +131,7 @@ func TestAmbiguousCharacterDetection(t *testing.T) {
})
}
func TestInHistoryButton(t *testing.T) {
func TestCommitListActions(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session := loginUser(t, user2.Name)
@ -164,6 +164,7 @@ func TestInHistoryButton(t *testing.T) {
htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href^='/%s/src/commit/']", repo.FullName()), false)
})
fileDiffSelector := fmt.Sprintf(".commit-list a[href='/%s/commit/%s?files=test.sh']", repo.FullName(), commitID)
t.Run("Commit list", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
@ -172,6 +173,7 @@ func TestInHistoryButton(t *testing.T) {
htmlDoc := NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href='/%s/src/commit/%s']", repo.FullName(), commitID), true)
htmlDoc.AssertElement(t, fileDiffSelector, false)
})
t.Run("File history", func(t *testing.T) {
@ -182,6 +184,7 @@ func TestInHistoryButton(t *testing.T) {
htmlDoc := NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href='/%s/src/commit/%s/test.sh']", repo.FullName(), commitID), true)
htmlDoc.AssertElement(t, fileDiffSelector, true)
})
})
}