Ambiguous compare URL results in 404 #6978

Closed
opened 2025-11-02 07:12:41 -06:00 by GiteaMirror · 10 comments
Owner

Originally created by @flozzone on GitHub (Mar 7, 2021).

2021/03/07 18:51:43 ...s/context/context.go:139:HTML() [D] Template: status/404
	/go/src/code.gitea.io/gitea/modules/context/context.go:139 (0x166ce41)
	/go/src/code.gitea.io/gitea/modules/context/context.go:168 (0x166d275)
	/go/src/code.gitea.io/gitea/modules/context/context.go:155 (0x2016f75)
	/go/src/code.gitea.io/gitea/routers/repo/compare.go:359 (0x2016f47)
	/go/src/code.gitea.io/gitea/routers/repo/compare.go:531 (0x2019dcf)
	/usr/local/go/src/reflect/value.go:476 (0x4a6586)
	/usr/local/go/src/reflect/value.go:337 (0x4a5a78)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0xd905d9)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0xd8ffaa)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xd91afc)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x167a813)
	/go/src/code.gitea.io/gitea/modules/context/repo.go:593 (0x167a7fc)
	/usr/local/go/src/reflect/value.go:476 (0x4a6586)
	/usr/local/go/src/reflect/value.go:337 (0x4a5a78)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0xd905d9)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0xd8ffaa)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xd91afc)
	/go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x1678034)
	/go/src/code.gitea.io/gitea/modules/context/panic.go:39 (0x1678025)

Description

There is a specific structure of repositories and organizations we need in order to complete our work. First I'll explain our use case. In Steps to reproduce I'll show how I could create the organization/repository structure, exactly how I was expecting it to be. However when trying to create a specific PR the feature-branch is not listed, shown in Steps to show that feature branch is not listed. Finally Steps to show 404 and how to adapt compare URL shows how I got the 404 page and how I adapted the compare URL to get the desired PR.
The repository structure is available at https://try.gitea.io. If you'd like me to create this structure somewhere else, just tell me.

Use case

  • A company develops a open source project
  • we mirror the company's repo to our gitea server inside company-org organization
  • we fork their repository and we push to our customization we/custom-project repo
  • we create PR from the mirror of the company's public repo company-org/project to our customization our-org/custom-project to merge upstream changes
  • we pay the company to develop custom features based on our customized code and thus the company gets access to their company-org organization
  • company pushes to a fork company-org/custom-project of our customized repo
  • we create PR from company's custom repo company-org/custom-project to our customization our-org/custom-project

At the end we would like to have the following fork chain:
company-org/project (mirror) <- our-org/custom-project <- company-org/custom-project

Steps to reproduce

  1. Created mirror from public repo: https://github.com/flozzone/project.git -> company/project
  2. Created fork from company/project to our-org/custom-project
  3. Created fork from our-org/custom-project to this-is-me/custom-project [1]
  4. Changed ownership from this-is-me/custom-project to company-org [1]
  5. Push changes on branch payed_feature to company-org/custom-project repo
  6. Goto company-org/custom-project

Steps to show that feature branch is not listed

7a. Select main branch
8a. Click Create Pull Request
9a. Open pull from dropdown
10a. payed-feature is not listed

Steps to show 404 and how to adapt compare URL

7b. Select payed-feature branch
8b. Click Create Pull Request -> 404
9b. Change compare URL from https://try.gitea.io/our-org/custom-project/compare/main...company-org:payed-feature to https://try.gitea.io/our-org/custom-project/compare/main...company-org/custom-project:payed-feature -> Compare is correctly shown

[1] Steps 3. and 4. were required in order to create a fork in the same organization in which the mirror is located. Creating
the fork directly was not possible since the owner was not listed when forking.

Thoughts and questions

Is this 404 occurring because we have the mirror and a fork of same repository inside one organization? Why is the adapted compare URL working. IMHO this is a popular use case (despite the fact that no one reported this before) or is there another way to accomplish what I want?

