aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
Commit message (Collapse)AuthorAgeFilesLines
* Fix panic when cloning with wrong ssh format. (#32076) (#32118)Giteabot2024-09-241-4/+7
| | | | | Backport #32076 by @lunny Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Prevent update pull refs manually and will not affect other refs update ↵Giteabot2024-09-021-0/+14
| | | | | | | | | | | | | | | | (#31931) (#31955) Backport #31931 by @lunny All refs under `refs/pull` should only be changed from Gitea inside but not by pushing from outside of Gitea. This PR will prevent the pull refs update but allow other refs to be updated on the same pushing with `--mirror` operations. The main changes are to add checks on `update` hook but not `pre-receive` because `update` will be invoked by every ref but `pre-receive` will revert all changes once one ref update fails. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* fix: allow actions artifacts storage migration to complete succesfully ↵Giteabot2024-06-051-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | (#31251) (#31257) Backport #31251 by @bohde Change the copy to use `ActionsArtifact.StoragePath` instead of the `ArtifactPath`. Skip artifacts that are expired, and don't error if the file to copy does not exist. --- When trying to migrate actions artifact storage from local to MinIO, we encountered errors that prevented the process from completing successfully: * The migration tries to copy the files using the per-run `ArtifactPath`, instead of the unique `StoragePath`. * Artifacts that have been marked expired and had their files deleted would throw an error * Artifacts that are pending, but don't have a file uploaded yet will throw an error. This PR addresses these cases, and allow the process to complete successfully. Co-authored-by: Rowan Bohde <rowan.bohde@gmail.com>
* Move database operations of merging a pull request to post receive hook and ↵Giteabot2024-05-081-0/+3
| | | | | | | | | | | | | | | | | | | | | add a transaction (#30805) (#30888) Backport #30805 by @lunny Merging PR may fail because of various problems. The pull request may have a dirty state because there is no transaction when merging a pull request. ref https://github.com/go-gitea/gitea/pull/25741#issuecomment-2074126393 This PR moves all database update operations to post-receive handler for merging a pull request and having a database transaction. That means if database operations fail, then the git merging will fail, the git client will get a fail result. There are already many tests for pull request merging, so we don't need to add a new one. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Fix missing migrate actions artifacts (#30874) (#30886)Giteabot2024-05-071-8/+16
| | | | | | | | Backport #30874 by @lunny The actions artifacts should be able to be migrate to the new storage place. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Make sure git version&feature are always prepared (#30877) (#30879)wxiaoguang2024-05-072-6/+3
| | | Backport #30877
* Add some tests to clarify the "must-change-password" behavior (#30693)wxiaoguang2024-04-275-12/+67
| | | | | | | | | | Follow #30472: When a user is created by command line `./gitea admin user create`: Old behavior before #30472: the first user (admin or non-admin) doesn't need to change password. Revert to the old behavior before #30472
* Enable more `revive` linter rules (#30608)silverwind2024-04-221-1/+1
| | | | | | | | | | | 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`.
* Add --skip-db option to dump command (#30613)Kemal Zebari2024-04-211-24/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Attempts to resolve #28720. --- Note that I am not a Gitea administrator so I don't normally use the gitea CLI. Just saw this issue and wanted an opportunity to understand how this subcommand works and see if I can add this feature :^) I tested both with `--skip-db` and without and it appears to not add any database-specific files to the generated archive i.e. I don't see a `gitea-db.sql` or `gitea.db` file: ```console $ TAGS="bindata sqlite sqlite_unlock_notify" make backend Running go generate... bindata for migration already up-to-date bindata for options already up-to-date bindata for public already up-to-date bindata for templates already up-to-date $ ./gitea dump --skip-db 2024/04/20 01:16:11 ...s/setting/session.go:77:loadSessionFrom() [I] Session Service Enabled 2024/04/20 01:16:11 ...s/storage/storage.go:176:initAttachments() [I] Initialising Attachment storage with type: local 2024/04/20 01:16:11 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspaces/gitea/data/attachments 2024/04/20 01:16:11 ...s/storage/storage.go:166:initAvatars() [I] Initialising Avatar storage with type: local 2024/04/20 01:16:11 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspaces/gitea/data/avatars 2024/04/20 01:16:11 ...s/storage/storage.go:192:initRepoAvatars() [I] Initialising Repository Avatar storage with type: local 2024/04/20 01:16:11 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspaces/gitea/data/repo-avatars 2024/04/20 01:16:11 ...s/storage/storage.go:186:initLFS() [I] Initialising LFS storage with type: local 2024/04/20 01:16:11 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspaces/gitea/data/lfs 2024/04/20 01:16:11 ...s/storage/storage.go:198:initRepoArchives() [I] Initialising Repository Archive storage with type: local 2024/04/20 01:16:11 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspaces/gitea/data/repo-archive 2024/04/20 01:16:11 ...s/storage/storage.go:208:initPackages() [I] Initialising Packages storage with type: local 2024/04/20 01:16:11 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspaces/gitea/data/packages 2024/04/20 01:16:11 ...s/storage/storage.go:219:initActions() [I] Initialising Actions storage with type: local 2024/04/20 01:16:11 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspaces/gitea/data/actions_log 2024/04/20 01:16:11 ...s/storage/storage.go:223:initActions() [I] Initialising ActionsArtifacts storage with type: local 2024/04/20 01:16:11 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspaces/gitea/data/actions_artifacts 2024/04/20 01:16:11 cmd/dump.go:172:runDump() [I] Dumping local repositories... /workspaces/gitea/data/gitea-repositories 2024/04/20 01:16:11 cmd/dump.go:195:runDump() [I] Skipping database 2024/04/20 01:16:11 cmd/dump.go:229:runDump() [I] Adding custom configuration file from /workspaces/gitea/custom/conf/app.ini 2024/04/20 01:16:11 cmd/dump.go:256:runDump() [I] Packing data directory.../workspaces/gitea/data 2024/04/20 01:16:11 cmd/dump.go:335:runDump() [I] Finish dumping in file /workspaces/gitea/gitea-dump-1713575771.zip $ unzip /workspaces/gitea/gitea-dump-1713575771.zip -d example Archive: /workspaces/gitea/gitea-dump-1713575771.zip . . . $ ls example/ app.ini custom data repos $ ls example/data/ actions_artifacts actions_log avatars home indexers jwt queues repo-archive repo-avatars tmp ``` Co-authored-by: Giteabot <teabot@gitea.io>
* chore: use errors.New to replace fmt.Errorf with no parameters will much ↵Cheng2024-04-217-11/+15
| | | | | better (#30621) use errors.New to replace fmt.Errorf with no parameters will much better
* Improve "must-change-password" logic and document (#30472)wxiaoguang2024-04-142-25/+27
| | | | | Unify the behaviors of "user create" and "user change-password". Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Performance optimization for git push (#30104)Lunny Xiao2024-04-091-13/+22
| | | | | Agit returned result should be from `ProcReceive` hook but not `PostReceive` hook. Then for all non-agit pull requests, it will not check the pull requests for every pushing `refs/pull/%d/head`.
* Clean up log messages (#30313)wxiaoguang2024-04-071-1/+1
| | | | | | `log.Xxx("%v")` is not ideal, this PR adds necessary context messages. Remove some unnecessary logs. Co-authored-by: Giteabot <teabot@gitea.io>
* Refactor "dump" sub-command (#30240)wxiaoguang2024-04-031-223/+63
| | | | | | | | | | Major changes: * Move some functions like "addReader" / "isSubDir" / "addRecursiveExclude" to a separate package, and add tests * Clarify the filename&dump type logic and add tests * Clarify the logger behavior and remove FIXME comments Co-authored-by: Giteabot <teabot@gitea.io>
* Move some asymkey functions to service layer (#28894)Lunny Xiao2024-03-041-2/+2
| | | | After the moving, all models will not depend on `util.Rename` so that I can do next step refactoring.
* Start to migrate from `util.OptionalBool` to `optional.Option[bool]` (#29329)65432024-02-231-4/+4
| | | just create transition helper and migrate two structs
* Refactor cmd setup and remove deadcode (#29313)wxiaoguang2024-02-222-13/+2
| | | | | | * use `setup(ctx, c.Bool("debug"))` like all other callers * `setting.RunMode = "dev"` is a no-op. * `if _, err := os.Stat(setting.RepoRootPath); err != nil` could be simplified
* Refactor JWT secret generating & decoding code (#29172)wxiaoguang2024-02-161-1/+1
| | | | | | | | Old code is not consistent for generating & decoding the JWT secrets. Now, the callers only need to use 2 consistent functions: NewJwtSecretWithBase64 and DecodeJwtSecretBase64 And remove a non-common function Base64FixedDecode from util.go
* Fix push to create with capitalize repo name (#29090)Lunny Xiao2024-02-081-5/+7
| | | Fix #29073
* Unify user update methods (#28733)KN4CK3R2024-02-041-23/+21
| | | | | | | | | | | Fixes #28660 Fixes an admin api bug related to `user.LoginSource` Fixed `/user/emails` response not identical to GitHub api This PR unifies the user update methods. The goal is to keep the logic only at one place (having audit logs in mind). For example, do the password checks only in one method not everywhere a password is updated. After that PR is merged, the user creation should be next.
* Add `must-change-password` cli parameter (#27626)KN4CK3R2024-02-031-1/+9
| | | | | | | | | | This PR adds a new `must-change-password` parameter to the `change-password` cli command. We already have the `must-change-password` command but it feels natural to have this integrated into the `change-password` cli command. --------- Co-authored-by: 6543 <6543@obermui.de>
* Simplify how git repositories are opened (#28937)Lunny Xiao2024-01-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## 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>
* Fix migrate storage bug (#28830)Lunny Xiao2024-01-201-0/+6
|
* Move doctor package from modules to services (#28856)Lunny Xiao2024-01-202-2/+2
|
* Return `responseText` instead of string in some functions (#28836)yp053272024-01-193-3/+3
| | | | Follow https://github.com/go-gitea/gitea/pull/28796#issuecomment-1891727591
* Move more functions to db.Find (#28419)Lunny Xiao2024-01-151-2/+2
| | | | | | | | | Following #28220 This PR move more functions to use `db.Find`. --------- Co-authored-by: delvh <dev.lh@web.de>
* Recommend/convert to use case-sensitive collation for MySQL/MSSQL (#28662)wxiaoguang2024-01-101-2/+2
| | | | | | | | | | | | | | | | | | Mainly for MySQL/MSSQL. It is important for Gitea to use case-sensitive database charset collation. If the database is using a case-insensitive collation, Gitea will show startup error/warning messages, and show the errors/warnings on the admin panel's Self-Check page. Make `gitea doctor convert` work for MySQL to convert the collations of database & tables & columns. * Fix #28131 ## :warning: BREAKING :warning: It is not quite breaking, but it's highly recommended to convert the database&table&column to a consistent and case-sensitive collation.
* Improve ObjectFormat interface (#28496)Lunny Xiao2023-12-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | The 4 functions are duplicated, especially as interface methods. I think we just need to keep `MustID` the only one and remove other 3. ``` MustID(b []byte) ObjectID MustIDFromString(s string) ObjectID NewID(b []byte) (ObjectID, error) NewIDFromString(s string) (ObjectID, error) ``` Introduced the new interfrace method `ComputeHash` which will replace the interface `HasherInterface`. Now we don't need to keep two interfaces. Reintroduced `git.NewIDFromString` and `git.MustIDFromString`. The new function will detect the hash length to decide which objectformat of it. If it's 40, then it's SHA1. If it's 64, then it's SHA256. This will be right if the commitID is a full one. So the parameter should be always a full commit id. @AdamMajer Please review.
* Improve CLI code and descriptions (#28482)wxiaoguang2023-12-158-28/+19
| | | | | | | | | | * Close #28444 * Actually, it doesn't need to use that trick because it looks like it is not necessary, no user really needs it * Remove the hidden (legacy) "doctor" subcommand and update documents * Fix "actions" usage ![image](https://github.com/go-gitea/gitea/assets/2114189/3c2b34a7-4f92-4a6c-96fd-9505e413d4ec)
* Abstract hash function usage (#28138)Adam Majer2023-12-131-2/+5
| | | | | | Refactor Hash interfaces and centralize hash function. This will allow easier introduction of different hash function later on. This forms the "no-op" part of the SHA256 enablement patch.
* Improve doctor cli behavior (#28422)wxiaoguang2023-12-112-28/+56
| | | | | | 1. Do not sort the "checks" slice again and again when "Register", it just wastes CPU when the Gitea instance runs 2. If a check doesn't exist, tell the end user 3. Add some tests
* Use db.Find instead of writing methods for every object (#28084)Lunny Xiao2023-11-241-1/+2
| | | | For those simple objects, it's unnecessary to write the find and count methods again and again.
* fixed duplicate attachments on dump on windows (#28019)Anudeep Reddy2023-11-141-1/+1
| | | | | | | | | | | | | | | | | | Hi, This PR fixes #27988. The use of `path.join`(which uses `/` as the file separator) to construct paths and comparing them with paths constructed using `filepath.join`(which uses platform specific file separator) is the root cause of this issue. The desired behavior is to ignore attachments when dumping data directory. Due to the what's mentioned above, the function `addRecursiveExclude` is not actually ignoring the attachments directory and is being written to the archive. The attachment directory is again added to the archive (with different file separator as mentioned in the issue) causing a duplicate entry on windows. The solution is to use `filepath.join` in `addResursiveExclude` to construct `currentAbsPath`.
* Refactor Find Sources and fix bug when view a user who belongs to an ↵Lunny Xiao2023-11-031-1/+1
| | | | | | | | | | | | unactive auth source (#27798) The steps to reproduce it. First, create a new oauth2 source. Then, a user login with this oauth2 source. Disable the oauth2 source. Visit users -> settings -> security, 500 will be displayed. This is because this page only load active Oauth2 sources but not all Oauth2 sources.
* Final round of `db.DefaultContext` refactor (#27587)JakobDev2023-10-141-1/+1
| | | Last part of #27065
* Penultimate round of `db.DefaultContext` refactor (#27414)JakobDev2023-10-115-31/+31
| | | | | | | Part of #27065 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* make writing main test easier (#27270)Lunny Xiao2023-09-281-3/+1
| | | | | | | | | This PR removed `unittest.MainTest` the second parameter `TestOptions.GiteaRoot`. Now it detects the root directory by current working directory. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* move the `gitea admin` subcommands into separate files (#27307)Nanguan Lin2023-09-277-619/+670
| | | | | As title. Probably it's better to put those sub cmd to different dirs. Will do that in the future.
* Another round of `db.DefaultContext` refactor (#27103)JakobDev2023-09-252-3/+4
| | | | | | | Part of #27065 --------- Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* More refactoring of `db.DefaultContext` (#27083)JakobDev2023-09-152-3/+3
| | | Next step of #27065
* Reduce usage of `db.DefaultContext` (#27073)JakobDev2023-09-142-4/+4
| | | | | | | | | | | | | | Part of #27065 This reduces the usage of `db.DefaultContext`. I think I've got enough files for the first PR. When this is merged, I will continue working on this. Considering how many files this PR affect, I hope it won't take to long to merge, so I don't end up in the merge conflict hell. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* fix: typo (#27009)MomentQYC2023-09-111-1/+1
|
* clarify aspects of the dump command (#26887)JonRB2023-09-031-1/+1
| | | | | | | | | clarify aspects of the dump command Possibly closes #26862 --------- Co-authored-by: delvh <dev.lh@web.de>
* Expanded minimum RSA Keylength to 3072 (#26604)mainboarder2023-08-281-1/+1
| | | | | | | | | | | | | | | German Federal Office for Information Security requests in its technical guideline BSI TR-02102-1 RSA Keylength not shorter than 3000bits starting 2024, in the year 2023 3000bits as a recommendation. Gitea should request longer RSA Keys by default in favor of security and drop old clients which do not support longer keys. https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Publikationen/TechnischeRichtlinien/TR02102/BSI-TR-02102.pdf?__blob=publicationFile&v=9 - Page 19, Table 1.2 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Handle base64 decoding correctly to avoid panic (#26483)wxiaoguang2023-08-141-2/+2
| | | Fix the panic if the "base64 secret" is too long.
* Fix stderr usages (#26477)wxiaoguang2023-08-131-2/+1
|
* Refactor tests (#26464)wxiaoguang2023-08-121-2/+2
| | | | 1. Give the global variable clear names 2. Use generic parameter for `onGiteaRun`
* Call git.InitSimple for runRepoSyncReleases (#26396)wxiaoguang2023-08-101-0/+4
| | | | | | Fix #26394 Otherwise, the git module is not initialized and it doesn't respect the "timeout" config in app.ini
* Fix incorrect CLI exit code and duplicate error message (#26346)wxiaoguang2023-08-052-16/+85
| | | Follow the CLI refactoring, and add tests.
* Improve CLI and messages (#26341)wxiaoguang2023-08-052-52/+17
| | | | | | | Follow the CLI refactoring 1. Remove the "checkCommandFlags" helper 2. Unify the web startup message, make them have consistent names as `./gitea help` 3. Fine tune some other messages (see the diff)