summaryrefslogtreecommitdiffstats
path: root/modules/git
Commit message (Collapse)AuthorAgeFilesLines
* Fix gogit `GetRefCommitID` (#32705) (#32712)Giteabot2024-12-042-2/+34
| | | | | | | | | | | | Backport #32705 by @Zettat123 Fix #32335 When we call `GetRefCommitID` and the reference is already a commit ID, the `GetRefCommitID` with go-git will return a `NotExist` error. This PR improves the `GetRefCommitID` for go-git. If the input is already a commit ID, it will be returned directly. Co-authored-by: Zettat123 <zettat123@gmail.com>
* Fix clean tmp dir (#32360) (#32593)Lunny Xiao2024-11-221-13/+23
| | | | | | | | | | | Backport #32360 Try to fix #31792 Credit to @jeroenlaylo Copied from https://github.com/go-gitea/gitea/issues/31792#issuecomment-2311920520 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Fix submodule parsing (#32571) (#32577)wxiaoguang2024-11-212-14/+64
| | | | A quick fix for #32568 Partially backport from #32571
* Refactor internal routers (partial backport, auth token const time ↵wxiaoguang2024-11-131-3/+2
| | | | | | | | | | | | | | comparing) (#32473) (#32479) Partially backport #32473. LFS related changes are not in 1.22, so skip them. 1. Ignore non-existing repos during migrations 2. Improve ReadBatchLine's comment 3. Use `X-Gitea-Internal-Auth` header for internal API calls and make the comparing constant time (it wasn't a serous problem because in a real world it's nearly impossible to timing-attack the token, but indeed security related and good to fix and backport) 4. Fix route mock nil check
* Refactor the usage of batch catfile (#31754) (#31889)Giteabot2024-08-2113-72/+179
| | | | | | | | | | | | | | Backport #31754 by @lunny When opening a repository, it will call `ensureValidRepository` and also `CatFileBatch`. But sometimes these will not be used until repository closed. So it's a waste of CPU to invoke 3 times git command for every open repository. This PR removed all of these from `OpenRepository` but only kept checking whether the folder exists. When a batch is necessary, the necessary functions will be invoked. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix `IsObjectExist` with gogit (#31790) (#31806)Giteabot2024-08-093-9/+119
| | | | | | | | | | | | | | | | Backport #31790 by @wolfogre Fix #31271. When gogit is enabled, `IsObjectExist` calls `repo.gogitRepo.ResolveRevision`, which is not correct. It's for checking references not objects, it could work with commit hash since it's both a valid reference and a commit object, but it doesn't work with blob objects. So it causes #31271 because it reports that all blob objects do not exist. Co-authored-by: Jason Song <i@wolfogre.com>
* Fix protected branch files detection on pre_receive hook (#31778) (#31796)Giteabot2024-08-084-7/+74
| | | | | | | | | | | | | | | | | | | Backport #31778 by @lunny Fix #31738 When pushing a new branch, the old commit is zero. Most git commands cannot recognize the zero commit id. To get the changed files in the push, we need to get the first diverge commit of this branch. In most situations, we could check commits one by one until one commit is contained by another branch. Then we will think that commit is the diverge point. And in a pre-receive hook, this will be more difficult because all commits haven't been merged and they actually stored in a temporary place by git. So we need to bring some envs to let git know the commit exist. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Add `TAGS` to `TEST_TAGS` and fix bugs found with gogit (#31791) (#31795)Giteabot2024-08-072-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | Backport #31791 by @wolfogre Found at https://github.com/go-gitea/gitea/pull/31790#issuecomment-2272898915 `unit-tests-gogit` never work since the workflow set `TAGS` with `gogit`, but the Makefile use `TEST_TAGS`. <img width="690" alt="image" src="https://github.com/user-attachments/assets/fb68df49-952b-42b9-8438-44200cefff43"> ![image](https://github.com/user-attachments/assets/78ff88c7-3b5f-4d50-9c58-e607bf7b1a71) This PR adds the values of `TAGS` to `TEST_TAGS`, ensuring that setting `TAGS` is always acceptable and avoiding confusion about which one should be set. After this PR: <img width="714" alt="image" src="https://github.com/user-attachments/assets/54cc7f38-d95b-4dbc-a87c-daba63462b86"> Co-authored-by: Jason Song <i@wolfogre.com>
* Fix slow patch checking with commits that add or remove many files (#31548) ↵Giteabot2024-07-051-8/+27
| | | | | | | | | | | | | | | | | | | (#31560) Backport #31548 by @brechtvl Running git update-index for every individual file is slow, so add and remove everything with a single git command. When such a big commit lands in the default branch, it could cause PR creation and patch checking for all open PRs to be slow, or time out entirely. For example, a commit that removes 1383 files was measured to take more than 60 seconds and timed out. With this change checking took about a second. This is related to #27967, though this will not help with commits that change many lines in few files. Co-authored-by: Brecht Van Lommel <brecht@blender.org>
* Refactor sha1 and time-limited code (#31023) (#31030)Giteabot2024-05-212-0/+25
| | | | | Backport #31023 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Make sure git version&feature are always prepared (#30877) (#30879)wxiaoguang2024-05-0712-124/+93
| | | Backport #30877
* Make "sync branch" also sync object format and add tests (#30878) (#30880)Giteabot2024-05-071-27/+0
| | | | | Backport #30878 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Improve grep search (#30843) (#30850)Giteabot2024-05-032-0/+22
| | | | | | | | Backport #30843 by wxiaoguang Reduce the context line number to 1, make "git grep" search respect the include/exclude patter, and fix #30785 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Update misspell to 0.5.1 and add `misspellings.csv` (#30573)silverwind2024-04-271-1/+1
| | | | | | Misspell 0.5.0 supports passing a csv file to extend the list of misspellings, so I added some common ones from the codebase. There is at least one typo in a API response so we need to decided whether to revert that and then likely remove the dict entry.
* Fix incorrect object id hash function (#30708)wxiaoguang2024-04-263-15/+8
| | | | | | | | | | | | | Great thanks to @oliverpool for figuring out the problem and proposing a fix. Regression of #28138 Incorrect hash causes the user's LFS files get all deleted when running `doctor fix all` (by the way, remove unused/non-standard comments) Co-authored-by: Giteabot <teabot@gitea.io>
* Deduplicate lfs common code (#30704)wxiaoguang2024-04-263-48/+42
|
* Enable more `revive` linter rules (#30608)silverwind2024-04-225-11/+8
| | | | | | | | | | | Noteable additions: - `redefines-builtin-id` forbid variable names that shadow go builtins - `empty-lines` remove unnecessary empty lines that `gofumpt` does not remove for some reason - `superfluous-else` eliminate more superfluous `else` branches Rules are also sorted alphabetically and I cleaned up various parts of `.golangci.yml`.
* Fix commit file status parser (#30602)wxiaoguang2024-04-191-1/+1
| | | Try to fix #30492
* Refactor cache and disable go-chi cache (#30417)wxiaoguang2024-04-131-11/+4
| | | use built-in cache package to wrap external go-chi cache package
* Limit the max line length when parsing git grep output (#30418)wxiaoguang2024-04-122-4/+26
|
* Refactor commit signature parser (#30228)wxiaoguang2024-04-017-98/+134
| | | | | | | To make it more flexible and support SSH signature. The existing tests are not changed, there are also tests covering `parseTagRef` which also calls `parsePayloadSignature` now. Add some new tests to `Test_parseTagData`
* Include encoding in signature payload (#30174)KN4CK3R2024-03-293-0/+75
| | | | | | | | | | | | | Fixes #30119 Include the encoding in the signature payload. before ![grafik](https://github.com/go-gitea/gitea/assets/1666336/01ab94a3-8af5-4d6f-be73-a10b65a15421) after ![grafik](https://github.com/go-gitea/gitea/assets/1666336/3a37d438-c70d-4d69-b178-d170e74aa683)
* Fix git grep search limit, add test (#30071)wxiaoguang2024-03-252-1/+17
| | | Fix #30069
* Support repo code search without setting up an indexer (#29998)wxiaoguang2024-03-244-7/+159
| | | | | | | | | | | | | | | | | By using git's ability, end users (especially small instance users) do not need to enable the indexer, they could also benefit from the code searching feature. Fix #29996 ![image](https://github.com/go-gitea/gitea/assets/2114189/11b7e458-88a4-480d-b4d7-72ee59406dd1) ![image](https://github.com/go-gitea/gitea/assets/2114189/0fe777d5-c95c-4288-a818-0427680805b6) --------- Co-authored-by: silverwind <me@silverwind.io>
* Fix some pending problems (#29985)wxiaoguang2024-03-222-6/+5
| | | | | | | | | | | | | | | | | These changes are quite independent and trivial, so I don't want to open too many PRs. * https://github.com/go-gitea/gitea/pull/29882#discussion_r1529607091 * the `f.Close` should be called properly * the error message could be more meaningful (https://github.com/go-gitea/gitea/pull/29882#pullrequestreview-1942557935) * https://github.com/go-gitea/gitea/pull/29859#pullrequestreview-1942324716 * the new translation strings don't take arguments * https://github.com/go-gitea/gitea/pull/28710#discussion_r1443778807 * stale for long time * #28140 * a form was forgotten to be changed to work with backend code
* Fix loadOneBranch panic (#29938)wxiaoguang2024-03-201-1/+1
| | | | | | Try to fix #29936 Far from ideal, but still better than panic.
* Fix missing error check of bufio.Scanner (#29882)coldWater2024-03-192-0/+9
| | | maybe more
* Lazy load object format with command line and don't do it in OpenRepository ↵Lunny Xiao2024-03-1215-31/+72
| | | | | | | (#29712) Most time, when invoking `git.OpenRepository`, `objectFormat` will not be used, so it's a waste to invoke commandline to get the object format. This PR make it a lazy operation, only invoke that when necessary.
* remove repetitive words (#29695)pengqiseven2024-03-111-1/+1
| | | Signed-off-by: pengqiseven <912170095@qq.com>
* Move get/set default branch from git package to gitrepo package to hide ↵Lunny Xiao2024-03-081-9/+2
| | | | repopath (#29126)
* Make wiki default branch name changable (#29603)wxiaoguang2024-03-062-4/+4
| | | | | | | | | Fix #29000 Fix #28685 Fix #18568 Related: #27497 And by the way fix #24036, add a Cancel button there (one line)
* Add a check for when the command is canceled by the program on Window… ↵charles2024-03-021-0/+12
| | | | | | | | | | | | | | | | | | (#29538) Close #29509 Windows, unlike Linux, does not have signal-specified exit codes. Therefore, we should add a Windows-specific check for Windows. If we don't do this, the logs will always show a failed status, even though the command actually works correctly. If you check the Go source code in exec_windows.go, you will see that it always returns exit code 1. ![image](https://github.com/go-gitea/gitea/assets/30816317/9dfd7c70-9995-47d9-9641-db793f58770c) The exit code 1 does not exclusively signify a SIGNAL KILL; it can indicate any issue that occurs when a program fails.
* Use `crypto/sha256` (#29386)KN4CK3R2024-02-251-2/+1
| | | | | | | | Go 1.21 improved the performance of `crypto/sha256`. It's now similar to `minio/sha256-simd`, so we should just use the standard libs. https://go.dev/doc/go1.21#crypto/sha256 https://go-review.googlesource.com/c/go/+/408795 https://github.com/multiformats/go-multihash/pull/173
* Add `io.Closer` guidelines (#29387)KN4CK3R2024-02-253-5/+10
| | | Co-authored-by: Yarden Shoham <git@yardenshoham.com>
* Refactor modules/git global variables (#29376)wxiaoguang2024-02-252-19/+21
| | | Move some global variables into a struct to improve maintainability
* Refactor git attributes (#29356)KN4CK3R2024-02-246-60/+80
|
* Do not double close reader (#29354)KN4CK3R2024-02-241-1/+11
| | | | | | | Fixes #29346 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Add support for `linguist-detectable` and `linguist-documentation` (#29267)KN4CK3R2024-02-233-69/+104
| | | | | | | | | Add support for `linguist-detectable` and `linguist-documentation` Add tests for the attributes https://github.com/github-linguist/linguist/blob/master/docs/overrides.md#detectable https://github.com/github-linguist/linguist/blob/master/docs/overrides.md#documentation
* Discard unread data of `git cat-file` (#29297)KN4CK3R2024-02-2210-80/+66
| | | | | | | | | | | Fixes #29101 Related #29298 Discard all read data to prevent misinterpreting existing data. Some discard calls were missing in error cases. --------- Co-authored-by: yp05327 <576951401@qq.com>
* Prevent double use of `git cat-file` session. (#29298)KN4CK3R2024-02-211-6/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes the reason why #29101 is hard to replicate. Related #29297 Create a repo with a file with minimum size 4097 bytes (I use 10000) and execute the following code: ```go gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, <repo>) assert.NoError(t, err) commit, err := gitRepo.GetCommit(<sha>) assert.NoError(t, err) entry, err := commit.GetTreeEntryByPath(<file>) assert.NoError(t, err) b := entry.Blob() // Create a reader r, err := b.DataAsync() assert.NoError(t, err) defer r.Close() // Create a second reader r2, err := b.DataAsync() assert.NoError(t, err) // Should be no error but is ErrNotExist defer r2.Close() ``` The problem is the check in `CatFileBatch`: https://github.com/go-gitea/gitea/blob/79217ea63c1f77de7ca79813ae45950724e63d02/modules/git/repo_base_nogogit.go#L81-L87 `Buffered() > 0` is used to check if there is a "operation" in progress at the moment. This is a problem because we can't control the internal buffer in the `bufio.Reader`. The code above demonstrates a sequence which initiates an operation for which the code thinks there is no active processing. The second call to `DataAsync()` therefore reuses the existing instances instead of creating a new batch reader.
* bump to use go 1.22 (#29119)techknowlogick2024-02-141-7/+7
|
* Refactor git version functions and check compatibility (#29155)wxiaoguang2024-02-142-30/+70
| | | | | | | | | | | | Introduce a new function checkGitVersionCompatibility, when the git version can't be used by Gitea, tell the end users to downgrade or upgrade. The refactored functions are related to make the code easier to test. And simplify the comments for "safe.directory" --------- Co-authored-by: delvh <dev.lh@web.de>
* Add merge style `fast-forward-only` (#28954)Chris Copeland2024-02-121-1/+1
| | | | | | | | | With this option, it is possible to require a linear commit history with the following benefits over the next best option `Rebase+fast-forward`: The original commits continue existing, with the original signatures continuing to stay valid instead of being rewritten, there is no merge commit, and reverting commits becomes easier. Closes #24906
* Refactor parseSignatureFromCommitLine (#29054)wxiaoguang2024-02-098-149/+104
| | | | | | | | | | | | Replace #28849. Thanks to @yp05327 for the looking into the problem. Fix #28840 The old behavior of newSignatureFromCommitline is not right. The new parseSignatureFromCommitLine: 1. never fails 2. only accept one format (if there is any other, it could be easily added) And add some tests.
* Simplify how git repositories are opened (#28937)Lunny Xiao2024-01-274-105/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Purpose This is a refactor toward building an abstraction over managing git repositories. Afterwards, it does not matter anymore if they are stored on the local disk or somewhere remote. ## What this PR changes We used `git.OpenRepository` everywhere previously. Now, we should split them into two distinct functions: Firstly, there are temporary repositories which do not change: ```go git.OpenRepository(ctx, diskPath) ``` Gitea managed repositories having a record in the database in the `repository` table are moved into the new package `gitrepo`: ```go gitrepo.OpenRepository(ctx, repo_model.Repo) ``` Why is `repo_model.Repository` the second parameter instead of file path? Because then we can easily adapt our repository storage strategy. The repositories can be stored locally, however, they could just as well be stored on a remote server. ## Further changes in other PRs - A Git Command wrapper on package `gitrepo` could be created. i.e. `NewCommand(ctx, repo_model.Repository, commands...)`. `git.RunOpts{Dir: repo.RepoPath()}`, the directory should be empty before invoking this method and it can be filled in the function only. #28940 - Remove the `RepoPath()`/`WikiPath()` functions to reduce the possibility of mistakes. --------- Co-authored-by: delvh <dev.lh@web.de>
* Check for sha256 support to use --object-format flag (#28928)John Olheiser2024-01-251-1/+3
| | | | | | | | | | | | This should fix https://github.com/go-gitea/gitea/issues/28927 Technically older versions of Git would support this flag as well, but per https://github.com/go-gitea/gitea/pull/28466 that's the version where using it (object-format=sha256) left "experimental" state. `sha1` is (currently) the default, so older clients should be unaffected in either case. Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Update go dependencies and fix go-git (#28893)wxiaoguang2024-01-232-3/+12
| | | | | More details are in the comment of repo_base_gogit.go And ref: https://github.com/go-git/go-git/issues/1006
* Add support for sha256 repositories (#23894)Adam Majer2024-01-1966-15/+539
| | | | | | | | | | | | | | | | Currently only SHA1 repositories are supported by Gitea. This adds support for alternate SHA256 with the additional aim of easier support for additional hash types in the future. Fixes: #13794 Limited by: https://github.com/go-git/go-git/issues/899 Depend on: #28138 <img width="776" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/5448c9a7-608e-4341-a149-5dd0069c9447"> --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
* Fix archive creating LFS hooks and breaking pull requests (#28848)Brecht Van Lommel2024-01-191-0/+5
| | | | | | | | | | | | | | | | | | | | | | When LFS hooks are present in gitea-repositories, operations like git push for creating a pull request fail. These repositories are not meant to include LFS files or git push them, that is handled separately. And so they should not have LFS hooks. Installing git-lfs on some systems (like Debian Linux) will automatically set up /etc/gitconfig to create LFS hooks in repositories. For most git commands in Gitea this is not a problem, either because they run on a temporary clone or the git command does not create LFS hooks. But one case where this happens is git archive for creating repository archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the system configuration for that command. According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git commands because the system configuration can be intentionally set up for Gitea to use. Resolves #19810, #21148
* Remove duplicated checkinit on git module (#28824)Lunny Xiao2024-01-171-4/+0
| | | | `checkInit` has been invoked in `InitSimple`. So it's unnecessary to invoke it twice in `InitFull`.