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.
gitea/models
Mihir Joshi 62f2d717b7
Fix reverting a merge commit failing (#28794) (#28825)
Backport https://github.com/go-gitea/gitea/pull/28794

Fixes #22236

---
Error occurring currently while trying to revert commit using read-tree
-m approach:
> 2022/12/26 16:04:43 ...rvices/pull/patch.go:240:AttemptThreeWayMerge()
[E] [63a9c61a] Unable to run read-tree -m! Error: exit status 128 -
fatal: this operation must be run in a work tree
> 	 - fatal: this operation must be run in a work tree

We need to clone a non-bare repository for `git read-tree -m` to work.


bb371aee6e
adds support to create a non-bare cloned temporary upload repository.

After cloning a non-bare temporary upload repository, we [set default
index](https://github.com/go-gitea/gitea/blob/main/services/repository/files/cherry_pick.go#L37)
(`git read-tree HEAD`).
This operation ends up resetting the git index file (see investigation
details below), due to which, we need to call `git update-index
--refresh` afterward.

Here's the diff of the index file before and after we execute
SetDefaultIndex: https://www.diffchecker.com/hyOP3eJy/

Notice the **ctime**, **mtime** are set to 0 after SetDefaultIndex.

You can reproduce the same behavior using these steps:
```bash
$ git clone https://try.gitea.io/me-heer/test.git -s -b main
$ cd test
$ git read-tree HEAD
$ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00
error: Entry '1' not uptodate. Cannot merge.
```

After which, we can fix like this:
```bash
$ git update-index --refresh
$ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00
```
1 year ago
..
actions Fix schedule tasks bugs (#28691) (#28780) 1 year ago
activities Speed up loading the dashboard on mysql/mariadb (#28546) (#28784) 1 year ago
admin Next round of `db.DefaultContext` refactor (#27089) 1 year ago
asymkey Retry SSH key verification with additional CRLF if it failed (#28392) (#28464) 1 year ago
auth Avoid cycle-redirecting user/login page (#28636) (#28658) 1 year ago
avatars Refactor system setting (#27000) (#27452) 1 year ago
db Avoid cycle-redirecting user/login page (#28636) (#28658) 1 year ago
dbfs Fix content holes in Actions task logs file (#25560) 2 years ago
fixtures Fix reverting a merge commit failing (#28794) (#28825) 1 year ago
git Fix `GetCommitStatuses` (#28787) (#28804) 1 year ago
issues Rework markup link rendering (#26745) (#28803) 1 year ago
migrations handle repository.size column being NULL in migration v263 (#28336) (#28363) 1 year ago
organization Another round of `db.DefaultContext` refactor (#27103) (#27262) 1 year ago
packages move repository deletion to service layer (#26948) 1 year ago
perm move repository deletion to service layer (#26948) 1 year ago
project Fix comment permissions (#28213) (#28216) 1 year ago
pull refactor some functions to support ctx as first parameter (#21878) 2 years ago
repo Rework markup link rendering (#26745) (#28803) 1 year ago
secret Refactor secrets modification logic (#26873) 1 year ago
shared/types Display owner of a runner as a tooltip instead of static text (#24377) 2 years ago
system Increase "version" when update the setting value to a same value as before (#28243) (#28244) 1 year ago
unit Use `Set[Type]` instead of `map[Type]bool/struct{}`. (#26804) 2 years ago
unittest Upgrade xorm (#27673) (#27691) 1 year ago
user Forbid removing the last admin user (#28337) (#28793) 1 year ago
webhook Fix comment permissions (#28213) (#28216) 1 year ago
error.go Forbid removing the last admin user (#28337) (#28793) 1 year ago
fixture_generation.go Fix yaml test (#27297) (#27303) 1 year ago
fixture_test.go Fix yaml test (#27297) (#27303) 1 year ago
main_test.go move repository deletion to service layer (#26948) 1 year ago
org.go refactor some functions to support ctx as first parameter (#21878) 2 years ago
org_team.go Use db.WithTx for AddTeamMember to avoid ctx abuse (#27095) 1 year ago
org_team_test.go Reduce usage of `db.DefaultContext` (#27073) 1 year ago
org_test.go Implement FSFE REUSE for golang files (#21840) 2 years ago
repo.go Refactor system setting (#27000) (#27452) 1 year ago
repo_test.go Implement FSFE REUSE for golang files (#21840) 2 years ago
repo_transfer.go Next round of `db.DefaultContext` refactor (#27089) 1 year ago
repo_transfer_test.go Next round of `db.DefaultContext` refactor (#27089) 1 year ago