-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix deleting a remote tag when a remote branch with the same name exists, or vice versa #5075
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 deleting a remote tag when a remote branch with the same name exists, or vice versa #5075
Conversation
Seems to be a copy/paste error from another test.
Trying to delete a remote tag when a remote branch with the same name exists results in an error, and vice versa.
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesFootnotes
|
miduddin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm this works, but I have some comments about the code. Thanks!
| cmdArgs := NewGitCmd("push"). | ||
| Arg(remoteName, "--delete"). | ||
| Arg(branchNames...). | ||
| Arg(lo.Map(branchNames, func(b string, _ int) string { return "refs/heads/" + b })...). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that now we have two lo.Map calls, one here and one on the caller of DeleteRemoteBranch. Is it preferable to have these two joined together?
Also, the caller works with the type models.RemoteBranch, there is a FullRefName() method that returns "refs/remotes/<remote_name>/<branch_name>" which unfortunately can't be used for this, but on the tag side that works with models.Tag the FullRefName() can be used. It's a bit weird from the consistency standpoint so I don't know if we want to use them without some extra work, but I figured to just mention it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the careful review, both are good observations.
-
No, I think it's fine this way; the fact that we have two
lo.Mapcalls doesn't bother me, and it helps with having clearer APIs. The alternatives would be: a) pass an instance ofmodels.RemoteBranchtoRemoteCommands.DeleteRemoteBranch, so that it can do both transformations inside; that's not possible, becausegit_commandsshouldn't have a dependency on the models. Or b) require the caller to pass in the full ref name, but callers shouldn't have to have this knowledge, it's a clearer API to only pass in the name. -
We can't use
FullRefName()anyway because we only want to pass in the bare names, but even if we could, we shouldn't useFullRefName()here. It's the full ref name from the perspective of the local repo, which is not what we need here. We need it from the perspective of the remote repo, and it's the responsibility of theDeleteRemoteTag/DeleteRemoteBranchfunctions to know how to construct these. It's true that for tags both are the same, but that's only because git doesn't have a concept of remote tags like it does for branches. You could imagine that a future version of git adds this, and then we might changeTag.FullRefNameto return the local ref for a remote tag, which would break theDeleteRemoteTagfunction if it were to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I do agree that the current implementation is good/clear enough as is, but I still wonder if there is a case to be made for putting the "refs/..." construction into one place since it has specific meaning. I don't have enough knowledge on the project structure though, so I'll leave the decisions to you, please don't treat this comment as a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that the current place (inside of DeleteRemoteTag/DeleteRemoteBranch) is exactly the right place. (And I don't feel we need an abstraction for this, like a FullRefFromTheRemotesPerspective or some such; that feels like overkill to me.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha no, I was thinking along the lines of using models.Branch instead of models.RemoteBranch which would make it more aligned with what the actual git command accepts (a full local refname), but I have no idea how to make it a good fit since we are working with remote branch view in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that would feel weird to me, and would make it rather harder to understand than easier.
Anyway, thanks again for the review!
Nothing to add to the PR title here.
Fixes #5072.