-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: add fork remote command #4831
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
feat: add fork remote command #4831
Conversation
Yes, that's a great follow-up. It should be easy to do, too. I will implement it.
Yeah, I might have gone overboard with the url parsing. I didn't know we had regex support. Regex would work well for ssh urls, but it's a bit more nuanced for http/https urls, but I'll try to simplify it.
I also don't have experience besides github, but I think most other hosting services follow the same owner/repo url pattern as github does, so it should work fine without any further modifications. I might be wrong on this, though. I'm away from home for about 2 weeks, so I won't be active on this right now. |
|
I've refactored the replacement to just use regex replace. I think your suggestion is great follow up, but I think it should be supported not just in this new add fork feature, but also when adding a general remote like @stefanhaller friendly ping |
ffd365b to
d74c08d
Compare
|
Nevermind, I added the ability to checkout PRs with |
d74c08d to
651ee12
Compare
|
Still didn't look at the code very much, but tested the feature, and it works nicely. One thing I'm wondering is whether we need the second prompt that asks for a remote name; in my own use, I always use the same name as the forkUsername, doesn't everybody? And then, I was also wondering if this even needs to be a separate command at all. We could include the functionality in the normal "add new remote" command, where the first prompt would say |
Not always. I often add my own fork as origin or the main repo as upstream. But if we ditched the name prompt, I guess I could just rename the remote after creating it.
Incorporating it into add remote sounds nice in theory, but I’m not sure it works as well in practice. You still end up with two prompts and some limits:
It also gets tricky if there’s no origin or multiple remotes. I think incorporating it this way would be too clunky. Dedicated command feels clearer, more powerful, and would allow more flexibility. I'm open to other suggestions for improving this new feature. |
|
I have used this for a while in my local build now, and I quite like it. I'm happy to keep it as a separate command; after thinking about it more, my suggestion to incorporate it into the add remote command wasn't so good. However, I still can't get used to the second prompt, and I still vote for getting rid of it. The only scenarios I can imagine where you would want a different remote name is either origin itself (but that's irrelevant here), or an "upstream" remote. For that, I'd imagine you would use the regular add remote command; or rename it afterwards. Since that's a one-time thing, I don't find that too bad. But in all other cases the additional prompt is simply confusing, it trips me up every time. Apart from that, I was thinking if we should have any special handling of the case that a remote with that name already exists; currently you get an error popup, which I guess is appropriate, but I was thinking it might be nice if I didn't have to pay attention and it would just use the existing remote and only check out the branch. But maybe that's too much magic and we just keep it the way it is. |
|
I'm okay with removing the name prompt. |
|
Yes, that's pretty much what I had in mind. We should probably only do that when "user:branch" was given though; otherwise, when only a user was given, there would be no feedback. I guess we should still show a "remote already exists" popup in that case. |
|
I'm not sure the behavior should change depending if only user was provided or not (in the case of remote already existing). |
e4ab952 to
9ddda01
Compare
I was initially thinking that it should definitely show a popup in the case that no branch was given, because otherwise the command would silently do nothing and you wouldn't see any feedback, which would feel a bit broken. But I now realized that this is not the case: it will still select the remote and fetch it, so you do get visual feedback. Fine with me then.
This coming along really nicely now, great work. I squashed your commits into one, rebased onto master, and added a few fixups; see their commit messages for what they are about. There are probably a few more minor nitpicks to sort out (for example, some error strings are not i18n'ed), but before I look more closely at those, there's one more fundamental thing to talk about: currently the function works with the selected remote and uses it as a base URL. I was surprised to see this in the code, and it contradicts what the tooltip says, which talks about the origin remote. I would have expected that it doesn't matter what remote is selected when I invoke Maybe it doesn't make a difference in practice since origin and all fork remotes tend to have the same URL pattern usually, but I'm not sure this has to be the case, and I just found it surprising. Any thoughts on that? |
I'm happy to hear that!
I must have accidentally typed 'origin' instead of 'remote', that has been my intention from the start. However, as I said I don't really see any usecase for using 2 schemes for different 'fork' remotes. Another argument is that it'd work fine without origin remote, but that's rare too. |
9ddda01 to
a5fa422
Compare
|
Hey, sorry for the delay. I think the only thing left now is to translate the errors from the |
6821aca to
993ae20
Compare
|
I finally got around to looking at this again, sorry that it took so long. I pushed several fixup commits again, please review. I'm happy with the current state of the branch, and would be ready to merge it if you agree with my changes.
That's the standard way of making changes to a branch during review. It allows you to maintain a clean commit history from the beginning, while still making changes transparent. See https://github.com/jesseduffield/lazygit/blob/master/docs/Fixup_Commits.md.
It's normal for CI to fail because of fixup commits. This check exists to make sure we don't forget to squash them at the end.
While this may be true for this particular PR, it's not the default assumption; most of my PRs have more than one commit. I prefer to use fixup commits no matter what so that I don't have to think about it.
Not at all, this wouldn't be an issue; tests always run against the english translation, so it's fine to hard-code translatable error messages in tests. However: I got rid of two of the errors (1550662), so the only one left is the one about an invalid origin URL. Since this should never happen in practice, I decided to not pollute the language file with it and leave it in english, I think that's good enough. |
993ae20 to
450af43
Compare
The changes make sense and everything's working nicely. Let's finally merge this. As for the fixup 'workflow' — I wasn't familiar with it but I like it. I squashed the commits. |
|
I also updated the PR description and removed the demo clip as it was outdated. |
The command allows you to quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote.
450af43 to
3892c40
Compare
PR Description
The command allows you to quickly add a fork remote by replacing the owner in the origin URL and optionally check out a branch from new remote.
Examples:
given url:
https://github.com/jesseduffield/lazygit.gitand username:
karolzwolakadds a new remote with url:
https://github.com/karolzwolak/lazygit.gitgiven url:
https://github.com/jesseduffield/lazygit.gitand username:
karolzwolak:add-fork-remote-commandadds a new remote with url:
https://github.com/karolzwolak/lazygit.gitand then checks out it's branch
add-fork-remote-commandPlease check if the PR fulfills these requirements
go generate ./...)