ingydotnet / git-subrepo

MIT License
3.18k stars 263 forks source link

Adding a second remote repository #594

Closed jcalfee closed 9 months ago

jcalfee commented 10 months ago

I would like to add a second remote repository to push to. The git subrepo [project] -r [--remote=new_url] command seam to ignore the new remote URL and just tells me the [old] repository was already up to date. So, it did not record the new URL in [project]/.gitrepo .. I also tried adding it to my main git remotes and then tried using the alias in git subrepo [project] -r [alias] to no avail. Am I doing something wrong? Is this supported?

thank you..

admorgan commented 10 months ago

git subrepo does not support multiple remote entries for a codebase. You can change the remote the code is pointing at via git subrepo update --remote "<new url>" -- <project path>. See https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-update--init--remote-N--no-fetch--no-recommend-shallow-f--force--checkout--rebase--merge--referenceltrepositorygt--depthltdepthgt--recursive--jobsltngt--no-single-branch--filterltfilterspecgt--ltpathgt82308203

jcalfee commented 10 months ago

Thanks for clarifying. The additional remotes would be for push deploys (production, dev, etc.). Currently I use subrepo to update the main repository then I have another folder and repo where I pull to update then push deploy from there where, in some cases, that would be unnecessary if I could push to other repositories from subrepo.. It could be automated, but some cases are just simple and don't need all that. This is still a very good and flexible setup though.

admorgan commented 10 months ago

You can do a git subrepo push -r "url" <subrepo path> will let you accomplish what you I believe your stated goal is. This will use the remote URL for this command only, if you want to update the remote you would need to add --update to the command.

jcalfee commented 10 months ago

This must be the confusion. The subdir in the subrepo help comes first before the -r "remote url":

$ git subrepo help push

   Usage: git subrepo push <subdir>|--all [<branch>] [-m msg] [--file=<msg file>] [-r <remote>] [-b <branch>] [-M|-R] [-u] [-f] [-s] [-N]

Your command does cause it to try and use the new URL. I can't get past this one even with a --force:

git-subrepo: Local repository does not contain 552dcad6.... Try to 'git subrepo fetch go' or add the '-F' flag to always fetch the latest content.

I don't want to pull because that is the target of a push deploy so it should have nothing new in it..

admorgan commented 10 months ago

Try git subrepo fetch -r <remote url> then try again.

jcalfee commented 10 months ago

Thanks .. I will never fetch from a push only deploy server though. I typically only push, but sometimes force push after an amend.. If there is a reason that force does not work that is fine, I'll just go back to the two repository hack.

admorgan commented 10 months ago

Is this issue closed in your opinion? Anything I can do to make this work better with your workflow?

jcalfee commented 10 months ago

a) The subrepo help appears to be incorrect. b) force push may be broken (but I can't confirm that one).

I would say you might want to fix (a) if you agree. That should help your script. Up to you if you want to close the ticket, feel free anytime. I'm just giving feedback. Thank you!

jcalfee commented 9 months ago

You can do a git subrepo push -r "url" <subrepo path> will let you accomplish what you I believe your stated goal is. This will use the remote URL for this command only,

Confirmed, git subrepo push -r "url" <subrepo path> worked. It used the alternative URL for that command only. This is very powerful in mono-repositories (as described).

It differs from git push a bit. It took a while to run so I was not sure if it was forming the subrepo tree or actually pushing. I figured out, it does prepare it but during the push git subrepo push ... does not show the server's output as it happens and does not show the server's output after it is done. But it does seam to confirm it worked and certainly confirms when it is done (Subrepo 'myrepo' pushed to 'url' (master).). A regular git push ... will stream the server's output during the push as it runs (you can hook scripts into git events). So, in my case, a partial work around is to try and tail the server while I push; but that is not ideal as a live deploy creates a new process that needs to be fish down (docker ps for example) and tailed on the server which requires that anyone doing the push have access to the server's logs (not just the 1st set of logs during the push).

This is still a very powerful trick with mono-repositories and push deploys over what can easily be done with git though. It really lets me control what gets pushed where very easily all while having unit tests keep en eye on the everything. I have some unit tests running during this git push so many common things can't break. It is really simple and powerful.

So, looking at git subrepo push it shows help

Usage: git subrepo push <subdir>|--all [<branch>] [-m msg] [--file=<msg file>] [-r <remote>] [-b <branch>] [-M|-R] [-u] [-f] [-s] [-N]

Maybe it would help a bit if this started out as:

Usage: git subrepo <options> push <subdir>|...
jcalfee commented 9 months ago

I'll close, I see how it works and the help is correct. The rest are feature suggestions.

jcalfee commented 9 months ago

After git subrepo push -r "url" <subrepo path> I did a regular git subrepo push <subrepo path> and it used the -r url as if I had specified update, but I did not specify update. In other words, I accidentally deployed to production when I mean to only push to the regular repository.