GitService
import { GitService } from "@skipcheck/tm1-client"; TM1 Git (schema 11.5.0): ties the model to a Git repository, pushes its objects there
as JSON files (dimensions/Region.json, …), and pulls them back, on this server
or another.
Pushing and pulling are two steps: push and pull make a plan saying
what would happen (the files, or the operations, such as
Skip Dimensions('Region')), and execute carries it out.
What TM1 (11.8) does here that you might not expect:
- A plan belongs to the TM1 session that made it: another session can't see it or run it. Executing a plan uses it up; it's gone afterwards.
- The remote needs a commit on the branch to start from: TM1 can't make a repository's first commit, and pushing when the model hasn't changed is refused too (both "Cannot create bare commit").
- A local
file://remote works forinitandstatus, but not for pushing or pulling ("shallow fetch is not supported by the local transport"); usehttps://,ssh://orgit://. TM1 also refuses a local repository its own user doesn't own. deployis refused while Git is initialized ("Cannot re-deploy"): it's for a server not yet tied to the repository.- A pull compares commits, not the model: it plans the changes between the commit
last deployed and the branch, so an object deleted on the server since is skipped
(
Skip Dimensions('Region')), not brought back.deploybrings the whole branch. - The first pull after the remote moves on still plans the commit TM1 had; the next
pull plans the new one. Check the plan's
Commitbefore executing it.
Tie the model to a repository:
// The remote's branch must already have a commit: TM1 can't make the first one
const credentials = GitCredentials.password("tm1-bot", token);
return tm1.git.init("https://git.example.com/finance/model.git", "dev", credentials, false);
Push the model's changes:
// Plan the commit, look at the files it would push, then push them
const commit = new GitCommitDetails("Add the Region dimension", "Ada Analyst", "ada@example.com");
const plan = await tm1.git.push("main", null, commit, credentials, false);
if (plan.SourceFiles?.length) await tm1.git.execute(plan);
Pull a branch, once the plan is for the commit wanted:
// TM1 11.8 plans the commit it had on the first pull after the remote moves on: pull
// again until the plan is for the commit wanted, then carry it out
for (let attempt = 0; attempt < 3; attempt++) {
const plan = await tm1.git.pull("main", credentials, null, false);
if (plan.Commit?.ID && newest.startsWith(plan.Commit.ID)) {
await tm1.git.execute(plan);
return;
}
}
Members
init | Ties the model to the repository at url, under the deployment's name (such as dev) if given, replacing an existing tie if force, with the Git configuration config or TM1's. |
uninit | Unties the model from its repository, even with a plan waiting if force. |
status | The tie, and what's on the remote. |
push | Plans a commit of the model's changes on top of branch (which must exist on the remote), pushed to newBranch or, with none, branch; even if the remote moved on if force. |
pull | Plans bringing the model up to branch, one commit or each commit in turn (mode, or TM1's, SingleCommit), over local changes if force. |
deploy | Ties a server not yet tied to a repository, and pulls branch into it, in one step; over local changes if force. |
plans | GET GitPlans, streamed. |
plan | One of this session's plans, by ID, or undefined if this session has none by that ID (an executed plan is gone). |
execute | Carries out a plan, from push, pull or plans, pushing its files or pulling its operations. |
init
init( url: string, deployment: string | null | undefined, credentials: GitCredentials, force: boolean, config?: GitConfigurationPatch | null, options?: Tm1CallOptions, ): Promise<Git>GitInit: ties the model to the repository at url, under the deployment's name (such as dev) if given, replacing an existing tie if force, with the Git configuration config or TM1's. Returns the tie: URL, deployment, deployed commit, and the remote's branches and tags.
TM1 REST ActionImport GitInit
uninit
uninit(force: boolean, options?: Tm1CallOptions): Promise<void>GitUninit: unties the model from its repository, even with a plan waiting if force. The model is left as it is.
TM1 REST ActionImport GitUninit
status
status(credentials: GitCredentials, options?: Tm1CallOptions): Promise<Git>GitStatus: the tie, and what's on the remote. Fails with a Tm1BadRequestException if Git isn't initialized.
TM1 REST ActionImport GitStatus
push
push( branch: string, newBranch: string | null | undefined, commit: GitCommitDetails, credentials: GitCredentials, force: boolean, options?: Tm1CallOptions, ): Promise<GitPushPlan>GitPush: plans a commit of the model's changes on top of branch (which must exist on the remote), pushed to newBranch or, with none, branch; even if the remote moved on if force. The plan lists the files; execute pushes them.
TM1 REST ActionImport GitPush
pull
pull( branch: string, credentials: GitCredentials, mode: GitPlanExecutionMode | null | undefined, force: boolean, options?: Tm1CallOptions, ): Promise<GitPullPlan>GitPull: plans bringing the model up to branch, one commit or each commit in turn (mode, or TM1's, SingleCommit), over local changes if force. Pull again if the plan's Commit isn't the branch's newest: TM1 (11.8) lags a pull behind the remote. The plan lists the operations; execute carries them out.
TM1 REST ActionImport GitPull
deploy
deploy( url: string, branch: string, deployment: string | null | undefined, credentials: GitCredentials, force: boolean, config?: GitConfigurationPatch | null, options?: Tm1CallOptions, ): Promise<void>GitDeploy: ties a server not yet tied to a repository, and pulls branch into it, in one step; over local changes if force. Refused while Git is initialized. status then shows the commit.
TM1 REST ActionImport GitDeploy
plans
plans(query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<GitPlan>GET GitPlans, streamed: this session's plans not yet executed, each a GitPushPlan or GitPullPlan (typeOf(GitPlan, plan)). Fails with a Tm1BadRequestException if Git isn't initialized.
TM1 REST EntitySet GitPlans
plan
plan(id: string, options?: Tm1CallOptions): Promise<GitPlan | undefined>One of this session's plans, by ID, or undefined if this session has none by that ID (an executed plan is gone). TM1 (11.8) sends no @odata.type for GitPlans('id'), so it couldn't be told apart as a push or a pull; the list says, so the plan is found there.
TM1 REST EntitySet GitPlans
execute
execute(plan: GitPlan, options?: Tm1CallOptions): Promise<void>tm1.Execute: carries out a plan, from push, pull or plans, pushing its files or pulling its operations. The plan is used up.
TM1 REST Action GitPushPlan/Execute Action GitPullPlan/Execute