How update a git submodule using octokit.js #184301
-
Select Topic AreaQuestion BodyI already tried to adopt this one: octokit/octokit.rb#936 / file at this time in octokit.js, but that doesn't worked. Is there a way to update a git submodule / submodule sha using octokit.js ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Short answer: there is no single “update submodule” API in Octokit.js. A submodule update is just a commit that changes the submodule gitlink SHA, and you have to do that manually via the Git data APIs. How it works conceptually A submodule is stored in the parent repo as a special tree entry that points to a commit SHA in another repo. Updating it means creating a new commit in the parent repo with a new gitlink SHA. The correct way using Octokit.js You must: Get the latest commit SHA of the submodule repo Create a new tree in the parent repo that updates the submodule entry Create a commit with that tree Update the branch reference Minimal example (Octokit.js) const owner = "OWNER"; // 1. Get current commit const baseCommitSha = ref.object.sha; // 2. Get base tree // 3. Create new tree with updated submodule SHA const { data: newTree } = await octokit.git.createTree({ // 4. Create commit // 5. Update branch ref Important notes mode: "160000" is mandatory for submodules You cannot use the Contents API for submodules This mirrors exactly what git submodule update does locally TL;DR Yes, you can update a submodule with Octokit.js, but only by manually creating a commit that updates the gitlink SHA using the Git Data API. There is no shortcut method. |
Beta Was this translation helpful? Give feedback.
-
Yeah updating submodules via the API is tricky. You can't directly update the submodule, but you can update the tree entry that points to the submodule commit. |
Beta Was this translation helpful? Give feedback.
Short answer: there is no single “update submodule” API in Octokit.js. A submodule update is just a commit that changes the submodule gitlink SHA, and you have to do that manually via the Git data APIs.
How it works conceptually
A submodule is stored in the parent repo as a special tree entry that points to a commit SHA in another repo. Updating it means creating a new commit in the parent repo with a new gitlink SHA.
The correct way using Octokit.js
You must:
Get the latest commit SHA of the submodule repo
Create a new tree in the parent repo that updates the submodule entry
Create a commit with that tree
Update the branch reference
Minimal example (Octokit.js)
import { Octokit } from "@…