-
I’m using
The main repo checks out the However, none of the other branches appear for the submodule, and I can’t find a way to check them out when I need to. I don’t see that I can do this through the checkout Action, but I’ve tried some other things I’d expect to at least do something. In the next Action step, I’ve tried these commands on the submodule.
But no matter what I do, I only see these:
None of my other branches ever show up, and I can’t check them out. Any idea why? Is there some limitation in Actions with submodules? Am I just doing something silly and wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Okay, I’ve tried lots of new things, and I figured something out. I can see the remote refs like this:
So the other branch does exist remotely. But still a branch list doesn’t show
This only occurs after using the checkout Action. When I clone with submodules locally everything is fine. I just don’t know if this is a bug for the checkout action or if I’m doing something wrong. |
Beta Was this translation helpful? Give feedback.
-
Hi @aormsby, Submodules are not on a branch. They are just a pointer to a particular commit of the submodule’s repository. After checkout the parent repo, you can update the submodule branch, and checkout the target branch then. Code sample as below(submodule : ticket7 with B1 branch)
Please refer to my workflow for the details. Doc: https://tech.serhatteker.com/post/2019-01/changing-git-submodules-urlbranch-to/ Thanks |
Beta Was this translation helpful? Give feedback.
-
Ooooohhhhhh, this makes complete sense. I just didn’t realize I needed to set the There’s still one small snag for me. If the submodule is a private repo, I get a fatal error when I run the sync because the submodule URL doesn’t include user name and key information by default.
I may be able to manipulate the URL in .gitmodules to include that, but I think it would be better to use the secret token like in the checkout. Shouldn’t the token credentials persist from the checkout action?? The readme says they should by default, but maybe I’m doing something wrong there as well. Edit: Also, could you explain why keeping |
Beta Was this translation helpful? Give feedback.
-
Okay, I’ve got it! The original solution I marked got me really close to the right functionality, but there were still some issues coming through. However, I want to thank @weide-zhou for their help. I couldn’t have come to these solutions without the push. :slight_smile: The Underlying ProblemThe git refspec for the submodules wasn’t configured to track any remote refs outside ‘master’ so I could never get the other remote refs to other branches. Incorrect config:
Config that gets all refs:
The checkout action has a default So we gotta fix that. @weide-zhou was on the way to that, but I found two ways to do it that attack the problem more directly. Solution #1 - change fetch-depthWorkflow:
From the checkout readme:
Setting the value to 0 leaves the fetch config set to *, and all remote refs are available for checkout. This is the quick fix. The downside is that you’re pulling the entire history of your branches and tags for the main repo and all submodules, so I also came up with a more surgical adjustment. Solution #2 - modify the config fetch by handThis solution allows control over specific submodule fetch config so other submodule configurations are left untouched. Workflow (same minus fetch-deptch):
Somewhere in your action you can run the following commands:
The main reason I had to build on @weide-zhou’s solution was to maintain the |
Beta Was this translation helpful? Give feedback.
-
@aormsby thank you so much! your back-and-forth (plus the detailed examples) saved me a whole bunch of time. I wanted to add a couple of notes in case anyone else finds themselves here:
Here is an excerpt from my workflow, which checks out a submodule parent, updates the reference to a particular submodule, and pushes that out, in case anyone finds this helpful. My goal here is to have a workflow actually running from within the submodule / child repository that checks out its referencing parent and programmatically updates the reference its parent keeps to whatever the current branch is:
|
Beta Was this translation helpful? Give feedback.
-
Turns out you can also do this:
No idea what’s better/faster/stronger here, but this solution was definitely straightforward. Works for any ref you don’t already have access to from the initial checkout. :slight_smile: Edit: I do want to be clear, though. Submodules are a pain, and different approaches work for different situations. For instance, my example here breaks my current work, and it’s annoying. Just something to be aware of. |
Beta Was this translation helpful? Give feedback.
Okay, I’ve got it! The original solution I marked got me really close to the right functionality, but there were still some issues coming through. However, I want to thank @weide-zhou for their help. I couldn’t have come to these solutions without the push. :slight_smile:
The Underlying Problem
The git refspec for the submodules wasn’t configured to track any remote refs outside ‘master’ so I could never get the other remote refs to other branches.
Incorrect config:
Config that gets all refs:
The checkout a…