Commit Graph
59 Commits
Author SHA1 Message Date
ChristopherHX 17623bba0d Remove Repository.getFilesChanged to fix Actions paths and paths-ignore filter (#23920)
Remove the misbehaving function and call
Repository.GetFilesChangedBetween instead.

Fixes #23919

---

~~_TODO_ test this~~ `Repository.getFilesChanged` seems to be only used
by Gitea Actions, but a similar function already exists

**Update** I tested this change and the issue is gone.
2023-04-07 14:42:43 +08:00
Brecht Van Lommel 8bdc0acf97 Fix pull request update showing too many commits with multiple branches (#22856)
When the base repository contains multiple branches with the same
commits as the base branch, pull requests can show a long list of
commits already in the base branch as having been added.

What this is supposed to do is exclude commits already in the base
branch. But the mechansim to do so assumed a commit only exists in a
single branch. Now use `git rev-list A B --not branchName` instead of
filtering commits afterwards.

The logic to detect if there was a force push also was wrong for
multiple branches. If the old commit existed in any branch in the base
repository it would assume there was no force push. Instead check if the
old commit is an ancestor of the new commit.
2023-03-09 12:14:22 -06:00
wxiaoguang dc9cebdf45 Use --message=%s for git commit message (#23028)
Close  #23027

`git commit` message option _only_ supports 4 formats (well, only ....):
* `"commit", "-m", msg`
* `"commit", "-m{msg}"`  (no space)
* `"commit", "--message", msg`
* `"commit", "--message={msg}"`

The long format with `=` is the best choice, and it's documented in `man
git-commit`:

`-m <msg>, --message=<msg> ...`

ps: I would suggest always use long format option for git command, as
much as possible.

Co-authored-by: Lunny Xiao <[email protected]>
2023-02-21 14:12:57 +08:00
wxiaoguang 6bc3079c00 Refactor git command package to improve security and maintainability (#22678)
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 <[email protected]>
2023-02-04 10:30:43 +08:00
flynnnnnnnnnn e81ccc406b Implement FSFE REUSE for golang files (#21840)
Change all license headers to comply with REUSE specification.

Fix #16132

Co-authored-by: flynnnnnnnnnn <flynnnnnnnnnn@github>
Co-authored-by: John Olheiser <[email protected]>
2022-11-27 18:20:29 +00:00
wxiaoguang dcd9fc7ee8 Refactor git command arguments and make all arguments to be safe to be used (#21535)
Follow #21464

Make all git command arguments strictly safe. Most changes are one-to-one replacing, keep all existing logic.
2022-10-23 22:44:45 +08:00
wxiaoguang d98c5db58f alternative to PR "improve code quality" (#21464)
This PR doesn't require new git version, and can be backported easily.

Co-authored-by: 6543 <[email protected]>
2022-10-15 12:49:26 +02:00
zeripath a2cfcdb91a Slightly simplify LastCommitCache (#20444)
The LastCommitCache code is a little complex and there is unnecessary
duplication between the gogit and nogogit variants.

This PR adds the LastCommitCache as a field to the git.Repository and
pre-creates it in the ReferencesGit helpers etc. There has been some
simplification and unification of the variant code.

Signed-off-by: Andrew Thornton <[email protected]>
2022-07-25 16:39:42 +01:00
Wim cb50375e2b Add more linters to improve code readability (#19989)
Add nakedret, unconvert, wastedassign, stylecheck and nolintlint linters to improve code readability

- nakedret - https://github.com/alexkohler/nakedret - nakedret is a Go static analysis tool to find naked returns in functions greater than a specified function length.
- unconvert - https://github.com/mdempsky/unconvert - Remove unnecessary type conversions
- wastedassign - https://github.com/sanposhiho/wastedassign -  wastedassign finds wasted assignment statements.
- notlintlint -  Reports ill-formed or insufficient nolint directives
- stylecheck - https://staticcheck.io/docs/checks/#ST - keep style consistent
  - excluded: [ST1003 - Poorly chosen identifier](https://staticcheck.io/docs/checks/#ST1003) and [ST1005 - Incorrectly formatted error string](https://staticcheck.io/docs/checks/#ST1005)
2022-06-20 12:02:49 +02:00
wxiaoguang 157b405753 Remove legacy git code (ver < 2.0), fine tune markup tests (#19930)
* clean git support for ver < 2.0

* fine tune tests for markup (which requires git module)

* remove unnecessary comments

* try to fix tests

* try test again

* use const for GitVersionRequired instead of var

* try to fix integration test

* Refactor CheckAttributeReader to make a *git.Repository version

* update document for commit signing with Gitea's internal gitconfig

* update document for commit signing with Gitea's internal gitconfig

Co-authored-by: Andrew Thornton <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
2022-06-16 23:47:44 +08:00
wxiaoguang a0051634b9 Refactor git module, make Gitea use internal git config (#19732)
* Refactor git module, make Gitea use internal git config, add safe.directory config

* introduce git.InitSimple and git.InitWithConfigSync, make serv cmd use gitconfig

* use HOME instead of GIT_CONFIG_GLOBAL, because git always needs a correct HOME

* fix cmd env in cmd/serv.go

* fine tune error message

* Fix a incorrect test case

* fix configAddNonExist

* fix configAddNonExist logic, add `--fixed-value` flag, add tests

* add configSetNonExist function in case it's needed.

* use configSetNonExist for `user.name` and `user.email`

* add some comments

* Update cmd/serv.go

Co-authored-by: zeripath <[email protected]>

* Update cmd/serv.go

Co-authored-by: zeripath <[email protected]>

* Update modules/git/git.go

Co-authored-by: zeripath <[email protected]>

* Update modules/setting/setting.go

Co-authored-by: zeripath <[email protected]>

* Update modules/git/repo_attribute.go

Co-authored-by: zeripath <[email protected]>

* fix spaces in messages

* use `configSet("core.protectNTFS", ...)` instead of `globalCommandArgs`

* remove GIT_CONFIG_NOSYSTEM, continue to use system's git config

* Update cmd/serv.go

Co-authored-by: zeripath <[email protected]>

* fix merge

* remove code for safe.directory

* separate git.CommonEnvs to CommonGitCmdEnvs and CommonCmdServEnvs

* avoid Golang's data race error

Co-authored-by: zeripath <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
2022-06-10 09:57:49 +08:00
Lunny Xiao 4344a64107 Allow custom default merge message with .gitea/default_merge_message/<merge_style>_TEMPLATE.md (#18177)
* Allow custom default merge message with .gitea/MERGE_MESSAGE_<merge_style>_TEMPLATE.md

* Some improvements

* Follow some advices

* Fix bug

* Fix bug

* Fix lint

* Fix close comment

* Fix test

* Fix and docs

* Improve codes

* Update docs and remove unnecessary variables

* return error for GetDefaultMergeMessage

* Fix test

* improve code

* ignore unknow unit type

* return error for GetDefaultMergeMessage

* Update services/pull/merge.go

* Some improvements

* Follow some advices

* Fix bug

* Fix lint

* Improve codes

* Update docs and remove unnecessary variables

* return error for GetDefaultMergeMessage

* improve code

* Handle deleted HeadRepo in GetDefaultMergeMessage

Signed-off-by: Andrew Thornton <[email protected]>

* Fix test

* Fix test

Co-authored-by: zeripath <[email protected]>
2022-05-08 20:32:45 +08:00
wxiaoguang 124b072f0b Remove git.Command.Run and git.Command.RunInDir* (#19280)
Follows #19266, #8553, Close #18553, now there are only three `Run..(&RunOpts{})` functions.
 * before: `stdout, err := RunInDir(path)`
 * now: `stdout, _, err := RunStdString(&git.RunOpts{Dir:path})`
2022-04-01 10:55:30 +08:00
Martin Scholz 26718a785a Change git.cmd to RunWithContext (#18693)
Change all `cmd...Pipeline` commands to `cmd.RunWithContext`.

#18553

Co-authored-by: Martin Scholz <[email protected]>
2022-02-11 13:47:22 +01:00
6543 3043eb36bf Delete old git.NewCommand() and use it as git.NewCommandContext() (#18552) 2022-02-06 20:01:47 +01:00
6543 80adbebbc8 Unexport git.GlobalCommandArgs (#18376)
Unexport the git.GlobalCommandArgs variable.
2022-01-25 18:15:58 +00:00
6543 54e9ee37a7 format with gofumpt (#18184)
* gofumpt -w -l .

* gofumpt -w -l -extra .

* Add linter

* manual fix

* change make fmt
2022-01-20 18:46:10 +01:00
zeripath 5cb0c9aa0d Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git
commands run within the request context.

This now means that the if there is a git repo already open in the context it will be used instead of reopening it.

Signed-off-by: Andrew Thornton <[email protected]>
2022-01-19 23:26:57 +00:00
luzpaz af92473920 Fix source typos (#18227)
Follow-up to #18219
2022-01-10 23:46:26 +08:00
mscherer 34b5436ae1 Refactor various strings (#17784)
Fixes #16478

Co-authored-by: Gusted <[email protected]>

Co-authored-by: Gusted <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
2021-12-02 15:28:08 +08:00
KN4CK3R d9ef43a712 Replace list.List with slices (#16311)
* Replaced list with slice.

* Fixed usage of pointer to temporary variable.

* Replaced LIFO list with slice.

* Lint

* Removed type check.

* Removed duplicated code.

* Lint

* Fixed merge.

Co-authored-by: 6543 <[email protected]>
2021-08-09 14:08:51 -04:00
zeripath 62c278e4ab Fix modified files list in webhooks when there is a space (#16288)
* Fix modified files list in webhooks when there is a space

There is an unfortunate bug with GetCommitFileStatus where files with
spaces are misparsed and split at the space.

There is a second bug because modern gits detect renames meaning that
this function no longer works correctly.

There is a third bug in that merge commits don't have their modified
files detected correctly.

Fix #15865


Signed-off-by: Andrew Thornton <[email protected]>
2021-07-02 21:23:37 +02:00
KN4CK3R 8e262104c2 Add Image Diff for SVG files (#14867)
* Added type sniffer.

* Switched content detection from base to typesniffer.

* Added GuessContentType to Blob.

* Moved image info logic to client.
Added support for SVG images in diff.

* Restore old blocked svg behaviour.

* Added missing image formats.

* Execute image diff only when container is visible.

* add margin to spinner

* improve BIN tag on image diffs

* Default to render view.

* Show image diff on incomplete diff.

Co-authored-by: silverwind <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: Lauris BH <[email protected]>
2021-06-05 15:32:19 +03:00
zeripath f9abf94bd9 HasPreviousCommit causes recursive load of commits unnecessarily (#14598)
This PR improves HasPreviousCommit to prevent the automatic and recursive loading
of previous commits using git merge-base --is-ancestor and git rev-list

Fix #13684

Signed-off-by: Andrew Thornton <[email protected]>
2021-02-10 07:00:57 +00:00
zeripath 511f6138d4 Use native git variants by default with go-git variants as build tag (#13673)
* Move last commit cache back into modules/git

Signed-off-by: Andrew Thornton <[email protected]>

* Remove go-git from the interface for last commit cache

Signed-off-by: Andrew Thornton <[email protected]>

* move cacheref to last_commit_cache

Signed-off-by: Andrew Thornton <[email protected]>

* Remove go-git from routers/private/hook

Signed-off-by: Andrew Thornton <[email protected]>

* Move FindLFSFiles to pipeline

Signed-off-by: Andrew Thornton <[email protected]>

* Make no-go-git variants

Signed-off-by: Andrew Thornton <[email protected]>

* Submodule RefID

Signed-off-by: Andrew Thornton <[email protected]>

* fix issue with GetCommitsInfo

Signed-off-by: Andrew Thornton <[email protected]>

* fix GetLastCommitForPaths

Signed-off-by: Andrew Thornton <[email protected]>

* Improve efficiency

Signed-off-by: Andrew Thornton <[email protected]>

* More efficiency

Signed-off-by: Andrew Thornton <[email protected]>

* even faster

Signed-off-by: Andrew Thornton <[email protected]>

* Reduce duplication

* As per @lunny

Signed-off-by: Andrew Thornton <[email protected]>

* attempt to fix drone

Signed-off-by: Andrew Thornton <[email protected]>

* fix test-tags

Signed-off-by: Andrew Thornton <[email protected]>

* default to use no-go-git variants and add gogit build tag

Signed-off-by: Andrew Thornton <[email protected]>

* placate lint

Signed-off-by: Andrew Thornton <[email protected]>

* as per @6543

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: 6543 <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
2020-12-17 22:00:47 +08:00
zeripath c05a8abc76 Multiple GitGraph improvements: Exclude PR heads, Add branch/PR links, Show only certain branches, (#12766)
* Multiple GitGraph improvements.

Add backend support for excluding PRs, selecting branches and files.

Fix #10327

Signed-off-by: Andrew Thornton <[email protected]>

* as per @silverwind

Signed-off-by: Andrew Thornton <[email protected]>

* as per @silverwind

Signed-off-by: Andrew Thornton <[email protected]>

* Only show refs in dropdown we display on the graph

Signed-off-by: Andrew Thornton <[email protected]>

* as per @silverwind

Signed-off-by: Andrew Thornton <[email protected]>

* use flexbox for ui header

Signed-off-by: Andrew Thornton <[email protected]>

* Move Hide Pull Request button to the dropdown

Signed-off-by: Andrew Thornton <[email protected]>

* Add SHA and user pictures

Signed-off-by: Andrew Thornton <[email protected]>

* fix test

Signed-off-by: Andrew Thornton <[email protected]>

* fix test 2

Signed-off-by: Andrew Thornton <[email protected]>

* fixes

* async

* more tweaks

* use tabs in tmpl

Signed-off-by: Andrew Thornton <[email protected]>

* remove commented thing

Signed-off-by: Andrew Thornton <[email protected]>

* fix linting

Signed-off-by: Andrew Thornton <[email protected]>

* Update web_src/js/features/gitgraph.js

Co-authored-by: silverwind <[email protected]>

* graph tweaks

* more tweaks

* add title

Signed-off-by: Andrew Thornton <[email protected]>

* fix loading indicator z-index and position

Co-authored-by: silverwind <[email protected]>
Co-authored-by: techknowlogick <[email protected]>
Co-authored-by: Lauris BH <[email protected]>
2020-11-08 12:21:54 -05:00
zeripath de6e427a01 go-version constraints ignore pre-releases (#13234)
Go-version constraints ignore pre-releases.

Rather than change the library further this PR simply changes
the git version comparison to use simple version compare ignoring the
issue of pre-releases.

Signed-off-by: Andrew Thornton <[email protected]>
2020-10-21 11:42:08 -04:00
6543 bc11caff94 [Vendor] Switch go-version lib (#12719)
* vendor: switch from "mcuadros/go-version" to "hashicorp/go-version"

* Adapt P1

* simplify

* fix lint

* adapt

* fix lint & rm old code

* no deadlock

* rm RWMutex and check GoVersion only 1-time

* Copyright header

Co-authored-by: techknowlogick <[email protected]>
2020-09-05 12:42:58 -04:00
zeripath 2f6aadffa8 Git 2.28 no longer permits diff with ... on unrelated branches (#12364)
* Git 2.28 no longer permits diff with ... on unrelated branches

Signed-off-by: Andrew Thornton <[email protected]>

* need to check stderr
2020-07-29 13:53:04 -04:00
zeripath 63e5bf6ef7 Only use --exclude on name-rev with git >= 2.13 (#12347)
Fix #11917

Signed-off-by: Andrew Thornton <[email protected]>
2020-07-28 15:11:05 +01:00
赵智超 ae20de7771 fix bug about can't skip commits base on base branch (#11555)
* fix bug about can't skip commits base on base branch

Signed-off-by: a1012112796 <[email protected]>

* Update modules/git/commit.go

Co-authored-by: Lauris BH <[email protected]>

* Update models/issue_comment.go

Co-authored-by: Lauris BH <[email protected]>

* fix lint

Co-authored-by: Lauris BH <[email protected]>
2020-06-24 20:40:52 +01:00
mrsdizzie d729d685d0 Fix 500 error on repos with no tags (#11870)
#11846 Introduced feature to show exact tag on commit view. However if a repo has no tags at all git prints out a separate and unhandled error " No names found, cannot describe anything."

 Adding --always to the command makes it always use the error in the style of "fatal: no tag exactly matches" even if there are no tags at all.

 Fixes #11869
 Fixes #11868
2020-06-12 14:02:14 -04:00
Cirno the Strongest b682a2c1b2 Show exact tag for commit on diff view (#11846)
* Show exact tag for commit on diff view

* Fix comment

Co-authored-by: techknowlogick <[email protected]>
2020-06-11 15:42:55 -04:00
Cirno the Strongest 4a4977a1f0 Don't consider tag refs as valid for branch name (#11847)
Co-authored-by: techknowlogick <[email protected]>
2020-06-10 19:00:39 -04:00
Cirno the Strongest 31df012968 Properly handle and return empty string for dangling commits in GetBranchName (#11587) 2020-05-23 20:49:48 +01:00
赵智超 0903b1ac8c Add push commits history comment on PR time-line (#11167)
* Add push commits history comment on PR time-line
* Add notify by email and ui of this comment type also

Signed-off-by: a1012112796 <[email protected]>

* Add migrations for IsForcePush
* fix wrong force-push judgement
* Apply suggestions from code review
* Remove commit number check
* add own notify fun
* fix some typo

Co-authored-by: guillep2k <[email protected]>

* fix lint

* fix style again, I forgot something before

* Change email notify way

* fix api

* add number check if It's force-push

* Add repo commit link fuction
remove unnecessary check
skip show push commits comment which not have commits alive

* Update issue_comment.go

* Apply suggestions from code review

Co-authored-by: mrsdizzie <[email protected]>

* Apply suggestions from code review

* fix ui view

Co-authored-by: silverwind <[email protected]>

* fix height

* remove unnecessary style define

* simplify GetBranchName

* Apply suggestions from code review

* save commit ids and isForce push by json
* simplify GetBranchName

* fix bug

Co-authored-by: guillep2k <[email protected]>
Co-authored-by: mrsdizzie <[email protected]>
Co-authored-by: Lauris BH <[email protected]>
Co-authored-by: silverwind <[email protected]>
2020-05-20 09:47:24 -03:00
zeripath 0198bbedc1 Allow compare page to look up base, head, own-fork, forkbase-of-head (#11327)
* Allow compare page to look up base, head, own-fork, forkbase-of-head

Signed-off-by: Andrew Thornton <[email protected]>

* as per @guillep2k

Signed-off-by: Andrew Thornton <[email protected]>

* Update routers/repo/compare.go

* as per @guillep2k

Signed-off-by: Andrew Thornton <[email protected]>

* Rationalise the names a little

Signed-off-by: Andrew Thornton <[email protected]>

* Rationalise the names a little (2)

Signed-off-by: Andrew Thornton <[email protected]>

* Fix 500 with fork of fork

Signed-off-by: Andrew Thornton <[email protected]>

* Prevent 500 on compare different trees

Signed-off-by: Andrew Thornton <[email protected]>

* dotdotdot is perfectly valid in both usernames and repo names

Signed-off-by: Andrew Thornton <[email protected]>

* ensure we can set the head and base repos too

Signed-off-by: Andrew Thornton <[email protected]>

* ensure we can set the head and base repos too (2)

Signed-off-by: Andrew Thornton <[email protected]>

* fix lint

Signed-off-by: Andrew Thornton <[email protected]>

* only set headRepo == baseRepo if isSameRepo

Signed-off-by: Andrew Thornton <[email protected]>
2020-05-12 08:52:46 +03:00
Lauris BH 43c09134a9 Migrate to go-git/go-git v5.0.0 (#10735) 2020-03-17 12:19:58 -04:00
SpaWn2KiLl 1f01f53c53 API add/generalize pagination (#9452)
* paginate results

* fixed deadlock

* prevented breaking change

* updated swagger

* go fmt

* fixed find topic

* go mod tidy

* go mod vendor with go1.13.5

* fixed repo find topics

* fixed unit test

* added Limit method to Engine struct; use engine variable when provided; fixed gitignore

* use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors

* set Page value on Home route

* improved memory allocations

* fixed response headers

* removed logfiles

* fixed import order

* import order

* improved swagger

* added function to get models.ListOptions from context

* removed pagesize diff on unit test

* fixed imports

* removed unnecessary struct field

* fixed go fmt

* scoped PR

* code improvements

* code improvements

* go mod tidy

* fixed import order

* fixed commit statuses session

* fixed files headers

* fixed headers; added pagination for notifications

* go mod tidy

* go fmt

* removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list

* Apply suggestions from code review

Co-Authored-By: 6543 <[email protected]>
Co-Authored-By: zeripath <[email protected]>

* fixed build error

* CI.restart()

* fixed merge conflicts resolve

* fixed conflicts resolve

* improved FindTrackedTimesOptions.ToOptions() method

* added backwards compatibility on ListReleases request; fixed issue tracked time ToSession

* fixed build error; fixed swagger template

* fixed swagger template

* fixed ListReleases backwards compatibility

* added page to user search route

Co-authored-by: techknowlogick <[email protected]>
Co-authored-by: 6543 <[email protected]>
Co-authored-by: zeripath <[email protected]>
2020-01-24 14:00:29 -05:00
zeripath 66ee9b87f9 Add require signed commit for protected branch (#9708)
* Add require signed commit for protected branch

* Fix fmt

* Make editor show if they will be signed

* bugfix

* Add basic merge check and better information for CRUD

* linting comment

* Add descriptors to merge signing

* Slight refactor

* Slight improvement to appearances

* Handle Merge API

* manage CRUD API

* Move error to error.go

* Remove fix to delete.go

* prep for merge

* need to tolerate \r\n in message

* check protected branch before trying to load it

* Apply suggestions from code review

Co-Authored-By: guillep2k <[email protected]>

* fix commit-reader

Co-authored-by: guillep2k <[email protected]>
2020-01-15 09:32:57 +01:00
Mario Lubenka 61db834904 Change target branch for pull request (#6488)
* Adds functionality to change target branch of created pull requests

Signed-off-by: Mario Lubenka <[email protected]>

* Use const instead of var in JavaScript additions

Signed-off-by: Mario Lubenka <[email protected]>

* Check if branches are equal and if PR already exists before changing target branch

Signed-off-by: Mario Lubenka <[email protected]>

* Make sure to check all commits

Signed-off-by: Mario Lubenka <[email protected]>

* Print error messages for user as error flash message

Signed-off-by: Mario Lubenka <[email protected]>

* Disallow changing target branch of closed or merged pull requests

Signed-off-by: Mario Lubenka <[email protected]>

* Resolve conflicts after merge of upstream/master

Signed-off-by: Mario Lubenka <[email protected]>

* Change order of branch select fields

Signed-off-by: Mario Lubenka <[email protected]>

* Removes duplicate check

Signed-off-by: Mario Lubenka <[email protected]>

* Use ctx.Tr for translations

Signed-off-by: Mario Lubenka <[email protected]>

* Recompile JS

Signed-off-by: Mario Lubenka <[email protected]>

* Use correct translation namespace

Signed-off-by: Mario Lubenka <[email protected]>

* Remove redundant if condition

Signed-off-by: Mario Lubenka <[email protected]>

* Moves most change branch logic into pull service

Signed-off-by: Mario Lubenka <[email protected]>

* Completes comment

Signed-off-by: Mario Lubenka <[email protected]>

* Add Ref to ChangesPayload for logging changed target branches
instead of creating a new struct

Signed-off-by: Mario Lubenka <[email protected]>

* Revert changes to go.mod

Signed-off-by: Mario Lubenka <[email protected]>

* Directly use createComment method

Signed-off-by: Mario Lubenka <[email protected]>

* Return 404 if pull request is not found. Move written check up

Signed-off-by: Mario Lubenka <[email protected]>

* Remove variable declaration

Signed-off-by: Mario Lubenka <[email protected]>

* Return client errors on change pull request target errors

Signed-off-by: Mario Lubenka <[email protected]>

* Return error in commit.HasPreviousCommit

Signed-off-by: Mario Lubenka <[email protected]>

* Adds blank line

Signed-off-by: Mario Lubenka <[email protected]>

* Test patch before persisting new target branch

Signed-off-by: Mario Lubenka <[email protected]>

* Update patch before testing (not working)

Signed-off-by: Mario Lubenka <[email protected]>

* Removes patch calls when changeing pull request target

Signed-off-by: Mario Lubenka <[email protected]>

* Removes unneeded check for base name

Signed-off-by: Mario Lubenka <[email protected]>

* Moves ChangeTargetBranch completely to pull service. Update patch status.

Signed-off-by: Mario Lubenka <[email protected]>

* Set webhook mode after errors were validated

Signed-off-by: Mario Lubenka <[email protected]>

* Update PR in one transaction

Signed-off-by: Mario Lubenka <[email protected]>

* Move logic for check if head is equal with branch to pull model

Signed-off-by: Mario Lubenka <[email protected]>

* Adds missing comment and simplify return

Signed-off-by: Mario Lubenka <[email protected]>

* Adjust CreateComment method call

Signed-off-by: Mario Lubenka <[email protected]>
2019-12-16 14:20:25 +08:00
Lunny Xiao 7b7d382b8b Fix datarace on git.GlobalCommandArgs on tests (#9162)
* fix datarace on git.GlobalCommandArgs on tests

* fix tests

* fix tests

* fix tests
2019-11-27 01:35:52 +01:00
jaqra 065bbddab9 Fix count for commit graph last page (#8843)
* Fix count for commit graph last page

* Remove used once variable

* Move func to model

* capitalize method name

* fix error message
2019-11-07 20:09:51 +02:00
zeripath fcb535c5c3 Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631)
This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however.

## Features
- [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.)
- [x] Verify commits signed with the default gpg as valid
- [x] Signer, Committer and Author can all be different
    - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon.
- [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available
    - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg
    - [x] Try to match the default key with a user on gitea - this is done at verification time
- [x] Make things configurable?
    - app.ini configuration done
    - [x] when checking commits are signed need to check if they're actually verifiable too
- [x] Add documentation

I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
2019-10-16 14:42:42 +01:00
Mario Lubenka f92a0b68fe Bugfix for image compare and minor improvements to image compare (#8289)
* Resolve error when comparing images

Signed-off-by: Mario Lubenka <[email protected]>

* Check blob existence instead of git-ls when checking if file exists

Signed-off-by: Mario Lubenka <[email protected]>

* Show file metadata also when a file was newly added

Signed-off-by: Mario Lubenka <[email protected]>

* Fixes error in commit view

Signed-off-by: Mario Lubenka <[email protected]>

* Excludes assigning path and image infos for compare routers to service package

Signed-off-by: Mario Lubenka <[email protected]>

* Removes nil default and fixes import order

Signed-off-by: Mario Lubenka <[email protected]>

* Adds missing comments

Signed-off-by: Mario Lubenka <[email protected]>

* Moves methods for assigning compare data to context into repo router package

Signed-off-by: Mario Lubenka <[email protected]>

* Show image compare for deleted images as well. Simplify check if image should be displayed

Signed-off-by: Mario Lubenka <[email protected]>
2019-10-04 15:58:54 -04:00
Mario Lubenka a37236314c Adds side-by-side diff for images (#6784)
* Adds side-by-side diff for images

Signed-off-by: Mario Lubenka <[email protected]>

* Explain blank imports

Signed-off-by: Mario Lubenka <[email protected]>

* Use complete word for width and height labels on image compare

Signed-off-by: Mario Lubenka <[email protected]>

* Update index.css from master

Signed-off-by: Mario Lubenka <[email protected]>

* Moves ImageInfo to git commit file

Signed-off-by: Mario Lubenka <[email protected]>

* Assign ImageInfo function for template and sets correct target for BeforeSourcePath

Signed-off-by: Mario Lubenka <[email protected]>

* Adds missing comment

Signed-off-by: Mario Lubenka <[email protected]>

* Return error if ImageInfo failed

Signed-off-by: Mario Lubenka <[email protected]>

* Avoid template panic when ImageInfo failed for some reason

Signed-off-by: Mario Lubenka <[email protected]>

* Show file size on image diff

Signed-off-by: Mario Lubenka <[email protected]>

* Removes unused helper function

Signed-off-by: Mario Lubenka <[email protected]>

* Reverts copyright year change

Signed-off-by: Mario Lubenka <[email protected]>

* Close file reader

Signed-off-by: Mario Lubenka <[email protected]>

* Update commit.go

Sets correct data key

* Moves reader.Close() up a few lines

* Updates index.css

* Updates CSS file

Signed-off-by: Mario Lubenka <[email protected]>

* Transfers adjustments for image compare to compare.go file

Signed-off-by: Mario Lubenka <[email protected]>

* Adjusts variable name

Signed-off-by: Mario Lubenka <[email protected]>

* Apply lesshint recommendations

Signed-off-by: Mario Lubenka <[email protected]>

* Do not show old image on image compare if it is not in index of base commit

Signed-off-by: Mario Lubenka <[email protected]>

* Change file size text

Signed-off-by: Mario Lubenka <[email protected]>
2019-09-16 17:03:22 +08:00
zeripath 7ad67109d7 Be more strict with git arguments (#7715)
* Be more strict with git arguments
* fix-up commit test
* use bindings for branch name
2019-08-05 21:39:39 +01:00
kolaente f9ec2f89f2 Add golangci (#6418) 2019-06-12 15:41:28 -04:00
Filip Navara 2af67f6044 Improve listing performance by using go-git (#6478)
* Use go-git for tree reading and commit info lookup.

Signed-off-by: Filip Navara <[email protected]>

* Use TreeEntry.IsRegular() instead of ObjectType that was removed.

Signed-off-by: Filip Navara <[email protected]>

* Use the treePath to optimize commit info search.

Signed-off-by: Filip Navara <[email protected]>

* Extract the latest commit at treePath along with the other commits.

Signed-off-by: Filip Navara <[email protected]>

* Fix listing commit info for a directory that was created in one commit and never modified after.

Signed-off-by: Filip Navara <[email protected]>

* Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit).

Signed-off-by: Filip Navara <[email protected]>

* Use go-git for reading blobs.

Signed-off-by: Filip Navara <[email protected]>

* Make SHA1 type alias for plumbing.Hash in go-git.

Signed-off-by: Filip Navara <[email protected]>

* Make Signature type alias for object.Signature in go-git.

Signed-off-by: Filip Navara <[email protected]>

* Fix GetCommitsInfo for repository with only one commit.

Signed-off-by: Filip Navara <[email protected]>

* Fix PGP signature verification.

Signed-off-by: Filip Navara <[email protected]>

* Fix issues with walking commit graph across merges.

Signed-off-by: Filip Navara <[email protected]>

* Fix typo in condition.

Signed-off-by: Filip Navara <[email protected]>

* Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes).

Signed-off-by: Filip Navara <[email protected]>

* Fix lising submodules.

Signed-off-by: Filip Navara <[email protected]>

* Fix build

Signed-off-by: Filip Navara <[email protected]>

* Add back commit cache because of name-rev

Signed-off-by: Filip Navara <[email protected]>

* Fix tests

Signed-off-by: Filip Navara <[email protected]>

* Fix code style

* Fix spelling

* Address PR feedback

Signed-off-by: Filip Navara <[email protected]>

* Update vendor module list

Signed-off-by: Filip Navara <[email protected]>

* Fix getting trees by commit id

Signed-off-by: Filip Navara <[email protected]>

* Fix remaining unit test failures

* Fix GetTreeBySHA

* Avoid running `git name-rev` if not necessary

Signed-off-by: Filip Navara <[email protected]>

* Move Branch code to git module

* Clean up GPG signature verification and fix it for tagged commits

* Address PR feedback (import formatting, copyright headers)

* Make blob lookup by SHA working

* Update tests to use public API

* Allow getting content from any type of object through the blob interface

* Change test to actually expect the object content that is in the GIT repository

* Change one more test to actually expect the object content that is in the GIT repository

* Add comments
2019-04-19 20:17:27 +08:00
Richard Mahn 2262811e40 Fixes 4762 - Content API for Creating, Updating, Deleting Files (#6314) 2019-04-17 12:06:35 -04:00