Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reverting a merge commit failing #28794

Merged
merged 7 commits into from
Jan 16, 2024
Merged

Fix reverting a merge commit failing #28794

merged 7 commits into from
Jan 16, 2024

Conversation

me-heer
Copy link
Contributor

@me-heer me-heer commented Jan 15, 2024

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.
bb371ae adds support to create a non-bare cloned temporary upload repository.

After cloning a non-bare temporary upload repository, we set default index (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:

$ 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:

$ git update-index --refresh
$ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 15, 2024
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 15, 2024
@lunny lunny added type/bug backport/v1.21 This PR should be backported to Gitea 1.21 labels Jan 15, 2024
@lunny lunny added this to the 1.22.0 milestone Jan 15, 2024
Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be some tests to cover the behavior? (Haven't read the details carefully yet)

@me-heer
Copy link
Contributor Author

me-heer commented Jan 15, 2024

Could there be some tests to cover the behavior? (Haven't read the details carefully yet)

Yes, I was going to work on them after this is merged/I'm sure the approach is right.

Do tests covering this new behavior go in the same PR or another PR usually?

@wxiaoguang
Copy link
Contributor

Could there be some tests to cover the behavior? (Haven't read the details carefully yet)

Yes, I was going to work on them after this is merged/I'm sure the approach is right.

Do tests covering this new behavior go in the same PR or another PR usually?

Usually (and preferred) to make the tests go in the same PR.

@lunny
Copy link
Member

lunny commented Jan 16, 2024

It seems it works in my manually local tests.

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 16, 2024
Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't thought deeply about this (eg: potential other approaches? no idea yet ....). Since it has been covered by tests and is better than before, I would vote my approval.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 16, 2024
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 16, 2024
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jan 16, 2024
@lunny lunny enabled auto-merge (squash) January 16, 2024 14:42
@lunny lunny merged commit b827024 into go-gitea:main Jan 16, 2024
25 checks passed
@GiteaBot
Copy link
Contributor

I was unable to create a backport for 1.21. @me-heer, please send one manually. 🍵

go run ./contrib/backport 28794
...  // fix git conflicts if any
go run ./contrib/backport --continue

@GiteaBot GiteaBot added backport/manual No power to the bots! Create your backport yourself! and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Jan 16, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jan 17, 2024
* giteaofficial/main:
  Retarget depending pulls when the parent branch is deleted (go-gitea#28686)
  Bump `@github/relative-time-element` to 4.3.1 (go-gitea#28819)
  Fix reverting a merge commit failing (go-gitea#28794)
  Render code block in activity tab (go-gitea#28816)
  Remove trust model selection from repository creation on web page because it can be changed in settings later (go-gitea#28814)
me-heer added a commit to me-heer/gitea that referenced this pull request Jan 17, 2024
Fixes go-gitea#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.

go-gitea@bb371ae
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:
```
$ git update-index --refresh
$ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00
```
me-heer added a commit to me-heer/gitea that referenced this pull request Jan 17, 2024
Fixes go-gitea#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.

go-gitea@bb371ae
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:
```
$ git update-index --refresh
$ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00
```
@lunny lunny added the backport/done All backports for this PR have been created label Jan 17, 2024
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this pull request Jan 17, 2024
Fixes go-gitea#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.

go-gitea@bb371ae
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:
```
$ git update-index --refresh
$ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00
```
lunny pushed a commit that referenced this pull request Jan 21, 2024
Backport #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.


bb371ae
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
```
henrygoodman pushed a commit to henrygoodman/gitea that referenced this pull request Jan 31, 2024
Fixes go-gitea#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.

go-gitea@bb371ae
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:
```
$ git update-index --refresh
$ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00
```
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this pull request Jan 31, 2024
Backport go-gitea/gitea#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.

go-gitea/gitea@bb371ae
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
```

(cherry picked from commit 62f2d71)
nrdufour added a commit to nrdufour/home-ops that referenced this pull request Feb 4, 2024
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker.io/gitea/gitea](https://github.com/go-gitea/gitea) | patch | `1.21.4` -> `1.21.5` |

---

### Release Notes

<details>
<summary>go-gitea/gitea (docker.io/gitea/gitea)</summary>

### [`v1.21.5`](https://github.com/go-gitea/gitea/releases/tag/v1.21.5)

[Compare Source](go-gitea/gitea@v1.21.4...v1.21.5)

-   SECURITY
    -   Prevent anonymous container access if `RequireSignInView` is enabled ([#&#8203;28877](go-gitea/gitea#28877)) ([#&#8203;28882](go-gitea/gitea#28882))
    -   Update go dependencies and fix go-git ([#&#8203;28893](go-gitea/gitea#28893)) ([#&#8203;28934](go-gitea/gitea#28934))
-   BUGFIXES
    -   Revert "Speed up loading the dashboard on mysql/mariadb ([#&#8203;28546](go-gitea/gitea#28546))" ([#&#8203;29006](go-gitea/gitea#29006)) ([#&#8203;29007](go-gitea/gitea#29007))
    -   Fix an actions schedule bug ([#&#8203;28942](go-gitea/gitea#28942)) ([#&#8203;28999](go-gitea/gitea#28999))
    -   Fix update enable_prune even if mirror_interval is not provided ([#&#8203;28905](go-gitea/gitea#28905)) ([#&#8203;28929](go-gitea/gitea#28929))
    -   Fix uploaded artifacts should be overwritten ([#&#8203;28726](go-gitea/gitea#28726)) backport v1.21 ([#&#8203;28832](go-gitea/gitea#28832))
    -   Preserve BOM in web editor ([#&#8203;28935](go-gitea/gitea#28935)) ([#&#8203;28959](go-gitea/gitea#28959))
    -   Strip `/` from relative links ([#&#8203;28932](go-gitea/gitea#28932)) ([#&#8203;28952](go-gitea/gitea#28952))
    -   Don't remove all mirror repository's releases when mirroring ([#&#8203;28817](go-gitea/gitea#28817)) ([#&#8203;28939](go-gitea/gitea#28939))
    -   Implement `MigrateRepository` for the actions notifier ([#&#8203;28920](go-gitea/gitea#28920)) ([#&#8203;28923](go-gitea/gitea#28923))
    -   Respect branch info for relative links ([#&#8203;28909](go-gitea/gitea#28909)) ([#&#8203;28922](go-gitea/gitea#28922))
    -   Don't reload timeline page when (un)resolving or replying conversation ([#&#8203;28654](go-gitea/gitea#28654)) ([#&#8203;28917](go-gitea/gitea#28917))
    -   Only migrate the first 255 chars of a Github issue title ([#&#8203;28902](go-gitea/gitea#28902)) ([#&#8203;28912](go-gitea/gitea#28912))
    -   Fix sort bug on repository issues list ([#&#8203;28897](go-gitea/gitea#28897)) ([#&#8203;28901](go-gitea/gitea#28901))
    -   Fix `DeleteCollaboration` transaction behaviour ([#&#8203;28886](go-gitea/gitea#28886)) ([#&#8203;28889](go-gitea/gitea#28889))
    -   Fix schedule not trigger bug because matching full ref name with short ref name ([#&#8203;28874](go-gitea/gitea#28874)) ([#&#8203;28888](go-gitea/gitea#28888))
    -   Fix migrate storage bug ([#&#8203;28830](go-gitea/gitea#28830)) ([#&#8203;28867](go-gitea/gitea#28867))
    -   Fix archive creating LFS hooks and breaking pull requests ([#&#8203;28848](go-gitea/gitea#28848)) ([#&#8203;28851](go-gitea/gitea#28851))
    -   Fix reverting a merge commit failing ([#&#8203;28794](go-gitea/gitea#28794)) ([#&#8203;28825](go-gitea/gitea#28825))
    -   Upgrade xorm to v1.3.7 to fix a resource leak problem caused by Iterate ([#&#8203;28891](go-gitea/gitea#28891)) ([#&#8203;28895](go-gitea/gitea#28895))
    -   Fix incorrect PostgreSQL connection string for Unix sockets ([#&#8203;28865](go-gitea/gitea#28865)) ([#&#8203;28870](go-gitea/gitea#28870))
-   ENHANCEMENTS
    -   Make loading animation less aggressive ([#&#8203;28955](go-gitea/gitea#28955)) ([#&#8203;28956](go-gitea/gitea#28956))
    -   Avoid duplicate JS error messages on UI ([#&#8203;28873](go-gitea/gitea#28873)) ([#&#8203;28881](go-gitea/gitea#28881))
    -   Bump `@github/relative-time-element` to 4.3.1 ([#&#8203;28819](go-gitea/gitea#28819)) ([#&#8203;28826](go-gitea/gitea#28826))
-   MISC
    -   Warn that `DISABLE_QUERY_AUTH_TOKEN` is false only if it's explicitly defined ([#&#8203;28783](go-gitea/gitea#28783)) ([#&#8203;28868](go-gitea/gitea#28868))
    -   Remove duplicated checkinit on git module ([#&#8203;28824](go-gitea/gitea#28824)) ([#&#8203;28831](go-gitea/gitea#28831))

Instances on **[Gitea Cloud](https://cloud.gitea.com)** will be automatically upgraded to this version during the specified maintenance window.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xNjUuMCIsInVwZGF0ZWRJblZlciI6IjM3LjE2NS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Reviewed-on: https://git.home/nrdufour/home-ops/pulls/355
Co-authored-by: Renovate <renovate@ptinem.io>
Co-committed-by: Renovate <renovate@ptinem.io>
silverwind pushed a commit to silverwind/gitea that referenced this pull request Feb 20, 2024
Fixes go-gitea#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.

go-gitea@bb371ae
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:
```
$ git update-index --refresh
$ git read-tree -m 1f085d7ed8 1f085d7ed8 9933caed00
```
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/manual No power to the bots! Create your backport yourself! backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reverting a merge commit fails
4 participants