Fix #19346 - Avoid MoreThanOne error when creating a branch whose name conflicts with other ref names#19557
Conversation
|
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? |
| 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), |
There was a problem hiding this comment.
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.
I tested it manually on my built instance with latest main, and it worked : Also creating a new file or a pull request in the branch that is sharing the tag name, and of children. From the moment the Tag is created with the same name as the branch, I have seen no problems, but well... |
|
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 Are these questions as blocker? |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
please send backport |
* 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)
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.