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

Ambiguous compare URL results in 404 #14921

Closed
2 of 6 tasks
flozzone opened this issue Mar 7, 2021 · 10 comments · Fixed by #14932
Closed
2 of 6 tasks

Ambiguous compare URL results in 404 #14921

flozzone opened this issue Mar 7, 2021 · 10 comments · Fixed by #14932
Labels
Milestone

Comments

@flozzone
Copy link
Contributor

flozzone commented 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?

@zeripath
Copy link
Contributor

zeripath commented 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?

@flozzone
Copy link
Contributor Author

flozzone commented 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 flozzone changed the title PR from forked repo to forked mirror results in 404 compare page Ambiguous compare URL results in 404 Mar 8, 2021
@zeripath
Copy link
Contributor

zeripath commented 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
Copy link
Contributor

zeripath commented 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
Copy link
Contributor

zeripath commented Mar 8, 2021

This should make 1.14 but likely rc2

@zeripath zeripath added this to the 1.14.0 milestone Mar 8, 2021
@flozzone
Copy link
Contributor Author

flozzone commented 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?

@zeripath
Copy link
Contributor

zeripath commented 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/

@flozzone
Copy link
Contributor Author

flozzone commented 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
Copy link
Contributor Author

flozzone commented 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.

@CL-Jeremy
Copy link
Contributor

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

@go-gitea go-gitea locked and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants