gitforge/modules/git
Mathieu Fenniak 9fe0cbee02 fix: relocate PR review comments using git blame --reverse, improving comment placement (#12015)
When a review comment is placed on a PR in Forgejo, Forgejo performs a `git blame` to identify which commit originated the line, and records that commit and line number in the comment's database record.  Later when the review is viewed, Forgejo currently makes no effort to place that comment in the correct *current* location, which may vary -- for example, if a PR had two commits and the comment was made on a line in the first commit, but the second commit changes line numbers in that file, the comment will appear in the incorrect location.

This PR adds the usage of `git blame --reverse` to calculate the correct location to display the comment in the current view (whether reviewing the PR commit-by-commit, or "Files changed").  It certainly does not fix all problems with comment placement (see comments).

Another major addition in this PR is a test harness for making relatively complex PRs and reviewing the diffs on the per-commit view and PR-diff views.

## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. All work and communication must conform to Forgejo's [AI Agreement](https://codeberg.org/forgejo/governance/src/branch/main/AIAgreement.md). There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests for Go changes

- I added test coverage for Go changes...
  - [x] in their respective `*_test.go` for unit tests.
  - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I ran...
  - [ ] `make pr-go` before pushing

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [x] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change.
- [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change.

<!--start release-notes-assistant-->

## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- Bug fixes
  - [PR](https://codeberg.org/forgejo/forgejo/pulls/12015): <!--number 12015 --><!--line 0 --><!--description cmVsb2NhdGUgUFIgcmV2aWV3IGNvbW1lbnRzIHVzaW5nIGBnaXQgYmxhbWUgLS1yZXZlcnNlYCwgaW1wcm92aW5nIGNvbW1lbnQgcGxhY2VtZW50-->relocate PR review comments using `git blame --reverse`, improving comment placement<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12015
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2026-04-11 21:45:39 +02:00
..
foreachref chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
internal
pipeline
pushoptions chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
tests/repos fix: detect renames when using diff-tree (#11038) 2026-01-25 15:51:18 +01:00
url
batch.go
batch_reader.go chore: handle error types consistently (#9873) 2026-03-06 00:48:06 +01:00
blame.go
blame_sha256_test.go
blame_test.go
blob.go fix: internal server error on a large .gitmodules (#10744) 2026-01-10 10:44:59 +01:00
blob_test.go feat(ui): add switch between formats when previewing CITATION.{cff,bib} files (#9103) 2025-11-14 14:39:20 +01:00
command.go fix: store pull mirror creds encrypted with keying (#11909) 2026-04-04 13:53:22 +02:00
command_race_test.go
command_test.go
commit.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
commit_info.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
commit_info_test.go
commit_reader.go
commit_sha256_test.go
commit_test.go chore: two small refactors in git module (#10109) 2025-11-15 13:24:00 +01:00
diff.go ci: detect and prevent empty case statements in Go code (#11593) 2026-03-10 02:50:28 +01:00
diff_compare.go
diff_compare_test.go chore: fix typos throughout the codebase (#10753) 2026-01-26 22:57:33 +01:00
diff_test.go chore: fix typos throughout the codebase (#10753) 2026-01-26 22:57:33 +01:00
error.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
fetch.go chore: unify the usage of CryptoRandomString (#10110) 2025-11-15 13:24:53 +01:00
fetch_test.go
git.go fix: make Fetch work with git < 2.41 (#10095) 2025-11-13 13:22:09 +01:00
git_test.go
grep.go feat: add support to opt-in for fuzzy search (#10378) 2025-12-17 13:51:48 +01:00
grep_test.go
hook.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
last_commit_cache.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
log_name_status.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
notes.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
notes_test.go
object_format.go
object_id.go
object_id_test.go
object_signature.go
parse.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
parse_test.go
README.md
ref.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
ref_test.go
remote.go
repo.go fix: store pull mirror creds encrypted with keying (#11909) 2026-04-04 13:53:22 +02:00
repo_archive.go
repo_attribute.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
repo_attribute_test.go
repo_base.go
repo_base_test.go
repo_blame.go fix: relocate PR review comments using git blame --reverse, improving comment placement (#12015) 2026-04-11 21:45:39 +02:00
repo_blame_test.go fix: relocate PR review comments using git blame --reverse, improving comment placement (#12015) 2026-04-11 21:45:39 +02:00
repo_blob_test.go
repo_branch.go
repo_branch_test.go
repo_commit.go chore: fix typos throughout the codebase (#10753) 2026-01-26 22:57:33 +01:00
repo_commit_test.go chore: two small refactors in git module (#10109) 2025-11-15 13:24:00 +01:00
repo_commitgraph.go
repo_compare.go fix: detect renames when using diff-tree (#11038) 2026-01-25 15:51:18 +01:00
repo_compare_test.go fix: detect renames when using diff-tree (#11038) 2026-01-25 15:51:18 +01:00
repo_gpg.go
repo_hook.go
repo_index.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
repo_language_stats.go
repo_language_stats_test.go
repo_object.go
repo_ref.go
repo_ref_test.go
repo_stats.go ci: detect and prevent empty case statements in Go code (#11593) 2026-03-10 02:50:28 +01:00
repo_stats_test.go
repo_tag.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
repo_tag_test.go chore: require.ErrorContains() is intended, but require.Errorf() is used (#11035) 2026-01-25 19:48:15 +01:00
repo_test.go fix: support git clone when /tmp has noexec (#10146) 2025-11-19 16:36:34 +01:00
repo_tree.go
signature.go
signature_test.go
submodule.go fix: internal server error on a large .gitmodules (#10744) 2026-01-10 10:44:59 +01:00
submodule_test.go
tag.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
tag_test.go
tree.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
tree_blob.go
tree_entry.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
tree_entry_mode.go
tree_test.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
utils.go
utils_test.go

Git Module

This module is merged from https://github.com/go-gitea/git which is a Go module to access Git through shell commands. Now it's a part of gitea's main repository for easier pull request.