Originally created by @flozzone on GitHub (Mar 7, 2021). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Make sure it's not mentioned in the FAQ (https://docs.gitea.io/en-us/faq) 5. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.13.2 - Git version: 2.26.2 - Operating system: docker - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [x] Yes (https://try.gitea.io/our-org/custom-project/compare/main...company-org:payed-feature) - [ ] No - Log gist: <!-- It really is important to provide pertinent logs --> <!-- Please read https://docs.gitea.io/en-us/logging-configuration/#debugging-problems --> <!-- In addition, if your problem relates to git commands set `RUN_MODE=dev` at the top of app.ini --> ``` 2021/03/07 18:51:43 ...s/context/context.go:139:HTML() [D] Template: status/404 /go/src/code.gitea.io/gitea/modules/context/context.go:139 (0x166ce41) /go/src/code.gitea.io/gitea/modules/context/context.go:168 (0x166d275) /go/src/code.gitea.io/gitea/modules/context/context.go:155 (0x2016f75) /go/src/code.gitea.io/gitea/routers/repo/compare.go:359 (0x2016f47) /go/src/code.gitea.io/gitea/routers/repo/compare.go:531 (0x2019dcf) /usr/local/go/src/reflect/value.go:476 (0x4a6586) /usr/local/go/src/reflect/value.go:337 (0x4a5a78) /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0xd905d9) /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0xd8ffaa) /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xd91afc) /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x167a813) /go/src/code.gitea.io/gitea/modules/context/repo.go:593 (0x167a7fc) /usr/local/go/src/reflect/value.go:476 (0x4a6586) /usr/local/go/src/reflect/value.go:337 (0x4a5a78) /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0xd905d9) /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0xd8ffaa) /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xd91afc) /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x1678034) /go/src/code.gitea.io/gitea/modules/context/panic.go:39 (0x1678025) ``` ## Description There is a specific structure of repositories and organizations we need in order to complete our work. First I'll explain our use case. In _Steps to reproduce_ I'll show how I could create the organization/repository structure, exactly how I was expecting it to be. However when trying to create a specific PR the feature-branch is not listed, shown in _Steps to show that feature branch is not listed_. Finally _Steps to show 404 and how to adapt compare URL_ shows how I got the 404 page and how I adapted the compare URL to get the desired PR. The repository structure is available at https://try.gitea.io. If you'd like me to create this structure somewhere else, just tell me. ### Use case * A company develops a open source project * `we` mirror the company's repo to our gitea server inside `company-org` organization * `we` fork their repository and `we` push to our customization `we/custom-project` repo * `we` create PR from the mirror of the company's public repo `company-org/project` to our customization `our-org/custom-project` to merge upstream changes * `we` pay the company to develop custom features based on our customized code and thus the company gets access to their `company-org` organization * `company` pushes to a fork `company-org/custom-project` of our customized repo * `we` create PR from company's custom repo `company-org/custom-project` to our customization `our-org/custom-project` At the end we would like to have the following fork chain: `company-org/project` (mirror) <- `our-org/custom-project` <- `company-org/custom-project` ### Steps to reproduce 1. Created mirror from public repo: https://github.com/flozzone/project.git -> `company/project` 2. Created fork from `company/project` to `our-org/custom-project` 3. Created fork from `our-org/custom-project` to `this-is-me/custom-project` [1] 4. Changed ownership from `this-is-me/custom-project` to `company-org` [1] 5. Push changes on branch `payed_feature` to `company-org/custom-project` repo 6. Goto `company-org/custom-project` #### Steps to show that feature branch is not listed 7a. Select `main` branch 8a. Click `Create Pull Request` 9a. Open `pull from` dropdown 10a. `payed-feature` is not listed #### Steps to show 404 and how to adapt compare URL 7b. Select `payed-feature` branch 8b. Click `Create Pull Request` -> 404 9b. Change compare URL from https://try.gitea.io/our-org/custom-project/compare/main...company-org:payed-feature to https://try.gitea.io/our-org/custom-project/compare/main...company-org/custom-project:payed-feature -> Compare is correctly shown [1] Steps 3. and 4. were required in order to create a fork in the same organization in which the mirror is located. Creating the fork directly was not possible since the owner was not listed when forking. ## Thoughts and questions Is this 404 occurring because we have the mirror and a fork of same repository inside one organization? Why is the adapted compare URL working. IMHO this is a popular use case (despite the fact that no one reported this before) or is there another way to accomplish what I want? <!-- ## Screenshots <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the type/bug label 2025-11-02 07:12:41 -06:00
Author
Owner

@zeripath commented on GitHub (Mar 7, 2021):

the simple issue is that the shortcut url: https://try.gitea.io/our-org/custom-project/compare/main...company-org:payed-feature is looking for the payed-feature branch in company-org/project not company-org/custom-project.

How would gitea know that you meant company-org/custom-project?

@zeripath commented on GitHub (Mar 7, 2021): the simple issue is that the shortcut url: https://try.gitea.io/our-org/custom-project/compare/main...company-org:payed-feature is looking for the payed-feature branch in company-org/project not company-org/custom-project. How would gitea know that you meant company-org/custom-project?
Author
Owner

@flozzone commented on GitHub (Mar 7, 2021):

This is what I thought, but gitea should now that I need a PR from company-org/custom-project since I selected it (see step 6) and clicked Create Pull Request. I am not constructing the compare URL myself.

For me it seems that the syntax which is used in the compare URL/view is ambiguous: ORG:BRANCH is not enough to identify a branch in my situation. The current syntax works well when the forked-from repo is owned by another organization with the assumption that it has the same name. With my structure I am hitting the limit to have just one fork of a repo in the same organization, this is why I needed step 3,4 to move the repo.

But I think this could be work around by first checking for ambiguity and in case use the full syntax: ORG/REPO:BRANCH. This is actually done in case I select some branch from company-org/project (See the screenshot below)

image

But somehow not all branches are shown. The payed-feature is not in the list:

image

while it should be there:

image

