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:
parent
d1d78c1b14
commit
0d3a759fdc
|
@ -1453,6 +1453,7 @@ commits.signed_by_untrusted_user_unmatched = Signed by untrusted user who does n
|
||||||
commits.gpg_key_id = GPG key ID
|
commits.gpg_key_id = GPG key ID
|
||||||
commits.ssh_key_fingerprint = SSH key fingerprint
|
commits.ssh_key_fingerprint = SSH key fingerprint
|
||||||
commits.view_path=View at this point in history
|
commits.view_path=View at this point in history
|
||||||
|
commits.view_single_diff = View changes to this file introduced in this commit
|
||||||
|
|
||||||
commit.operations = Operations
|
commit.operations = Operations
|
||||||
commit.revert = Revert
|
commit.revert = Revert
|
||||||
|
|
|
@ -81,6 +81,14 @@
|
||||||
<td class="text right aligned tw-py-0">
|
<td class="text right aligned tw-py-0">
|
||||||
<button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{.ID}}">{{svg "octicon-copy"}}</button>
|
<button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{.ID}}">{{svg "octicon-copy"}}</button>
|
||||||
{{if not $.PageIsWiki}}
|
{{if not $.PageIsWiki}}
|
||||||
|
{{if $.FileName}}
|
||||||
|
<a
|
||||||
|
class="btn interact-bg tw-p-2"
|
||||||
|
data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_single_diff"}}"
|
||||||
|
href="{{printf "%s/commit/%s?files=%s" $commitRepoLink (PathEscape .ID.String) (PathEscapeSegments $.FileName)}}">
|
||||||
|
{{svg "octicon-file-diff"}}
|
||||||
|
</a>
|
||||||
|
{{end}}
|
||||||
<a
|
<a
|
||||||
class="btn interact-bg tw-p-2"
|
class="btn interact-bg tw-p-2"
|
||||||
data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}"
|
data-tooltip-content="{{ctx.Locale.Tr "repo.commits.view_path"}}"
|
||||||
|
|
|
@ -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) {
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
session := loginUser(t, user2.Name)
|
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)
|
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) {
|
t.Run("Commit list", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
@ -172,6 +173,7 @@ func TestInHistoryButton(t *testing.T) {
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
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, 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) {
|
t.Run("File history", func(t *testing.T) {
|
||||||
|
@ -182,6 +184,7 @@ func TestInHistoryButton(t *testing.T) {
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
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, fmt.Sprintf(".commit-list a[href='/%s/src/commit/%s/test.sh']", repo.FullName(), commitID), true)
|
||||||
|
htmlDoc.AssertElement(t, fileDiffSelector, true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue