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 #19346 - Avoid MoreThanOne error when creating a branch whose name conflicts with other ref names #19557

Merged
merged 4 commits into from
May 1, 2022

Conversation

99rgosse
Copy link
Contributor

@99rgosse 99rgosse commented Apr 29, 2022

This simple commit will ensure that we specify the "Branch" prefix when we want to create new branch. Fix #19346

Otherwise git would check between /refs/heads/tags and /refs/heads/branch and return
error: src refspec mytest matches more than one.
error: failed to push some refs to 'branch'
when there is a tag sharing the same name than the branch.

@6543 6543 added the type/bug label Apr 29, 2022
@6543 6543 added this to the 1.17.0 milestone Apr 29, 2022
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Apr 29, 2022
@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 Apr 29, 2022
@zeripath
Copy link
Contributor

Although I think this is worthwhile I suspect that there will be multiple other problems further down the line. Have you completely tested how Gitea behaves when there are similar branch/tag names?

@@ -35,7 +35,7 @@ func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_mode

if err := git.Push(ctx, repo.RepoPath(), git.PushOptions{
Remote: repo.RepoPath(),
Branch: fmt.Sprintf("%s:%s%s", oldBranchName, git.BranchPrefix, branchName),
Branch: fmt.Sprintf("%s%s:%s%s", git.BranchPrefix, oldBranchName, git.BranchPrefix, branchName),
Copy link
Contributor

@wxiaoguang wxiaoguang Apr 29, 2022

Choose a reason for hiding this comment

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

The oldBranchName might be checked whether is has the BranchPrefix already (and handle the existing prefix gracefully). Otherwise there will be another error.


Hmm, not a must since the old code already works. It seems that this function requires that oldBranchName and branchName shouldn't not have the prefix.

@99rgosse
Copy link
Contributor Author

Although I think this is worthwhile I suspect that there will be multiple other problems further down the line. Have you completely tested how Gitea behaves when there are similar branch/tag names?

I tested it manually on my built instance with latest main, and it worked :
Creating branches from the problematic branch, or creating from other branches
Even creating from branch of branch of the branch that is sharing the tag name.

Also creating a new file or a pull request in the branch that is sharing the tag name, and of children.

image

From the moment the Tag is created with the same name as the branch, I have seen no problems, but well...
If you want I can try to add more tests to this ?

@zeripath
Copy link
Contributor

By testing I meant general UI testing. e.g. How does open PRs from this duplicate branch work? Will do the correct thing? Can you create a PR from the tag and/or the branch? Does it just default to the branch? What happens when you view the branches page on the repository? Do the counts work correctly? How about the Tag page?

@wxiaoguang
Copy link
Contributor

By testing I meant general UI testing. e.g. How does open PRs from this duplicate branch work? Will do the correct thing? Can you create a PR from the tag and/or the branch? Does it just default to the branch? What happens when you view the branches page on the repository? Do the counts work correctly? How about the Tag page?

Some of the questions seems more general to the PR modules (not affected by this one). Some questions like Can you create a PR from the tag and/or the branch? I think it's correct now (I have checked all calls to the CreateNewBranch before, all passed-in arguments are branch names).

Are these questions as blocker?

@codecov-commenter
Copy link

Codecov Report

Merging #19557 (31484c9) into main (1597e2d) will increase coverage by 0.00%.
The diff coverage is 50.00%.

@@           Coverage Diff           @@
##             main   #19557   +/-   ##
=======================================
  Coverage   47.39%   47.39%           
=======================================
  Files         952      952           
  Lines      132577   132576    -1     
=======================================
+ Hits        62829    62840   +11     
+ Misses      62174    62156   -18     
- Partials     7574     7580    +6     
Impacted Files Coverage Δ
modules/setting/log.go 58.23% <0.00%> (ø)
routers/api/v1/repo/language.go 57.14% <100.00%> (-0.76%) ⬇️
services/repository/branch.go 55.38% <100.00%> (ø)
models/asymkey/gpg_key_common.go 52.63% <0.00%> (-3.95%) ⬇️
modules/notification/mail/mail.go 39.04% <0.00%> (-2.74%) ⬇️
modules/log/event.go 59.92% <0.00%> (-2.34%) ⬇️
modules/notification/ui/ui.go 58.92% <0.00%> (-1.79%) ⬇️
models/unit/unit.go 46.08% <0.00%> (-1.74%) ⬇️
models/notification.go 63.17% <0.00%> (-1.09%) ⬇️
models/repo_list.go 75.66% <0.00%> (-0.49%) ⬇️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 094c8fd...31484c9. Read the comment docs.

@6543 6543 merged commit edff571 into go-gitea:main May 1, 2022
@6543
Copy link
Member

6543 commented May 1, 2022

please send backport

zjjhot added a commit to zjjhot/gitea that referenced this pull request May 1, 2022
* giteaofficial/main:
  Avoid MoreThanOne Error (go-gitea#19557)
  [skip ci] Updated licenses and gitignores
  Simplify loops to copy (go-gitea#19569)
  Use middleware to open gitRepo (go-gitea#19559)
  Added X-Mailer header to outgoing emails (go-gitea#19562)
  fix go-gitea#19545 (go-gitea#19563)
  [skip ci] Updated translations via Crowdin
  Respect DefaultUserIsRestricted system default when creating new user (go-gitea#19310)
  Mute link in diff header (go-gitea#19556)
  Add API to query collaborators permission for a repository (go-gitea#18761)
  Permalink files In PR diff (go-gitea#19534)
  Fix Pull Request comment filename word breaks (go-gitea#19535)
  Don't error when branch's commit doesn't exist (go-gitea#19547)
@6543 6543 added the backport/done All backports for this PR have been created label May 3, 2022
wxiaoguang pushed a commit that referenced this pull request May 3, 2022
@wxiaoguang wxiaoguang added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label May 3, 2022
@wxiaoguang wxiaoguang changed the title Fix #19346 - avoid MoreThanOne Error Fix #19346 - Avoid MoreThanOne error when creating a branch whose name conflicts with other ref names May 3, 2022
AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this pull request Aug 24, 2022
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
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 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using web interface to create branch from existing branch with identical release name leads to error 500
8 participants