@flozzone commented on GitHub (Mar 7, 2021): This is what I thought, but gitea should now that I need a PR from `company-org/custom-project` since I selected it (see step 6) and clicked `Create Pull Request`. I am not constructing the compare URL myself. For me it seems that the syntax which is used in the compare URL/view is ambiguous: ORG:BRANCH is not enough to identify a branch in my situation. The current syntax works well when the forked-from repo is owned by another organization with the assumption that it has the same name. With my structure I am hitting the limit to have just one fork of a repo in the same organization, this is why I needed step 3,4 to move the repo. But I think this could be work around by first checking for ambiguity and in case use the full syntax: ORG/REPO:BRANCH. This is actually done in case I select some branch from `company-org/project` (See the screenshot below) ![image](https://user-images.githubusercontent.com/1153549/110257226-24dd2d80-7f9d-11eb-9999-0b736e009d91.png) But somehow not all branches are shown. The `payed-feature` is not in the list: ![image](https://user-images.githubusercontent.com/1153549/110257292-8a311e80-7f9d-11eb-88fe-deaf368052b1.png) while it should be there: ![image](https://user-images.githubusercontent.com/1153549/110257328-b8aef980-7f9d-11eb-8f9c-056f0a2a1d66.png)
Author
Owner

@zeripath commented on GitHub (Mar 8, 2021):

So the simplifying code is getting things wrong in this case. The trouble is I can't remember where I put it.

@zeripath commented on GitHub (Mar 8, 2021): So the simplifying code is getting things wrong in this case. The trouble is I can't remember where I put it.
Author
Owner

@zeripath commented on GitHub (Mar 8, 2021):

OK there is no way we can ever use the simplified url in this case - however, that seems like an overkill in the general case - because most people will not be doing this kind of naughty behaviour...

Aha. The trick is if the baserepo is a fork then that is the only way you could need the full repo id.

diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl
index 4d8d28921..b77f28f92 100644
--- a/templates/repo/home.tmpl
+++ b/templates/repo/home.tmpl
@@ -64,7 +64,7 @@
 			{{if eq $n 0}}
 				{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
 					<div class="fitted item mx-0">
-						<a href="{{.BaseRepo.Link}}/compare/{{.BaseRepo.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}:{{end}}{{.BranchName | EscapePound}}">
+						<a href="{{.BaseRepo.Link}}/compare/{{.BaseRepo.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}{{if .BaseRepo.IsFork}}/{{.Repository.Name}}{{end}}:{{end}}{{.BranchName | EscapePound}}">
 							<button id="new-pull-request" class="ui compact basic button">{{if .PullRequestCtx.Allowed}}{{.i18n.Tr "repo.pulls.compare_changes"}}{{else}}{{.i18n.Tr "action.compare_branch"}}{{end}}</button>
 						</a>
 					</div>

sorts out the initial 404

@zeripath commented on GitHub (Mar 8, 2021): OK there is no way we can ever use the simplified url in this case - however, that seems like an overkill in the general case - because most people will not be doing this kind of naughty behaviour... Aha. The trick is if the baserepo is a fork then that is the only way you could need the full repo id. ```diff diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 4d8d28921..b77f28f92 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -64,7 +64,7 @@ {{if eq $n 0}} {{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}} <div class="fitted item mx-0"> - <a href="{{.BaseRepo.Link}}/compare/{{.BaseRepo.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}:{{end}}{{.BranchName | EscapePound}}"> + <a href="{{.BaseRepo.Link}}/compare/{{.BaseRepo.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}{{if .BaseRepo.IsFork}}/{{.Repository.Name}}{{end}}:{{end}}{{.BranchName | EscapePound}}"> <button id="new-pull-request" class="ui compact basic button">{{if .PullRequestCtx.Allowed}}{{.i18n.Tr "repo.pulls.compare_changes"}}{{else}}{{.i18n.Tr "action.compare_branch"}}{{end}}</button> </a> </div> ``` sorts out the initial 404
Author
Owner

@zeripath commented on GitHub (Mar 8, 2021):

This should make 1.14 but likely rc2

@zeripath commented on GitHub (Mar 8, 2021): This should make 1.14 but likely rc2
Author
Owner

@flozzone commented on GitHub (Mar 9, 2021):

Thanks @zeripath for your fast reaction and patch. Since I was always using the docker container you provided, I would have to build it on my own and push it to our server. Easier would be some kind of nightly build to test this out. Is there something similar with your provided patch?

@flozzone commented on GitHub (Mar 9, 2021): Thanks @zeripath for your fast reaction and patch. Since I was always using the docker container you provided, I would have to build it on my own and push it to our server. Easier would be some kind of nightly build to test this out. Is there something similar with your provided patch?
Author
Owner

@zeripath commented on GitHub (Mar 9, 2021):

the associated PR touches two templates only and which can be placed in your custom folder as per https://docs.gitea.io/en-us/customizing-gitea/

@zeripath commented on GitHub (Mar 9, 2021): the associated PR touches two templates only and which can be placed in your custom folder as per https://docs.gitea.io/en-us/customizing-gitea/
Author
Owner

@flozzone commented on GitHub (Mar 9, 2021):

I've tryied it out, but it requires other templates in the $GITEA_CUSTOM path, an error message said. So I aborted testing.

@flozzone commented on GitHub (Mar 9, 2021): I've tryied it out, but it requires other templates in the $GITEA_CUSTOM path, an error message said. So I aborted testing.
Author
Owner

@flozzone commented on GitHub (Mar 9, 2021):

But since you are releasing so frequently, I guess I don't have to wait so long for this to get released.

@flozzone commented on GitHub (Mar 9, 2021): But since you are releasing so frequently, I guess I don't have to wait so long for this to get released.
Author
Owner

@CL-Jeremy commented on GitHub (Mar 14, 2021):

This won't be merged until v1.14.0 (or a release candidate) is released.

You can get the template files from: https://github.com/CL-Jeremy/gitea/tree/backport-fix-14921/templates/repo. Download these two raw files: home.tmpl and diff/compare.tmpl, put them in $GITEA_CUSTOM/templates/repo and you are good to go.

These files are generated with:

git checkout v1.13.4
git remote add zeripath https://github.com/zeripath/gitea.git
git fetch zeripath fix-14921-compare-urls-on-forked-forks
git cherry-pick zeripath/fix-14921-compare-urls-on-forked-forks
@CL-Jeremy commented on GitHub (Mar 14, 2021): This won't be merged until v1.14.0 (or a release candidate) is released. You can get the template files from: https://github.com/CL-Jeremy/gitea/tree/backport-fix-14921/templates/repo. Download these two raw files: [home.tmpl](/CL-Jeremy/gitea/raw/backport-fix-14921/templates/repo/home.tmpl) and [diff/compare.tmpl](/CL-Jeremy/gitea/raw/backport-fix-14921/templates/repo/diff/compare.tmpl), put them in `$GITEA_CUSTOM/templates/repo` and you are good to go. These files are generated with: ``` git checkout v1.13.4 git remote add zeripath https://github.com/zeripath/gitea.git git fetch zeripath fix-14921-compare-urls-on-forked-forks git cherry-pick zeripath/fix-14921-compare-urls-on-forked-forks ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#6978