aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
Commit message (Collapse)AuthorAgeFilesLines
* Reduce integration test overhead (#32475)Rowan Bohde2024-11-1416-51/+0
| | | | | | | | | | | | | In profiling integration tests, I found a couple places where per-test overhead could be reduced: * Avoiding disk IO by synchronizing instead of deleting & copying test Git repository data. This saves ~100ms per test on my machine * When flushing queues in `PrintCurrentTest`, invoke `FlushWithContext` in a parallel. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Refactor LFS SSH and internal routers (#32473)wxiaoguang2024-11-121-3/+2
| | | | | | | | | | | | | | | | | | Gitea instance keeps reporting a lot of errors like "LFS SSH transfer connection denied, pure SSH protocol is disabled". When starting debugging the problem, there are more problems found. Try to address most of them: * avoid unnecessary server side error logs (change `fail()` to not log them) * figure out the broken tests/user2/lfs.git (added comments) * avoid `migratePushMirrors` failure when a repository doesn't exist (ignore them) * avoid "Authorization" (internal&lfs) header conflicts, remove the tricky "swapAuth" and use "X-Gitea-Internal-Auth" * make internal token comparing constant time (it wasn't a serous problem because in a real world it's nearly impossible to timing-attack the token, but good to fix and backport) * avoid duplicate routers (introduce AddOwnerRepoGitLFSRoutes) * avoid "internal (private)" routes using session/web context (they should use private context) * fix incorrect "path" usages (use "filepath") * fix incorrect mocked route point handling (need to check func nil correctly) * split some tests from "git general tests" to "git misc tests" (to keep "git_general_test.go" simple) Still no correct result for Git LFS SSH tests. So the code is kept there (`tests/integration/git_lfs_ssh_test.go`) and a FIXME explains the details.
* Fix git error handling (#32401)wxiaoguang2024-11-022-34/+10
|
* Fix clean tmp dir (#32360)Lunny Xiao2024-10-291-13/+23
| | | | | | | | | | | | 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>
* update git book link to v2 (#32221)Ehsan Shirvanian2024-10-091-2/+2
| | | | | | Fix the dead link `https://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository` for empty repositories to help how to clone the repository to `https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository` which is v2 of the git book. This also updates download git links
* bump to go 1.23 (#31855)techknowlogick2024-09-101-1/+1
|
* Refactor the usage of batch catfile (#31754)Lunny Xiao2024-08-2013-72/+179
| | | | | | | | | | 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.
* Fix `IsObjectExist` with gogit (#31790)Jason Song2024-08-093-9/+119
| | | | | | | | | | | | | 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.
* Add `TAGS` to `TEST_TAGS` and fix bugs found with gogit (#31791)Jason Song2024-08-072-1/+15
| | | | | | | | | | | 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`. 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.
* Fix protected branch files detection on pre_receive hook (#31778)Lunny Xiao2024-08-064-7/+74
| | | | | | | | | | | | | | | 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.
* Fix slow patch checking with commits that add or remove many files (#31548)Brecht Van Lommel2024-07-041-8/+27
| | | | | | | | | | | | | 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.
* Refactor sha1 and time-limited code (#31023)wxiaoguang2024-05-202-0/+25
| | | | | | | Remove "EncodeSha1", it shouldn't be used as a general purpose hasher (just like we have removed "EncodeMD5" in #28622) Rewrite the "time-limited code" related code and write better tests, the old code doesn't seem quite right.
* Make "sync branch" also sync object format and add tests (#30878)wxiaoguang2024-05-061-27/+0
|
* Make sure git version&feature are always prepared (#30877)wxiaoguang2024-05-0612-124/+93
| | | Otherwise there would be more similar issues like #29287
* Improve grep search (#30843)wxiaoguang2024-05-032-0/+22
| | | | Reduce the context line number to 1, make "git grep" search respect the include/exclude patter, and fix #30785
* Resolve lint for unused parameter and unnecessary type arguments (#30750)Chongyi Zheng2024-04-296-24/+14
| | | | | | | | | | Resolve all cases for `unused parameter` and `unnecessary type arguments` Related: #30729 --------- Co-authored-by: Giteabot <teabot@gitea.io>
* 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