mirror of https://github.com/go-gitea/gitea.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
6bc3079c00
This PR follows #21535 (and replace #22592) ## Review without space diff https://github.com/go-gitea/gitea/pull/22678/files?diff=split&w=1 ## Purpose of this PR 1. Make git module command completely safe (risky user inputs won't be passed as argument option anymore) 2. Avoid low-level mistakes like https://github.com/go-gitea/gitea/pull/22098#discussion_r1045234918 3. Remove deprecated and dirty `CmdArgCheck` function, hide the `CmdArg` type 4. Simplify code when using git command ## The main idea of this PR * Move the `git.CmdArg` to the `internal` package, then no other package except `git` could use it. Then developers could never do `AddArguments(git.CmdArg(userInput))` any more. * Introduce `git.ToTrustedCmdArgs`, it's for user-provided and already trusted arguments. It's only used in a few cases, for example: use git arguments from config file, help unit test with some arguments. * Introduce `AddOptionValues` and `AddOptionFormat`, they make code more clear and simple: * Before: `AddArguments("-m").AddDynamicArguments(message)` * After: `AddOptionValues("-m", message)` * - * Before: `AddArguments(git.CmdArg(fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email)))` * After: `AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email)` ## FAQ ### Why these changes were not done in #21535 ? #21535 is mainly a search&replace, it did its best to not change too much logic. Making the framework better needs a lot of changes, so this separate PR is needed as the second step. ### The naming of `AddOptionXxx` According to git's manual, the `--xxx` part is called `option`. ### How can it guarantee that `internal.CmdArg` won't be not misused? Go's specification guarantees that. Trying to access other package's internal package causes compilation error. And, `golangci-lint` also denies the git/internal package. Only the `git/command.go` can use it carefully. ### There is still a `ToTrustedCmdArgs`, will it still allow developers to make mistakes and pass untrusted arguments? Generally speaking, no. Because when using `ToTrustedCmdArgs`, the code will be very complex (see the changes for examples). Then developers and reviewers can know that something might be unreasonable. ### Why there was a `CmdArgCheck` and why it's removed? At the moment of #21535, to reduce unnecessary changes, `CmdArgCheck` was introduced as a hacky patch. Now, almost all code could be written as `cmd := NewCommand(); cmd.AddXxx(...)`, then there is no need for `CmdArgCheck` anymore. ### Why many codes for `signArg == ""` is deleted? Because in the old code, `signArg` could never be empty string, it's either `-S[key-id]` or `--no-gpg-sign`. So the `signArg == ""` is just dead code. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> |
2 years ago | |
---|---|---|
.. | ||
foreachref | 2 years ago | |
internal | 2 years ago | |
pipeline | 2 years ago | |
tests/repos | 3 years ago | |
url | 2 years ago | |
README.md | 6 years ago | |
batch_reader.go | 2 years ago | |
blame.go | 2 years ago | |
blame_test.go | 2 years ago | |
blob.go | 2 years ago | |
blob_gogit.go | 2 years ago | |
blob_nogogit.go | 2 years ago | |
blob_test.go | 2 years ago | |
command.go | 2 years ago | |
command_race_test.go | 2 years ago | |
command_test.go | 2 years ago | |
commit.go | 2 years ago | |
commit_convert_gogit.go | 2 years ago | |
commit_info.go | 2 years ago | |
commit_info_gogit.go | 2 years ago | |
commit_info_nogogit.go | 2 years ago | |
commit_info_test.go | 2 years ago | |
commit_reader.go | 2 years ago | |
commit_test.go | 2 years ago | |
diff.go | 2 years ago | |
diff_test.go | 2 years ago | |
error.go | 2 years ago | |
git.go | 2 years ago | |
git_test.go | 2 years ago | |
hook.go | 2 years ago | |
last_commit_cache.go | 2 years ago | |
last_commit_cache_gogit.go | 2 years ago | |
last_commit_cache_nogogit.go | 2 years ago | |
log_name_status.go | 2 years ago | |
notes.go | 2 years ago | |
notes_gogit.go | 2 years ago | |
notes_nogogit.go | 2 years ago | |
notes_test.go | 2 years ago | |
parse_gogit.go | 2 years ago | |
parse_gogit_test.go | 2 years ago | |
parse_nogogit.go | 2 years ago | |
parse_nogogit_test.go | 2 years ago | |
ref.go | 2 years ago | |
remote.go | 2 years ago | |
repo.go | 2 years ago | |
repo_archive.go | 2 years ago | |
repo_attribute.go | 2 years ago | |
repo_attribute_test.go | 2 years ago | |
repo_base.go | 2 years ago | |
repo_base_gogit.go | 2 years ago | |
repo_base_nogogit.go | 2 years ago | |
repo_blame.go | 2 years ago | |
repo_blob.go | 2 years ago | |
repo_blob_gogit.go | 2 years ago | |
repo_blob_nogogit.go | 2 years ago | |
repo_blob_test.go | 2 years ago | |
repo_branch.go | 2 years ago | |
repo_branch_gogit.go | 2 years ago | |
repo_branch_nogogit.go | 2 years ago | |
repo_branch_test.go | 2 years ago | |
repo_commit.go | 2 years ago | |
repo_commit_gogit.go | 2 years ago | |
repo_commit_nogogit.go | 2 years ago | |
repo_commit_test.go | 2 years ago | |
repo_commitgraph.go | 2 years ago | |
repo_commitgraph_gogit.go | 2 years ago | |
repo_compare.go | 2 years ago | |
repo_compare_test.go | 2 years ago | |
repo_gpg.go | 2 years ago | |
repo_hook.go | 2 years ago | |
repo_index.go | 2 years ago | |
repo_language_stats.go | 2 years ago | |
repo_language_stats_gogit.go | 2 years ago | |
repo_language_stats_nogogit.go | 2 years ago | |
repo_language_stats_test.go | 2 years ago | |
repo_object.go | 2 years ago | |
repo_ref.go | 2 years ago | |
repo_ref_gogit.go | 2 years ago | |
repo_ref_nogogit.go | 2 years ago | |
repo_ref_test.go | 2 years ago | |
repo_stats.go | 2 years ago | |
repo_stats_test.go | 2 years ago | |
repo_tag.go | 2 years ago | |
repo_tag_gogit.go | 2 years ago | |
repo_tag_nogogit.go | 2 years ago | |
repo_tag_test.go | 2 years ago | |
repo_test.go | 2 years ago | |
repo_tree.go | 2 years ago | |
repo_tree_gogit.go | 2 years ago | |
repo_tree_nogogit.go | 2 years ago | |
sha1.go | 2 years ago | |
sha1_gogit.go | 2 years ago | |
sha1_nogogit.go | 2 years ago | |
sha1_test.go | 2 years ago | |
signature.go | 2 years ago | |
signature_gogit.go | 2 years ago | |
signature_nogogit.go | 2 years ago | |
submodule.go | 2 years ago | |
submodule_test.go | 2 years ago | |
tag.go | 2 years ago | |
tag_test.go | 2 years ago | |
tree.go | 2 years ago | |
tree_blob.go | 2 years ago | |
tree_blob_gogit.go | 2 years ago | |
tree_blob_nogogit.go | 2 years ago | |
tree_entry.go | 2 years ago | |
tree_entry_gogit.go | 2 years ago | |
tree_entry_mode.go | 2 years ago | |
tree_entry_nogogit.go | 2 years ago | |
tree_entry_test.go | 2 years ago | |
tree_gogit.go | 2 years ago | |
tree_nogogit.go | 2 years ago | |
utils.go | 2 years ago | |
utils_test.go | 2 years ago |
README.md
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.